Commit Graph

25 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Zach Clendenen
10c930112d fix(streaming): put an abandoned session back when its teardown fails before the stop, and give the reaper job room for the exit save pull (Greptile review) 2026-09-18 18:52:11 -05:00
Zach Clendenen
ca4ba4ee9a fix(streaming): keep a reap going past one failing container, give it the hold ceiling, keep no per-minute history, and share the abandoned-session read (code-review) 2026-09-18 16:28:02 -05:00
Zach Clendenen
9ee6bd4950 feat(streaming): reap abandoned streaming sessions every minute
A session whose heartbeat went stale was only torn down when a new claim
found every container of its platform held, so a player who left without
the pagehide release landing kept the emulator running. A scheduled task
now sweeps every configured container and hands stale sessions to the
existing abandoned-session teardown, which is made public for it.
2026-09-18 16:28:02 -05:00
Zach Clendenen
e4548b771c fix(streaming): keep retrying a webstation exit pull the exit never confirmed
A webstation exit that timed out or failed may still be writing its save dump, so taking its first answer as final could leave the archive uncollected. The stop now reports whether the broker answered, and only an answered exit or a confirmed save-and-exit takes one fetch. The claim test now makes a real claim while the pull runs.
2026-09-18 12:53:20 -05:00
Zach Clendenen
a62d1158ad fix(streaming): keep retrying a save pull the broker has not confirmed finished
A per-emulator broker acks DELETE /launch before the emulator has flushed its saves, and a blocking save-and-exit that timed out or failed may still be killing it, so one answer from those pulls could miss the session's saves. Only a webstation exit, which answers once its dump is written, and a confirmed blocking save-and-exit take the first answer as final.
2026-09-18 12:13:11 -05:00
Zach Clendenen
11eabe6431 docs(streaming): fit the branch's comments and docstrings in two lines
The repo caps a comment at two lines and a docstring at one sentence plus Args and Returns. Several comments and docstrings this branch wrote or edited ran to three lines or more, so they are tightened, with parameter notes moved under Args.
2026-09-18 12:03:10 -05:00
Zach Clendenen
36844e6c93 fix(streaming): take one answer from a save pull once the emulator has stopped
The pull retries to wait out an emulator still writing its saves, but every teardown stops the emulator first, so a pull after an exit with nothing new ran all five attempts and held the player's next claim for about twelve seconds. Only a background save-and-exit, where the broker may still be saving, keeps retrying.
2026-09-17 20:10:07 -05:00
Zach Clendenen
2512069345 fix(streaming): mark the exit save pull before the teardown stops the emulator
The release and abandoned teardowns only marked the pull after the stop, the card evacuation and the state pull. On a pool the player's next claim landed on a free sibling in that window, found nothing pending and hydrated from the archive before last. The mark now goes down as soon as the teardown owns the container, and a teardown that ends without starting the pull clears it.
2026-09-17 20:08:48 -05:00
Zach Clendenen
52893d301d fix(streaming): let a save pull clear only the mark it was given
The marker was one bare flag per user and ROM, so when two pulls overlapped the first to finish deleted the mark the second had set, and a claim behind the second stopped waiting for it. Each mark now carries a token and the clear is a compare-and-delete.
2026-09-17 20:06:55 -05:00
Zach Clendenen
8127fc11ae docs(streaming): fit the force-release note in two lines 2026-09-17 18:56:26 -05:00
Zach Clendenen
adf891b091 docs(streaming): place the force-release note before the quiesce
The note is written once the drain marker is held, so "before the drain"
pointed a reader at the wrong step.
2026-09-17 18:40:48 -05:00
Zach Clendenen
4f2d1198f2 docs(streaming): tighten the comments this branch grew
Several notes had run to four or more lines, a couple of them recounting
how the code was reordered rather than what it does now.
2026-09-17 16:59:38 -05:00
Zach Clendenen
e8c96f8aa8 refactor(streaming): drop arguments no caller varies
resolve_owned_session's include_desktop was never passed, and the two
teardown helpers and stamp_launched defaulted arguments every caller
supplies. The 409 builder's holder snapshot no longer reuses the name of
the container above it.
2026-09-17 16:53:46 -05:00
Zach Clendenen
f512bead7f fix(streaming): hold a claim until the last session's saves are filed
An exit pulls the in-game save archive off the container in a detached task,
so a claim landing right behind the release hydrated the container from the
archive before last and the player lost the session they just finished.

The teardown marks the pull pending in Redis before spawning it and clears the
marker when the task ends, and a claim waits the marker out before hydrating.
The wait is capped so a wedged pull costs one stale hydrate rather than a claim
that never answers.
2026-09-17 15:49:33 -05:00
Zach Clendenen
13e65ec375 fix(streaming): leave no ended notice when a player retakes their own session
A crashed tab leaves a stale session, and pressing Play again sweeps it.
The sweep left the same notice a force-release does, which went to the
user, whose only tab was the one that had just claimed the container: it
read the push as its own session ending and handed the claim straight
back.

The takeover now names the claimant, and the sweep skips the notice when
it is the owner coming back. A takeover by anyone else still leaves it.
2026-09-17 15:07:24 -05:00
Zach Clendenen
e3b529e214 fix(streaming): carry container and desktop on the session-ended notice
The termination notice named only the platform, so a tab could not tell
which of the account's claims had ended. One room carries them all: a
player holding two sessions from a pool, or an admin with a desktop open
alongside a game, tore down the wrong screen.

The notice now names the container it ended and whether that claim was a
desktop. Stream.vue ignores a desktop notice and one for a container it
did not claim; Desktop.vue gains the listener it never had, so a
force-released desktop says so at once instead of at the next heartbeat.

The tombstone also moves ahead of the drain in both teardown paths: the
session is over the moment the marker lands, and a poll during the
seconds of broker round trips that follow found no reason at all.
2026-09-17 15:04:27 -05:00
Georges-Antoine Assi
f78348da0f refactor(streaming): move the endpoint's domain layer into handler/streaming
endpoints/streaming.py had grown to 3778 lines, but only about a third of
that was routes. The rest was a second copy of the layer handler/streaming
already exists to hold: broker verbs, webstation protocol translation,
state and save and memory-card transfer, session teardown.

Split it along those seams rather than by route, and give claim_session
the same treatment: its 406 lines are now four named phases.

Cross-module calls go through the module (states.pull_state_to_library,
commands.stop) instead of imported names, so one definition site is what
tests patch and what every caller reads.

No route path, scope or response model changed, so the OpenAPI schema is
untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 18:47:18 -04:00