* feat(saves): add save channels and snapshots
* feat(saves): close spec gaps in save channels and hash with sigil
* feat(saves): play snapshots in the v2 player, which pushes snapshots
* fix(saves): code review: authorization, retention losses, held-save sync, batched responses
* refactor(saves): simplify pass
* refactor(saves): review-polish pass
* docs(saves): humanizer pass
* feat(saves): run every EmulatorJS page on the v2 player
* feat(saves): per-user snapshot pins
* feat(sigil): store the identity a save restore needs and pin sigil 0f05f25
* fix(saves): meet type-aware lint in the v2 player
* feat(sigil): store N64 header and playlist title ids, pin sigil 0847fda
* feat(saves): convert saves for a core on download and list save layouts
* feat(saves): prune unreachable archival snapshots and empty detached channels on delete
* feat(saves): device sync from the token, held snapshots and shared-card pushes
* feat(saves): arc restores past abandoned snapshots and color channels by age
* fix(saves): code-review and security-audit fixes
* refactor(saves): simplify pass
* chore(saves): review-polish pass
* docs(saves): humanizer pass
* fix(sync): file RetroArch autosave versions as their channel's next snapshot
* fix(saves): address review findings and trim docstrings
* fix(saves): share-lock planned rows by id so PostgreSQL accepts the lock
* test(saves): stub the detached-channels fetch in SaveDataTab stories
* feat(saves): carry the full current snapshot in a 409, pin sigil 2071dff
* chore(sigil): pin 5d4ddb4, which reads .cue and .gdi sheets
* docs(saves): drop v2 wording now that one UI remains
* chore(sigil): pin 0190443, which reads PS2 raw BIN images and cue sheets
* fix(sigil): treat a file too short for its format as routine during scans
* chore(migrations): renumber save channel migrations after upstream's 0154
* fix(snapshots): a hardcore switch on unchanged content makes a new current
* fix(sync): decide a channel's slot from its history and the device's snapshot
* chore(docker): pin sigil at 794d99f for PSP Store release save prefixes
* refactor(db): squash the save channel migrations into 0161
Fold the slot linking (0162) and the rom_files sigil identity columns (0163)
into 0161_save_channels, so the feature ships as one revision.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(saves): close visibility and input gaps found in review (pr-ready step 2)
code-review --fix:
- negotiate_sync drops channel slots on ROMs hidden from the caller
- channel PATCH/attach/DELETE answer 404 when the channel's ROM is hidden
- a push copying a save from a hidden ROM answers 404
- _own_device applies require_token_device to bound client tokens
- adopting a legacy save syncs its sharing with the channel it joins
security-audit follow-ups:
- another user's detached public save or state is no longer downloadable
- profile and option values must be a single path segment
- companions are de-duplicated and capped at 8
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(saves): share channel and asset lookups, drop duplicates (pr-ready step 3)
simplify:
- readable_channel_or_404 and channels_on_files replace four copies of the
channel 404 check and two copies of the file-fed channel listing
- readable_rom_asset_or_404 serves both public save and state downloads
- _own_device resolves through require_device; _clone_origin takes the source
- reuse _unprocessable, DESCRIPTOR_EXTENSIONS, SAVE_SLOT_MAX_LENGTH, uniqueBy
and uuidv7; neutral forms default their required pattern to the allowed one
- RetroArch delete checks held rows in one query, a guarded upload lists the
slot only without a channel head, and uploads are read off the event loop
- snapshotSession builds push requests once; player comment cleanups
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(saves): trim two docstrings to two lines (pr-ready step 4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(saves): answer held RetroArch paths with 423, mirror slot labels
- RetroArch Cloud Sync answers 423 Locked for a PUT over a held unslotted save
and for a DELETE where only held rows sit at the path, instead of 409 and 404
- channelLabelForSlot returns null for blank and state_ slots, as the backend's
channel_label does, so the player files them under no channel either
- document that sharing a channel lets every user read and push into it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(docker): pin sigil at 85f88a8 for Switch .nup containers
* fix(snapshots): a save pushed in another shape or format makes a new current
* refactor(saves): drop the always-true SAVE_SYNC.SNAPSHOTS heartbeat flag
Nothing reads it, and the SAVE_SYNC block's presence already tells a
client the server speaks the snapshot API. Also trim the rom detail
channel field comments to one line each.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(frontend): use uuidv7 for every client-generated id
Drop the randomToken wrapper and the notification inbox's Math.random tab
id, so uuidv7 is the one helper that works outside a secure context.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(saves): trim redundant snapshot API surface, dead code and duplicate logic
API:
- Drop PUT /snapshots/{id}/devices/{device_id}; GET /snapshots/{id}?hold=true holds.
- GET /snapshots is history only (channel_id required); GET /channels serves currents.
- A snapshot carries channel_id instead of an embedded channel.
- POST /saves/{id}/content takes the same query parameters as the GET, plus container_path.
Backend:
- Remove the archival write path, clone.py, DBStatesHandler.get_state, the sigil
identity-hash path, unused relationships and composite snapshot indexes.
- One held/frozen lookup, one bulk-delete guard, SQLAlchemy dialect upserts, and
the shared reserve_version_name in the writer.
- The writer takes a visibility filter and checks the channel and parent itself.
- The restore handler picks per-game or merge; fewer wrapper types and tables.
Frontend:
- Channel delete uses the shared typed confirm; DeleteChannelDialog is gone.
- Held offline pushes go through a per-channel SnapshotSession.
- Remove the slot-based pending upload path.
- The timeline shares the fan's badge logic.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* refactor(saves): release archival backups through module functions
The saves and states handlers each built a private DBSnapshotsHandler to
call release_backup and refresh_backup_digests, since they can't import
the shared instance. Both only ever ran inside the caller's session, so
they are now module functions taking it, like channel_for_slot.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* refactor(saves): share one deleted-assets handler instance
The saves handler built its own DBDeletedAssetsHandler because it can't
import the package's instance. The instance is now built in
deleted_assets_handler.py and re-exported by the package, so both use it.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(db): bump client token and device last-used timestamps without a prior read
update_last_used() and update_last_seen_debounced() read the row with
session.get() and then updated it in the same transaction. When two requests
with the same Client API Token ran concurrently and both passed the debounce
check, the second UPDATE hit MariaDB error 1020 (Record has changed since last
read), so a read-only GET returned HTTP 500. Make each a single conditional
UPDATE that only touches the row when the debounce window has passed.
Fixes#5379
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* test(db): code-review fixes for last-used race tests
Reuse the executed_statements fixture, scope race listeners to
sync_engine, add the device race test, drop an unused fixture, and
apply trunk fmt.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(db): simplify pass on last-used race fix
Share the race hook as tests/db_race_stubs.run_before_first, look tokens
up by id in tests, trim duplicated docstrings, and state the handler
comment as current behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(db): humanizer pass on last-used handler comments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(db): run MariaDB and MySQL sessions at READ COMMITTED
MariaDB 11.6+ turns on innodb_snapshot_isolation, so at REPEATABLE READ any
transaction that reads a row and then writes it fails with error 1020
("Record has changed since last read") when another transaction committed
to that row in between. READ COMMITTED, PostgreSQL's default, takes a fresh
snapshot per statement and removes the whole class of failures.
A server logging binlog_format=STATEMENT refuses InnoDB writes below
REPEATABLE READ, so its sessions keep the default and log a warning once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* perf(auth): skip last-used and last-active writes inside the debounce window
Client-token auth bumped the token, the device and the user on every
request, the user with an undebounced UPDATE plus a re-SELECT. The token's
loaded last_used_at now gates the token and device bumps, and
set_last_active checks the loaded last_active and bumps through a
debounced conditional UPDATE, so a request inside the window writes
nothing and takes no row lock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
- Match on (issuer, sub) with exact collation, so subjects from another
provider or differing only in case never match.
- Refuse a login whose email is linked to another subject at the same
issuer instead of rebinding the account; relink only across issuers.
- Check the account is enabled before saving identity changes.
- Keep the old email when it is claimed between the check and the write.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Store the provider's `sub` on a new nullable users.oidc_sub column, look users
up by it first and fall back to email, backfilling the sub on the next login. A
user matched by sub gets their stored email updated, unless another account
already holds it.
Fixes#1690
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore(mypy): switch to strict mode with listed exceptions
Replace the hand-picked flags with `strict = True`, turning off only the
four flags that aren't clean yet (disallow_any_generics,
warn_return_any, disallow_untyped_calls, disallow_untyped_decorators).
Any other strict flag, including those future mypy releases add to the
preset, is on by default.
That turns on no_implicit_reexport, strict_equality and extra_checks:
- Import each name from the module that defines it. About 240 test
sites patched a dependency through the module that imported it
(`scan_module.fs_rom_handler`); they now import the same object from
its source, so every patch targets what it did before. Tests that
replace a module attribute are unchanged.
- handler.streaming.memory_cards re-exports store_memory_card_version
explicitly, since endpoints call it there and tests patch it there.
- mutagen gets implicit_reexport, as it re-exports without __all__.
- Test comparisons build typed values (CoverResult, a typed expected
dict, enum .value) and the CORS lookup casts for its identity check.
- One ss_handler ** spread keeps a coded ignore: extra_checks wants its
NotRequired dump_* keys spelled out, and the media dict never has them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* chore(mypy): give every generic its type arguments
Drop disallow_any_generics from the strict-mode exceptions and fix the
347 bare generics it reports, 230 of them in app code.
- Bare `dict` becomes `dict[str, Any]`: update payloads, raw provider
JSON and endpoint bodies map string keys to mixed values, so the Any is
real and now written down. The OpenAPI document is unchanged.
- Rom query filters take and return RomSelect; _music_facet_joins and
_exclude_hidden are generic over the Select they're given, and
_build_hash_selects returns id-only selects.
- Redis clients are typed by what they return: the decoding caches are
Redis[str], the RQ connection and binary cache Redis[bytes].
- The rest get explicit parameters: Row, Pattern, ColumnElement,
QueryableAttribute, SpooledTemporaryFile, Task, Future and friends.
Precise types reached callers that had been getting Any, which surfaced:
- The LaunchBox cache writer is fed binary-cache pipelines.
- The flashpoint and IGDB request helpers return raw JSON of varying
shape, not always a dict.
- The rom search endpoint returned dicts under a list[SearchRomSchema]
annotation; it now validates them into that schema.
- The audit filter's id subquery selects strings.
- In tests the binary cache is the non-decoding fake shared with
async_cache, so it is cast to Redis[bytes] rather than changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* test(upload): assert cleanup against the patched upload directory
The 409 test checked config's ROM_UPLOAD_TMP_BASE while the fixture patches
the endpoint's copy to tmp_path/uploads, so it passed even if cleanup failed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* chore(mypy): keep the row type through the ROM filter helpers
filter_roms and its helpers also receive select(Rom.id) membership queries,
so they now take and return the caller's Select type instead of narrowing to
RomSelect. merged_ra_metadata mixes scalar and list values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(backend): make type ignores match what mypy reports
Third in the staged series clearing the errors #4655 made visible.
Whole-project mypy: 91 errors in 26 files -> 64 in 23.
Twenty `# type: ignore[assignment]` comments in
endpoints/responses/rom.py never suppressed anything. The request-scoped
values `from_orm_with_request` attaches to a Rom (rom_user, has_notes,
user_saves and the rest) are not declared on the model, so mypy reports
`attr-defined`; it does so under 1.19 as well as 2.3, so the code was
wrong when the comments were written rather than drifting since. They
now name the error they were meant to silence.
Seventy-nine ignores across 24 files suppressed nothing at all under
`--warn-unused-ignores`, and are removed. One of them,
`utils/zip_cache.py`, keeps its `attr-defined` code for the private
`zipfile._get_compressor` and drops only `assignment`. The unused set is
identical under mypy 2.3.0 and 2.3.1, and removing them leaves the error
count unchanged under both, so none was quietly needed.
The two `filter` helpers typed as `[QueryT: Select | Update | Delete]`
bound the TypeVar to the union, so `query.filter(...)` returned the union
and could not be assigned back to `QueryT`. Constraining it to the three
types lets mypy check each one separately, and the callers are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPpv6W2ygP9tQ61fTQxdYp
* fix(backend): replace mypy and ASYNC240 trunk-ignores with real fixes
A `trunk-ignore` only suppresses when Trunk runs the linter. Plain mypy
does not read them, so the 13 on mypy findings were all still errors to
`mypy .` and would fail a whole-project check. Each now has a fix.
endpoints/tasks.py: `common_data` was a plain dict literal unpacked into
eight TypedDict constructors, so mypy saw `dict[str, Any]` and could not
match its keys. It holds exactly the fields of BaseTaskStatusResponse and
is now annotated as one, so the unpacking is checked.
handler/metadata/gamelist_handler.py: both media maps were inferred as
`dict[str, str]`, so indexing the TypedDict with their keys was
unprovable. Their keys are now typed `GamelistMediaKey`, the Literal of
the TypedDict's fields. A misspelt map key is now an error at the entry;
before, only the index site could have noticed, and it was suppressed.
handler/metadata/playmatch_handler.py: `attr` was a bare `str`. A TypeIs
guard narrows it to the five lookup attributes, and the frozenset is
derived from that Literal so the names live in one place. mypy now checks
that each name is a real PlaymatchRomMatch key. It does not check that
each takes an int, since mypy is lenient about value types on a union key;
that still rests on which five names are listed.
endpoints/search.py: the per-source tuples mixed ROM-list and handler
types, which mypy joined to `object`. The dict is now annotated with what
the loop uses: Mapping rows and the MetadataHandler base.
tests/handler/metadata/test_launchbox_handler.py: `Path.stat()` inside an
async test (ASYNC240) now goes through `anyio.Path`, as the rest of the
codebase already does.
Whole-project mypy: 64 errors in 23 files -> 51 in 20, identical under
2.3.0 and 2.3.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPpv6W2ygP9tQ61fTQxdYp
* fix(backend): keep gamelist media keys in one place
Review pointed out that `GamelistMediaKey` repeated all fourteen fields
of GamelistMetadataMedia. Python has no `keyof`, so any Literal of a
TypedDict's keys is a second declaration of them, and a field added to
the TypedDict would be left out of it without any error.
The three index sites go back to suppressing `literal-required`, now as
`# type: ignore[literal-required]` so plain mypy reads it as well as
Trunk. The TypedDict stays the only declaration of the key set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPpv6W2ygP9tQ61fTQxdYp
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Add a new scheduled task that syncs RetroAchievements progress for all
users with a RetroAchievements username.
Environment variables:
- `ENABLE_SCHEDULED_RETROACHIEVEMENTS_PROGRESS_SYNC`: Enable or disable
the task (default: `false`)
- `SCHEDULED_RETROACHIEVEMENTS_PROGRESS_SYNC_CRON`: Cron string to
schedule the task (default: "0 4 * * *" - daily at 4 AM)