Commit Graph

50 Commits

Author SHA1 Message Date
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
Georges-Antoine Assi
93681f459c Merge pull request #4596 from LoneAngelFayt/streaming-patches-4
fix(streaming): put every container in a pool, and reach later pools by key
2026-09-22 08:09:52 -04:00
Sam Dornan
4ffc7c5ce1 style: apply the formatting requires-python already implies (#4638) 2026-09-19 12:33:45 -04:00
Zach Clendenen
08f1e0001e simplify(pr-ready step 3): group dialable containers per platform in one place, point the claim comment at interchangeable_with 2026-09-17 11:46:22 -05:00
Zach Clendenen
9c1e9f4d75 fix(streaming): put every container in a pool, claim from the first
A platform's containers are now grouped into pools of interchangeable
members (same emulator, memory card sync, save picker and protocol), so a
lone container is a pool of one instead of a skipped non-member. Game claims,
status, heartbeats and joins still walk only the first pool, which matches
the containers they reached before.

The "not a pool member" warning fired on every lookup, one container at a
time. It now fires once per config and names every container a game claim
can never reach. Named lookups (desktop, admin release, named heartbeat)
already reach a container in any pool.
2026-09-17 11:42:18 -05:00
Zach Clendenen
c62af75621 polish(pr-ready step 4): trim the heartbeat and named-container comments 2026-09-17 09:53:01 -05:00
Zach Clendenen
e2e35835db simplify(pr-ready step 3): run a named heartbeat through the pool's lookup, reuse the store heartbeat and entry_for_platform
A named container is a one-entry candidate list, so the heartbeat has one lookup
and one status answer instead of a closure branching on the key, and it no longer
reads the session twice. The desktop view beats through the store wrapper, and
configured_emulator shares the platform match.
2026-09-17 09:41:31 -05:00
Zach Clendenen
398c088d49 polish(pr-ready step 4): wrap the fleet row's state line and actions, trim prose
At 320px the End session button ran past the row, and below md the state
line truncated away who holds the session. The actions now wrap and the
state line wraps at every width. Docstrings and the xs comment are cut to
the repo's two-line limit.
2026-09-17 08:19:22 -05:00
Zach Clendenen
bdd661d30a simplify(pr-ready step 3): share the per-platform entry lookup, build the state line in one place
entry_for_platform backs both container_for_session and
resolve_named_container, and the fleet row's state line is assembled in
sessionState instead of split across template blocks.
2026-09-17 08:14:41 -05:00
Zach Clendenen
339308d586 fix(streaming): resolve a named container by key, not through the pool
An admin ending a session names the container, but the lookup went through
containers_for_platform, which drops any container that disagrees with the
head of the pool. A second container with a different emulator, card sync,
save picker or protocol then 404'd on release, surfacing as "Could not end
the session." in the fleet panel, while its session kept holding it.

The named lookup now goes through containers_by_key and only checks that the
container serves the platform. Owner checks are unchanged.
2026-09-17 07:58:07 -05:00
Georges-Antoine Assi
d16aa85968 Merge branch 'master' into streaming-patches-3
AssetList moved its timestamp into <AssetTimestamp> and gained
groupBySlot on master, so the picker's `timestamp` prop now feeds the
component's date and both props coexist. The "updated" | "created" type
and its accessor join Asset's other shared helpers in v2/utils/assets,
where AssetPreview takes them too, since the old local name collided
with the AssetTimestamp component.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 19:12:34 -04:00
Georges-Antoine Assi
bf6f9db02a fix(streaming): serialize one player's claims on a platform
The ownership check and the reservation that follows it are separate Redis
round trips, so two concurrent claims from one player could each read no
session of their own and then win a different member of the pool, leaving
the second one unreachable. A per-player, per-platform gate held across the
pair makes the loser read the winner's session instead of a free container.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 17:38:47 -04:00
Zach Clendenen
4e327fd72e simplify(pr-ready step 3): cut the clears_stale_saves comments to the why
Each of them had grown a paragraph explaining where the broker flag lives
and when to reach for it, which the config example already covers.
2026-09-15 23:33:39 -05:00
Zach Clendenen
9cef7f2f29 review(pr-ready step 2): pool on the picker capability, not the raw flag
Two legacy broker containers serving the same emulator stopped pooling when
one carried a clears_stale_saves the resolver had just logged as having no
effect. Comparing supports_save_picker folds in the webstation gate, so it
is the same test for a webstation pair and inert for the rest.
2026-09-15 23:31:52 -05:00
Zach Clendenen
5e217c7f64 feat(streaming): let an operator declare whether their broker clears saves
The save picker was gated on a hardcoded set of emulators mirroring the
webstation broker's `clears_stale_saves`, a value that lives in another
repo. A broker release that turns it on for a new emulator needed a RomM
code change before the picker appeared, and an operator on a fork or a
newer broker could not turn it on at all. The other direction was worse
because it was silent: if the broker stopped clearing, the pick still
validated, the archive still uploaded, and the container's own newer
files overwrote it with no error anywhere.

`clears_stale_saves` now joins `memory_card_sync` in
PLATFORM_OVERRIDE_KEYS, resolved per container in `_resolve_one`, which
leaves the emulator table as the default rather than the authority. It
also joins the pool-interchangeability check, since the picker is
advertised from the head of the pool and a member that keeps its own
files would take the pick and discard it.
2026-09-15 23:22:27 -05:00
Zach Clendenen
14f847dc57 Merge remote-tracking branch 'upstream/master' into pr-ready-851cea
# Conflicts:
#	frontend/src/v2/views/Player/Stream.vue
2026-09-15 17:29:00 -05:00
Zach Clendenen
f58a7ad7e0 polish(pr-ready step 4): trim the comments and name the resolve helper for its answer
Cut the docstrings and comments this branch added down to the one non-obvious
fact each, in the resolver and in the tests alike, and rename the new helper to
_claimable_broker_host so it says what it returns next to _derive_broker_host.
2026-09-15 17:09:59 -05:00
Zach Clendenen
1b3caebabf simplify(pr-ready step 3): flatten the container resolve and compare protocols by name
Move the three ways a raw entry fails to resolve into one helper with a guard
clause each, so none of them has to unset a broker host a sibling branch set.

The subfolder match moves onto WebstationProtocol, next to the normalization it
has to agree with, and interchangeable_with compares protocol names, the
discriminator the record already uses elsewhere.
2026-09-15 17:05:08 -05:00
Zach Clendenen
9a4b644c01 review(pr-ready step 2): let a player reclaim their own stale container
The holder gate added with the pool ran before the stale-takeover walk, so a
player whose tab crashed was refused their own container until its TTL lapsed.
Block only on a live holder, and when the holder's own session is stale narrow
the candidates to that container so the existing takeover path reclaims it.

Also widen the proxy path check to compare the host's URL path, so a container
on another origin mounted at a path that disagrees with its subfolder is
refused the same way a bare path already was.
2026-09-15 16:57:37 -05:00
Zach Clendenen
df6ded2786 fix(streaming): refuse a proxied container whose host and subfolder disagree
A same-origin entry sends the browser to `host`, but activate answers with
the room URL the broker built from its own SUBFOLDER, and that is an
absolute path, so urljoin lets it replace the path `host` carries. The two
values are therefore not independent: both have to be the container's own
SUBFOLDER.

Get them wrong and nothing complains. A container mounted at /streaming-2
while declaring /streaming resolves, claims its own key, and hands the
player a URL the proxy routes to whoever owns /streaming: a different
container, mid-session, with no trace of it in either log. The likeliest
way in is a second pool member proxied at its own path with `subfolder`
left to its default.

Resolve the entry, log it, and clear broker_host so it cannot be claimed,
matching how the other unusable configurations are handled. It stays in
the fleet view, where the operator can see what is wrong with it. A full
URL `host` is untouched; it carries an origin of its own for that absolute
path to land on, so there the two are free to differ.
2026-09-15 13:30:34 -05:00
Zach Clendenen
50027b64ed fix(streaming): pool same-origin webstation containers across subfolders
interchangeable_with() compared protocol by instance identity, and
WebstationProtocol is interned per exact subfolder — so two containers
proxied at different subfolders, the normal way to run a same-origin
pool, were never recognized as pool members. Compare by type instead;
capabilities are class-level constants, so type equality is what
"same shape" actually means.
2026-09-15 12:49:08 -05:00
Georges-Antoine Assi
c0001bd27d style(streaming): trim the save-picker comments and the emulator compare
review-polish pass over the save-picker change.

Two comments carried more prose than the rule allows. The emulator comparison
re-normalized a value ResolvedContainer already lowercases at resolve time,
which the sibling state resolver relies on, so it now reads the same way.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 12:09:45 -04:00
Georges-Antoine Assi
1c5255df1f refactor(streaming): resolve the picked save once and list it like a save
simplify pass over the save-picker change.

The claim validated the pick, dropped the resolved row and passed the bare id
down two layers, where hydration fetched and re-checked the same save. It now
carries the row the way the resume state and the memory card already are, so
the restorability rule has one home and the claim one lookup.

The picker holds the picked id rather than the row, so an id that is no longer
on offer falls back to the newest by construction instead of through a watch,
and the list of archives uses AssetList, the variant meant for saves, rather
than the tile strip whose thumbnail area a save never fills.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 11:58:59 -04:00
Georges-Antoine Assi
73b7725686 fix(streaming): report only the saves the broker can restore
code-review pass over the save-picker change.

The launch screen listed every save this emulator wrote, but the broker only
restores .zip archives, so a bare save file could be named as the one about to
be restored while a much older archive actually went up. One restorable list
now feeds the panel, the tab and the picker alike.

A claim that carries a pick looks the save up by id instead of loading every
save on the ROM to scan for it, and the emulator comparison normalizes both
sides so a config value that is not already lowercase cannot silently match
nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 11:39:46 -04:00
Georges-Antoine Assi
20d44b3bee Merge remote-tracking branch 'origin/master' into streaming-patches
# Conflicts:
#	backend/handler/streaming/states.py
2026-09-15 11:23:42 -04:00
Georges-Antoine Assi
62b6a7596b docs(streaming): trim the state-screenshot comments
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 07:41:22 -04:00
Georges-Antoine Assi
ef9983fc02 refactor(streaming): one home for the PNG check, one deadline for the frame
The magic-byte test moves behind `_is_png`, so the two places that need it (the
broker body, where the answer decides whether the embedded frame is tried, and
the filesystem sink) read as one rule instead of two. Narrowing the extract
catch back to the failures a savestate archive can raise keeps a programming
error loud rather than logging it as a missing thumbnail.

The frame fetch gets its own 10s deadline: it runs while the claim is still
held and the player waits on the exit screen, and a thumbnail does not need the
archive-transfer budget.

From the pr-ready simplify pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 07:37:33 -04:00
Georges-Antoine Assi
63129edb30 fix(streaming): reject a non-PNG broker frame and inflate off the loop
The broker's screenshot now shadows the frame PCSX2 embeds in its own state,
so a 200 that is not a PNG has to read as no frame rather than as an unusable
one, or the state lands with no thumbnail at all. Extraction moves onto a
thread alongside the fetch it falls back from, since the body it inflates runs
to hundreds of megabytes.

From the pr-ready code-review pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 07:30:06 -04:00
Zach Clendenen
fb0b389adb style(streaming): trim the save-picker comments to the facts
review-polish pass over the save-picker change.

The comments explaining why an older pick only lands where the broker clears
the save tree said the same thing in four places, so each one now carries only
what its own reader cannot get from the code. The save fixture in the launch
screen test becomes a typed factory, which the emulator-scoping case it did not
cover yet now uses.
2026-09-14 03:02:03 -05:00
Zach Clendenen
a9ec19b3d9 refactor(streaming): look the picked save up by id instead of scanning the list
simplify pass over the save-picker change.

`resolve_save_archive` loaded every save the user has for the ROM just to find
one row by id. `db_save_handler.get_save` is the owner-scoped point lookup the
save endpoints already use for exactly this, so call it and check the rom_id,
which drops a list load per claim that carries a pick.

The ROM scoping moves from the query into the check, so pin it with a test.
2026-09-14 02:51:47 -05:00
Zach Clendenen
b0d33be5b0 fix(streaming): order the launch screen saves the way the backend restores them
code-review pass (xhigh, --fix) over the save-picker change.

The launch screen inherited `user_saves` ordered by `updated_at` from the rom
schema, while the backend picks the archive to restore by `(created_at, id)`.
A content-hash rewrite on an older row was enough to make the two disagree, so
the no-picker panel could name a save the broker would not restore. The list
is now sorted the way the backend orders it.

Also give the restorability rule one home on the backend, so the validator and
the selector cannot drift, and correct a stale comment that still called the
memory card id claimSession's third argument.
2026-09-14 02:43:27 -05:00
Zach Clendenen
107d797292 feat(streaming): let the launch screen pick which save to restore
Containers whose broker clears the save tree before restoring can land an
archive older than the container's own files, so offer the pick there and
validate it at claim time.
2026-09-13 23:57:21 -05:00
Zach Clendenen
16c355e4d2 docs(streaming): correct how non-PCSX2 states get their thumbnail
The docstring said the other emulators write the frame as its own file,
served by /state-screenshot. romm-broker PR 36 removed state_screenshot_path()
from every emulator module and replaced it with a single pixelflux capture of
the stream, so there are no per-emulator frame files left. PCSX2 is still the
only format that embeds one, read only when the broker's capture 404s.
2026-09-13 23:41:51 -05:00
Zach Clendenen
a9aef8a8e9 fix(streaming): take state thumbnails from the broker's frame
The browser capture read #videoCanvas by id, but the default path routes
frames through a MediaStreamTrackGenerator into a hidden #videoStream, so
drawImage returned a transparent bitmap. That still carries PNG magic, so
the backend accepted it and filed a blank thumbnail against a good state.

pull_state_to_library now asks the broker for the container's own capture
first, which is the same route for every emulator, and falls back to an
embedded frame (PCSX2) only when the broker answers 404. The browser
capture, its Redis stash, and the /state-frame endpoint are gone.
2026-09-13 21:33:09 -05:00
Georges-Antoine Assi
1250b1231f refactor(streaming): collapse the screenshot source selection
Apply the simplify pass.

The selection ran four interleaved "is None" guards over a preference
boolean and called the broker from two identical sites. Draining the
stash up front makes the whole order one guard: ask the broker when
nothing better is in hand, then fall back to the browser frame.

Tests get a _screenshot_for() builder next to _state_for(), replacing
seven copies of the same seven-field Screenshot construction.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-12 20:42:16 -04:00
Georges-Antoine Assi
95a71a6539 fix(streaming): drain the stashed frame and ask the broker once
Apply the code-review pass over the screenshot preference order.

take_state_frame() was the only consumer that deletes the Redis key, so
once an emulator's own frame won, a stashed browser frame survived its
save and could become a later one's thumbnail. Drain it on every pull.
For RetroArch the unguarded final fallback re-issued the identical
/state-screenshot GET, a second blocking 60s request held while the
container reservation is still out. The retroarch literal moves to a
module-level _BROKER_FRAME_EMULATORS, next to the other per-emulator
tables, and extract_state_screenshot() catches anything the zip read
raises so a corrupt embedded PNG costs the thumbnail, not the state.

Tests cover the RetroArch broker preference, its fallback to the browser
frame, and the single broker request when neither source exists.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-12 20:33:14 -04:00
Zach Clendenen
2b77526a81 fix(streaming): prefer RetroArch's own screenshot over the browser frame
The browser-captured canvas frame is a lagging, lossy copy of the video
stream and can hold a torn or missing keyframe right after a scene
change (e.g. pausing), producing a corrupted save-state thumbnail even
though the state itself is fine. RetroArch already writes its own
thumbnail off the core's real framebuffer at save time, so prefer that
for RetroArch and fall back to the browser frame only if it's missing.
Other emulators, which write no thumbnail of their own, are unaffected.
2026-09-12 15:09:32 -05:00
Zach Clendenen
836654c1d4 fix(streaming): prefer PCSX2's embedded screenshot over the browser frame
PCSX2 embeds a screenshot in every .p2s savestate, already in hand from
the state download with no extra round-trip or framebuffer readback
risk. pull_state_to_library() tried the browser-captured frame first
regardless, which produced black thumbnails when that capture missed
the live canvas. Extract the embedded screenshot first for PCSX2 and
fall back to the browser frame only when it's unavailable; behavior
for every other emulator is unchanged since extract_state_screenshot()
always returns None for them.
2026-09-12 15:09:32 -05:00
Georges-Antoine Assi
7546ebafda docs(streaming): move the migration guide to the docs site
The webstation migration guide belongs in rommapp/docs, where users reading
about emulator streaming will find it (rommapp/docs#128). The deprecation
warning and the protocol module now link to the published page.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 19:10:28 -04: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
Georges-Antoine Assi
7443b690be fix(streaming): keep the container's answers inside its own origin
A broker's launch, join and desktop replies name the URL the browser loads
in an iframe, and urljoin keeps an absolute (or `javascript:`) URL verbatim,
so a container that answered with one could run script in RomM's origin
instead of its own. The three sites now share one resolver that drops a room
URL leaving the configured host, the stage refuses a source that is not
http(s), and the frame is sandboxed without allow-top-navigation so a
container page cannot steer the tab it sits in.

Also drop the shared secret from the config entry a resolution warning
prints, which named the misconfigured container by dumping it whole.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:53:43 -04:00
Georges-Antoine Assi
e85fce8e80 fix(streaming): close the holes a review pass found
Session ownership and lifecycle, mostly around who a teardown belongs to:

- file the exit state, save states and state frames under the session's
  owner rather than the caller, so an admin driving someone else's session
  no longer collects their saves
- beat the heartbeat from the admin desktop view, which the stale sweep was
  tearing down three minutes in
- take the claim through release_own_session when a launch aborts, instead
  of deleting a key another player may already hold
- require the same claim to stamp a launch, so a late activate cannot revive
  a drain marker with a six hour TTL
- pull the in-game save archive on every teardown path, not just the two
  that remembered to
- skip draining keys in the admin force-release sweep

Plus: pool members must share a protocol, since the head's capabilities are
what the frontend renders; a claim clears terminations across the whole pool;
multiplayer is only recorded where the broker can actually seat a joiner; and
an unserializable config no longer caches forever on a repr() that repeats.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:33:44 -04:00
Georges-Antoine Assi
eccafd13d1 refactor(streaming): polish pass over the new modules
- The five new modules each defined `log = logging.getLogger("romm")`, which is
  what `logger.logger` already exports; they import it now.
- `ACK_TIMEOUT` had two homes. It is a protocol fact, so `protocol.py` owns it
  and the endpoint imports it from there; the unused
  `BROKER_LOAD_STATE_TIMEOUT` copy goes.
- Module and function docstrings trimmed to what the code cannot say: the
  change history and the justifications belong in the commit messages they came
  from.
- `asset_store` takes the union `write_file` accepts rather than `Any`.
- Four hand-rolled `setInterval` pairs (presence beat, session poll, exit
  chord, live sessions, activity tick) become `useIntervalFn`, which also
  cleared a real gap: the presence composable's timer had no scope teardown.
- The launch pushes are matched on the container the claim's 202 named, not on
  the platform: a pool serves one platform from more than one container, so a
  second tab could otherwise act on the first's launch.
- Test helpers typed: the push capture and the resume-claim tuple carry real
  types, and an unused `_claim_ready` helper goes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 13:13:02 -04:00
Georges-Antoine Assi
74c77d0bb2 feat(streaming): answer the claim before the launch, and push what happens
`POST /streaming/sessions` blocked for up to STREAMING_LAUNCH_TIMEOUT (10
minutes) while a broker unpacked a pkg or archive, and four mechanisms existed
to keep that survivable: a 3s status poll the client ran alongside it purely
for progress, `launch_timeout` shipped through /config so the client could size
its own axios ceiling, and a cancel-then-undo branch that re-released a session
the player had already abandoned, because a blocking POST cannot be cancelled.

The claim now answers 202 as soon as the container is reserved and everything
that can fail synchronously has (404, 409, 428 are all still the claim's own
status). The launch runs detached and pushes to the user room the
force-release notice already used:

- `streaming:launch-ready` carries the room URL and the resume outcome
- `streaming:launch-failed` carries the reason; the claim is already freed
- `streaming:launch-phase` carries the broker's extraction phase

The backend polls the broker for that phase itself, once, however many tabs are
watching, and only pushes changes. `GET /sessions/{platform}/status` stays as
the fallback for a tab that missed a push.

That retires the client's launch poll, the `launch_timeout` plumbing and the
cancel-then-undo branch. Leaving during a launch is now just a release, and the
launch-ready handler hands the container back if the player has already gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 12:04:58 -04:00
Georges-Antoine Assi
f6b842fe62 refactor(streaming): move the session store and broker transport into handlers
`endpoints/streaming.py` held a general-purpose Redis session store and an HTTP
client alongside its routes, so both were reachable only through the ASGI test
client and neither could serve a second caller. They now sit in
`handler/streaming/` next to the container and protocol modules, matching how
`handler/netplay_handler.py` already owns its Redis room state.

- `session_store.py`: the keys, TTLs, compare-and-set helpers, drain markers,
  staleness rule and termination notices. Its names are public now, because the
  module boundary is the privacy boundary.
- `broker.py`: the urllib transport, its bounded reads and byte caps, and the
  translation of a transport failure into the 502/503 the frontend parses.

The endpoint module drops from 5157 lines to 3616 and keeps the routes, the
claim and teardown flows, and the asset sync.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 10:55:45 -04:00
Georges-Antoine Assi
1246d18fe3 refactor(streaming): resolve containers once, behind a broker protocol
Two shapes of streaming broker were branched on at 19 call sites, and every
consumer re-derived a container's host, key, emulator, capabilities and card
sync from the raw YAML on each call. `_containers_for_platform` re-ran host
parsing and the operator's misconfiguration warnings on every request, and
`_container_label` re-read config.yml once per listed row.

`handler/streaming/`:
- `protocol.py` gives each broker shape a class owning its route prefixes,
  timeouts, response dialect, stream-URL assembly and capability flags. A call
  site now asks `protocol.supports_disc_swap` or `protocol.save_state_accepted`
  instead of re-testing `protocol: webstation`. Instances are interned per
  subfolder so identical configs share one object.
- `capabilities.py` holds the per-platform and per-emulator slot tables and the
  state transfer limits, keyed purely by platform and emulator.
- `config.py` turns the raw list into frozen `ResolvedContainer` records with
  every question already answered, memoized until the config changes, so the
  warnings fire once per config rather than once per lookup. A container RomM
  cannot dial still resolves, with an empty key: unclaimable, but visible in
  the admin fleet view where the operator can see why.

`endpoints/streaming.py` drops ~700 lines and takes records rather than dicts
throughout; `container.emulator` and `container.protocol.session_route(...)`
replace the derivations that used to run per call.

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