Commit Graph

148 Commits

Author SHA1 Message Date
Georges-Antoine Assi
07d983f75c Merge remote-tracking branch 'origin/master' into feat/streaming-retroarch-core-states
# Conflicts:
#	backend/tests/test_migrations.py
2026-09-28 09:55:44 -04:00
Georges-Antoine Assi
96ede4f04b Merge remote-tracking branch 'origin/master' into feat/streaming-retroarch-core-override 2026-09-27 20:19:32 -04:00
Zach Clendenen
da6edad29a fix(streaming): address Greptile review of the RetroArch state core
A broker too old to name its core also doesn't refuse a pushed state from
another core, so hydration with no core filter now only sends a newest
state that has no recorded core, and otherwise sends nothing.
2026-09-27 17:55:25 -05:00
Zach Clendenen
9e2dbc207d feat(streaming): hydrate and resume only states the booted core can load
A RetroArch container's core filter comes from the core activate reports
booting, or before launch from the configured core and the broker's
default (asked over its cores route and cached for a minute). Hydration,
an explicit resume and the config payload all apply it, so a state
written by one core never lands where another core's quick-load reads it.
A resume the booted core cannot load launches fresh, and the resume
endpoint refuses such a state up front with a 400.
2026-09-27 16:42:02 -05:00
Zach Clendenen
288ad2e5de feat(streaming): record the RetroArch core that wrote each state
States gain a nullable `core` column (migration 0141). A pulled state keeps
the core the broker names in its X-State-Core header, and a pushed state
names its core on the way down so a broker running another one refuses it.
NULL keeps meaning the platform's default core, which wrote every state
stored before cores were recorded.
2026-09-27 16:41:43 -05:00
Zach Clendenen
21c5b65d17 fix(streaming): address Greptile review of the RetroArch core override
- Retry the exit once when a broker boots the wrong core and the first exit
  fails: the broker refuses every activate while that game runs, and the
  released claim leaves nothing behind to stop it.
- Stamp the launch's core tier on the session and report it through the
  status poll, so a tab that missed launch-ready still warns about an
  untested or broken core, once.
- Translate the core-untested and core-blocked warnings in every locale.
2026-09-27 16:41:38 -05:00
Zach Clendenen
3fbb746ded test(streaming): review-polish pass, assert the core reaches the tier warning 2026-09-27 14:44:09 -05:00
Zach Clendenen
8336f127b6 refactor(streaming): simplify pass on the RetroArch core override 2026-09-27 14:39:13 -05:00
Zach Clendenen
2d25618ee2 fix(streaming): code-review pass on the RetroArch core override 2026-09-27 14:29:47 -05:00
Georges-Antoine Assi
96e2c2ad42 refactor(backend): pr-ready follow-ups for device installs
- Replace the inline bytes-to-text decodes with redis_handler.as_text
- Add utils.auth.token_device_id for a request's token-bound device
- Look up a group's member tokens in one query and close them in one pass

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 15:04:56 -04:00
Zach Clendenen
cd813caeba fix(streaming): tighten core override edge cases from review 2026-09-27 09:49:31 -05:00
Zach Clendenen
66e268cce9 feat(streaming): ask import-spec about the configured RetroArch core 2026-09-27 09:49:17 -05:00
Zach Clendenen
9f00d757a8 fix(streaming): don't hydrate default-core states into another RetroArch core 2026-09-27 09:49:13 -05:00
Zach Clendenen
007fb90e53 feat(streaming): warn the player when the RetroArch core is untested or known broken 2026-09-27 09:49:08 -05:00
Zach Clendenen
a4d594404a feat(streaming): send the RetroArch core on activate and end sessions a broker booted on another 2026-09-27 09:49:03 -05:00
Zach Clendenen
cdf2aba0da feat(streaming): per-platform RetroArch core in the streaming config 2026-09-27 09:49:01 -05:00
Sam Dornan
7c2b049b70 chore(mypy): drop warn_return_any and validate provider responses with strict JSON (#4826) 2026-09-26 20:13:55 -04:00
Sam Dornan
5a6c895d33 chore(mypy): give every generic its type arguments (#4818)
* 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>
2026-09-26 16:32:29 -05:00
Georges-Antoine Assi
fbff4347ac Merge pull request #4815 from rommapp/fix/local-time-asset-names
fix(saves): stamp save and state file names with local time
2026-09-26 17:22:51 -04:00
Sam Dornan
bd16648c9a chore(mypy): switch to strict mode with listed exceptions (#4817)
* 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

* 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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 15:45:37 -05:00
Georges-Antoine Assi
8c3874a5b0 Merge remote-tracking branch 'origin/master' into HEAD
# Conflicts:
#	backend/tests/endpoints/test_saves.py
2026-09-26 16:08:30 -04:00
Georges-Antoine Assi
b6c03e79eb fix(saves): stamp save and state file names with local time
State names were built with toISOString() in the browser, and save,
streaming save and memory card names with datetime.now(timezone.utc) on
the server, so every timestamp in an asset's file name was UTC. States
now use the browser's local time and server-named assets use the
server's local time (the container's TZ). Matching and ordering read the
stored file_name and the DB timestamps, so existing files are unaffected.

Fixes #4726

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 13:58:54 -04:00
Zach Clendenen
e2305e09e0 fix(streaming): address Greptile review on #4796
- A label longer than the request limit no longer becomes a container's
  name, so every published name is one the desktop endpoint accepts. The
  limit moves to handler.streaming.config as CONTAINER_NAME_MAX_LENGTH.
- A label equal to another container's key in any case no longer names
  its container, matching the case-insensitive lookup.
- An oversized broker manifest now fails the import build instead of
  being dropped, which lost the state typing of the base's entries.
- A broker error body is read against a 5 second deadline, like every
  other broker read.
- Type the _labelled test helper.
2026-09-25 22:12:50 -05:00
Zach Clendenen
9ade9dfdb8 simplify(pr-ready step 3): collapse duplicated branches and dead code
- config: one _keys_by_label grouping serves both the unique-label map
  and the shared-label warning.
- claim_session: one abort-and-raise for either refused pick; the
  newest-save lookup is a single conditional expression.
- launch: pick refusal fields off one optional ImportRefusedError.
- imports: skip_state is always true for a foreign save archive; drop an
  unreachable KeyError and the unused str form of _read_member.
- webstation: ImportSpec.state_channel is a Literal.
- Stream.vue: the 400 refusal hint folds into the generic server branch;
  pickableStates drops a guard nativeStreamStates already has.
2026-09-25 19:20:30 -05:00
Zach Clendenen
b6f2abb30f review(pr-ready step 2): harden import archives and fix review findings
Security (from the step 1 audit):
- Inflate zip entries a chunk at a time, so an entry whose header
  understates its size fails the CRC check instead of inflating in full.
- Cap the broker manifest at 1 MiB before reading it.
- Rebuild copied entries as regular files, keeping only permission bits,
  so a symlink entry cannot ride into the container.

Code review (xhigh):
- Bound the broker error body read at 1 MiB and truncate what is logged
  and returned.
- De-duplicate refusal hints in Stream.vue.
- Unpack only save members as zips; a zip-shaped state stays whole.
- Pick the newest state off an archive by created_at.
- Run newest_restorable off the event loop.
- Name a carried base entry by its staged path in the manifest.
2026-09-25 19:15:38 -05:00
Zach Clendenen
cf4353e9e2 Merge branch 'feature/streaming-container-names' into streaming-patches-8
# Conflicts:
#	backend/endpoints/streaming.py
#	backend/handler/streaming/config.py
2026-09-25 18:04:31 -05:00
Zach Clendenen
f45cd3d3cc feat(streaming): open a container's desktop by its name 2026-09-25 15:20:39 -05:00
Zach Clendenen
6e491beeda feat(streaming): name containers by their own label when it is unique 2026-09-25 15:18:02 -05:00
Zach Clendenen
c9f1d5e33b feat(streaming): offer only the foreign picks a broker imports, and honour the picked state over an older save's exit state
The streaming config now ships import_kinds per container, from the broker's
cached import-spec, so the picker hides foreign saves and states a broker would
refuse instead of failing them after the launch starts.

On DuckStation and RPCS3, a save pick other than the newest archive no longer
lets that archive's own exit state stand in for the picked state: the state
rides the import archive, or the resume is reported lost where the broker
cannot import it.
2026-09-25 12:53:04 -05:00
Georges-Antoine Assi
a18c8493c1 Merge remote-tracking branch 'origin/master' into streaming-patches-6
# Conflicts:
#	backend/endpoints/streaming.py
#	backend/tests/endpoints/test_streaming.py
2026-09-25 11:52:57 -04:00
Georges-Antoine Assi
b6dcfc6a3c polish(pr-ready step 4): trim comments and docstrings, keep the newest-state lookup off the event loop
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 11:48:16 -04:00
Georges-Antoine Assi
8f7d092d67 simplify(pr-ready step 3): one refusal type, one resume-import value, one zip staging loop
- build ImportRefusalSchema directly in the broker, dropping the mirror dataclass and the asdict conversion
- replace the resume_via_import/resume_needs_import pair with one ResumeImport literal
- stage base and foreign zips through a shared helper, parse each member once, and read the base only when something is imported
- ImportSpec.kinds is a set of names, and a successful import-spec answer is cached briefly so one claim asks once
- show the suggested emulator's display name in the refusal hint
- trim long comments and the dangling spec reference

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 11:43:08 -04:00
Georges-Antoine Assi
aa80073d34 feat(streaming): run exit save pulls on the streaming worker
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 11:34:05 -04:00
Georges-Antoine Assi
eaea7e6db1 review(pr-ready step 2): decide import eligibility on the won container and release the claim on refusal
- recheck import-spec right after the win; refuse a foreign save/state the won broker will not import instead of sending it natively
- only route an older native exit state through the import archive when the broker takes archive-channel states
- withhold resume_slot from activate when the import was lost
- import_spec: webstation-only, ACK timeout, catch http.client errors
- keep a foreign archive's own state out of a save import; preserve member timestamps and modes
- fix cs_CZ/pl_PL plural forms, a stale picker comment, and change-history docstrings

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 11:33:48 -04:00
Georges-Antoine Assi
4348c1e63d Merge remote-tracking branch 'origin/master' into streaming-patches-6
# Conflicts:
#	backend/handler/streaming/launch.py
#	backend/tests/endpoints/test_streaming.py
#	frontend/src/services/api/streaming.ts
2026-09-25 10:50:24 -04:00
Georges-Antoine Assi
22aa445d27 fix(streaming): hold the reaper off for a stale window after a restart, schedule it only with streaming on, and warn about later pools once across processes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 09:29:48 -04:00
Georges-Antoine Assi
29e6b8c1e9 fix(streaming): keep a claim fresh through its setup, log what spawned work raised, and notify a task's success only after that work ends (code-review)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 08:40:50 -04:00
Georges-Antoine Assi
2fc0460670 Merge remote-tracking branch 'origin/master' into streaming-reaper
# Conflicts:
#	backend/tasks/registry.py
#	backend/tasks/tasks.py
#	backend/tests/tasks/test_tasks.py
#	docs/BACKEND_ARCHITECTURE.md
2026-09-24 21:52:08 -04:00
Georges-Antoine Assi
8a33ccb35a Merge branch 'master' into streaming-patches-5 2026-09-24 21:01:09 -04:00
Georges-Antoine Assi
2eb2b5973e refactor(streaming): share the claim query params, mark-and-start the exit save pull in one call, and drop no-op casts (simplify)
- Declare the container and claimed_at query params once, with named length limits.
- Add lifecycle.start_exit_save_pull for the two callers that mark and start back to back.
- Build every claim query on the frontend through one claimParams helper.
- Drop PlayerState casts that narrowed nothing in the launch socket handlers.
- Reuse _load_session in the _drain test helper.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 17:49:59 -04:00
Georges-Antoine Assi
d99c3c5f7b fix(streaming): report a failed archive resume, stop duplicate stream entry, and fold emulator case in core checks (code-review)
- Exit-state emulators with no uploaded archive no longer send a resume slot or report resume=true.
- isCoreCompatible compares emulator ids case-insensitively, like grouping and labels.
- launch-ready skips enterStream when a status poll already entered the stream.
- A Desktop heartbeat answered after a release no longer overwrites the exited state.
- Drop the notice_in_scope alias, reuse session_is_desktop, trim over-long comments.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 17:43:30 -04:00
Zurdi
404518c5e0 Merge pull request #4749 from rommapp/claude/issue-2653-7225d5
feat: rename saves and states, and one public/private look across v2
2026-09-24 22:37:54 +02:00
zurdi
7132bfed5e Keep a save's or state's thumbnail while something still shows it
Deleting a save or state removed its thumbnail row and file unconditionally,
so a save and a state sharing a stem lost the shared preview when either one
went. Every delete path (single and bulk deletes, slot pruning, streaming
history pruning) now goes through release_thumbnail, which keeps:

- a thumbnail another save or state still matches by name, checked in SQL the
  way their thumbnail lookup matches, so it follows the database collation;
- a gallery screenshot that only shares the stem by chance;
- the file, when dropping the row, if another row spells the same file in a
  different case on a case-insensitive filesystem.

Renaming reuses the same is_bound check to decide whether a thumbnail is
shared, replacing the casefold helper.

Addresses Greptile's review on #4749.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 21:16:22 +02:00
Georges-Antoine Assi
ffdbe79032 Merge remote-tracking branch 'origin/master' into streaming-patches-5
Port the branch's emulator labels and live-state flag onto master's typed
streaming schemas, and carry the labelled state reason into
useSaveStateTabs now that the EmulatorJS view delegates to it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:37:10 -04:00
zurdi
a779fa41f7 fix(audit): apply the second pr-ready code review
- Re-measure the phone event rows whenever a web font finishes loading,
  and when a scrollbar narrows the rows, not only at mount.
- Log only the kind of an audit claim key when Redis fails, since a
  failed sign-in's key holds the text typed as the username.
- Make play-session ingest take the caller's permissions explicitly, so
  no caller skips the hidden-rom check by leaving them out.
- Read an empty collection cover URL as no cover, as the other fields do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 10:18:57 +02:00
zurdi
982a751085 fix: address Greptile's review of the notifications PR
- A failed LaunchBox or Switch TitleDB download, or an unreadable LaunchBox
  archive, now fails the task instead of returning empty stats, so its
  starter hears it failed rather than finished.
- The inbox replays changes made while a fetch is in flight onto its
  response, so a push, read or dismissal is not undone by an older list.
- A refused mark-read turns its rows unread again, and the inbox view tries
  each row once a visit so a failing server is not asked in a loop.
- Recipient resolution and sender attribution move from the endpoint into
  notification_handler.
- SendNotificationSection inherits attributes again, and record_termination
  loses a docstring sentence the code already says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 14:44:50 +02:00
zurdi
bb5769e606 refactor: apply the simplify pass
- One home for pushing to a user's room: `SocketHandler.emit_to_user`, on a
  write-only manager kept per event loop and on the server's own channel.
  Streaming's push_to_user and the sync and scan emitters use it too.
- Notifications are stored in one transaction per send, so a broadcast is one
  commit, and pushed concurrently. Recipients are resolved from id and
  enabled only, and the actor is loaded with just the fields it shows.
- notify_user_or_admins holds the "whoever started it, else the admins"
  rule both the scan and the task runner applied by hand.
- A scan notifies from finish(), so no exit path can forget it.
- `data` is never null, dropping its guards; the toast host, the inbox and
  the admin form share one tone icon map; the inbox icon uses RAvatar.
- The store keeps its list when a socket echo changes nothing, and small
  dead parameters and duplicated lists are gone.
- The socket reconnect after a logout moved from the inbox to AppLayout,
  since every v2 feature depends on the socket's identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 13:04:18 +02:00
zurdi
ff6b160117 feat: persistent notifications
Toasts disappear after a few seconds, and nothing reaches a user who has no
tab open. Notifications are now stored per user and kept until dismissed, so
what a background job or another user did is waiting the next time RomM is
opened.

Backend:
- `notifications` table (0130) with kind, level, data, actor and read_at, capped
  at the newest 200 per user.
- /api/notifications: list, mark read, dismiss one, dismiss all.
- notify()/notify_admins() store the row and push `notifications:new` to the
  user's socket room; read/dismiss push to the user's other tabs.
- Producers: a scan's end (to whoever started it; an unattended scan tells
  the admins when it failed or found new games), a manual task's end (to who
  ran it; a scheduled task's failure to the admins), an admin ending someone's
  stream, and an admin changing someone's role.

Frontend (v2):
- Unread count badge on the navbar avatar, and a Notifications entry in the
  user menu and settings sidebar.
- Notifications view: marks what it shows read, links each row to what it is
  about, dismiss one or all.
- Live toast for a new notification, except scans, which already toast.
- The text is rendered from the kind in the reader's language (18 locales).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 10:35:33 +02:00
Sam Dornan
ddd87ff554 feat(metadata): take region and language from the dump a hash matched (#4664) 2026-09-22 23:47:23 -04:00
Zach Clendenen
1960cd20be fix(streaming): budget import archive expansion, route non-newest resume picks through import, and stop shipping console.warn (Greptile) 2026-09-22 08:13:54 -05:00