Commit Graph

12511 Commits

Author SHA1 Message Date
Zach Clendenen
b7daab85a4 fix(streaming): enter a running game off the poll only on the claimed container
The status poll names no container, so it can answer with another tab's session on the same platform, and a loading tab that missed launch-ready would adopt that room as its own and later save and end it on unload.
2026-09-18 11:40:14 -05:00
Zach Clendenen
2cc00f2c4b fix(streaming): bind the desktop's release and heartbeat to its claim
The desktop sent only its container, so a desktop tab that missed losing its claim could end whichever game took the container, and its beat kept the admin's own game there alive instead of reporting the desktop ended. It now sends the claimed_at its claim answered with, as the game view does.
2026-09-18 11:39:24 -05:00
Zach Clendenen
156cfe4676 fix(streaming): name the claim a player's save-and-exit ends
A playing tab leaves through save-and-exit on Save & Exit, unmount and tab close, and sent neither the container nor the claim stamp, so a tab that missed its takeover could save and end the claim that replaced it. It now sends both, as release already does.
2026-09-18 11:37:40 -05:00
Zach Clendenen
75146307c5 docs(streaming): say which route reports a session's room
The heartbeat answers active with no host long after the launch returned, so the field is not None only until launch; only the status poll fills it.
2026-09-18 11:31:37 -05:00
Zach Clendenen
392eb56f6f test(streaming): pin the takeover notice ahead of the drain
Only the owner release path checked that the tombstone is written before the quiesce, so the abandoned-takeover teardown could fall back to the old order without a test failing.
2026-09-18 11:31:17 -05:00
Zach Clendenen
cdbd1fdf5c test(streaming): cover an unnamed release and heartbeat on another platform
A container serving two platforms keeps one session under one key, so an unnamed ngc release or heartbeat must not reach the caller's ps2 game there. Nothing pinned the platform filter in either lookup.
2026-09-18 11:30:21 -05:00
Zach Clendenen
accb42d9b5 test(streaming): name the desktop room test for the field it pins
No route reads a desktop's stored room back: the desktop POST answers with it directly and the status poll skips desktops, so the test only pins the stored field and should not promise a recovery path.
2026-09-18 11:28:56 -05:00
Zach Clendenen
157df721c6 refactor(streaming): list /config rows from the pools a claim walks
The config endpoint re-derived the key filter and case-insensitive platform grouping that the pool helpers own, so the Play button row and the claim could drift apart. It now reads the first container of each platform's first pool from the same helper.
2026-09-18 11:28:03 -05:00
Zach Clendenen
aef947e3da docs(streaming): say a heartbeat reaches any desktop only by naming it
An unnamed beat skips every desktop, not only one outside the platform's first pool.
2026-09-18 11:23:51 -05:00
Zach Clendenen
79be00ceb0 refactor(streaming): require a platform when scoping a session lookup
Every caller names the platform, so the None default and the branch it fed only widened the signature.
2026-09-18 11:23:19 -05:00
Zach Clendenen
a3a71d32bc test(streaming): cover a claim re-stamped between the heartbeat's lookup and write
The stale-stamp test is turned away at the lookup, so nothing exercised the claimed_at clause in the heartbeat's compare-and-set.
2026-09-18 11:19:15 -05:00
Zach Clendenen
c3c549e58e fix(streaming): bind save-and-exit to the claim it was given
A playing tab unloads through save-and-exit, which matched on user and platform alone, so a tab that missed its takeover could save and end the claim that replaced it. It now takes the same container and claimed_at as release and resolves its target through the same helper, answering not_found when that claim is gone.
2026-09-18 11:18:27 -05:00
Zach Clendenen
84493c3f4d fix(streaming): let a named release of a taken-over claim be a no-op
The stamp check ran after the ownership check, so a tab whose claim another player took over got a 403 and kept retrying instead of reading the release as a gone claim.
2026-09-17 20:13:58 -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
58de909b3e test(streaming): run a claim against the key a real exit marked
The old pair never made the next claim, and the claim-side test stubbed the wait with one that ignored its ids, so nothing tied the key the exit marks to the one the claim waits on.
2026-09-17 20:05:28 -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
932558903b fix(streaming): label the emulator on the resume preview and the EJS state reason
The resume preview on the launch screen and the EmulatorJS picker's
incompatible-core reason still showed the raw id, so a streamed RetroArch
state read "retroarch" under a heading that said RetroArch.
2026-09-17 18:53:53 -05:00
Zach Clendenen
3301b344a7 fix(streaming): start the stream volume bar at 60%
Matches the room's first-visit level, so the bar no longer shows 100
while the game plays quieter.
2026-09-17 18:53:38 -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
64fa4a0205 test(streaming): drive launch recovery through the status poll
The heartbeat never answers with a room and only beats once the game is on
screen, so the recovery tests fed it a reply it cannot send. The status poll
is what finds a running launch from the loading state.
2026-09-17 18:40:14 -05:00
Zach Clendenen
d545e13b3d fix(streaming): label the emulator on save and state picker cards
The pickers before a launch still showed the raw id, so a Play! save read
"play" there while every other asset chip named it.
2026-09-17 18:38:40 -05:00
Zach Clendenen
d3795cb1b8 fix(streaming): mark the save pull pending before save-and-exit lets go
A blocking save-and-exit with no state to pull deletes the key outright,
and the save pull was marked pending only after that. A claim winning the
container in between found nothing pending and hydrated the archive
before this session's. The pull is now marked while the claim still
holds the key, as the other teardown paths already do.
2026-09-17 18:36:04 -05:00
Zach Clendenen
1c3836cb1e fix(streaming): keep the unload release's query on older browsers
URLSearchParams.size arrived in Chrome 113 and Safari 17, both above the
floor in .browserslistrc. Below it the size read undefined, the query was
dropped, and the unload release lost its container and claim stamp: a
desktop tab's release then missed the desktop and leaked the claim.
2026-09-17 18:33:19 -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
f425fb5553 refactor(streaming): read the joinable filter from one place
The join walk and the joinable listing each spelled out what makes a
session joinable, kept in step by a comment. Both now ask access.
2026-09-17 16:56:34 -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
85079be5c5 fix(streaming): name RetroArch in the emulator labels
The labels map covers the ids a surface is handed rather than resolves,
and a save written under RetroArch carries "retroarch". With no entry
the asset chip showed the bare id.
2026-09-17 16:50:31 -05:00
Zach Clendenen
7e16bcb7ba test(streaming): cover a drain on a later pool member
The existing case marks the head of the pool, which the head-only read
also reported as draining. Mirroring it proves the refusal now reads
every member.
2026-09-17 16:50:31 -05:00
Zach Clendenen
b80d9af68c fix(streaming): scope the ended-session notice to the claim asked about
The tombstone is keyed per container, so the status poll walked a pool
reading any notice it found: an admin desktop's, or one from another
platform the container serves. A game tab then tore itself down with a
reason belonging to a claim it never held. The notice records the ended
claim's platform and kind, so the walk now applies the same scope the
live-session lookup uses.
2026-09-17 16:47:01 -05:00
Zach Clendenen
74577192a9 test(streaming): build the stream test's child stubs from one factory 2026-09-17 16:20:19 -05:00
Zach Clendenen
55eab7c59c test(streaming): cover the heartbeat CAS owner re-check and the desktop claim drop 2026-09-17 16:17:10 -05:00
Zach Clendenen
5021ef2fa0 fix(streaming): label the Play! emulator and the asset chips
Play! served PS2 sessions under the raw id "play", since it was missing from
the emulator display names, and the save and state chips showed whatever id
the broker recorded because the names never reached the frontend.

/config now ships the display names, and the chips and core group heads label
an id through them, falling back to the id for one the backend does not name.
2026-09-17 16:09:13 -05:00
Zach Clendenen
5233649ebd fix(streaming): join the session the caller asked for
An unnamed join stopped at the first pool member holding a live session, so a
desktop, another platform's game, the caller's own session or a ROM they cannot
see masked the session they were offered and the join answered 404 or handed
back somebody else's room.

The walk now skips a member that fails the same filter the joinable listing
applies and keeps looking, and the Join button carries the container of the row
it came from into the stream URL so the join names its session outright.
2026-09-17 15:59:57 -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
010e0fba4a fix(streaming): let a tab that missed launch-ready find its way in
The room URL only ever existed in the launch-ready push, so a socket that
dropped while the game was coming up left the tab loading forever over a
session that was running, with no way out but a release.

The session now records the room the launch answered with, the status poll
reports it along with the container it was found on, and a loading tab enters
the stream on that answer.
2026-09-17 15:36:05 -05:00
Zach Clendenen
c2e599439f fix(streaming): answer with the container a claim would win
/config listed containers with no key, so a platform whose only container is
misconfigured showed a Play button that could never stream, and it listed a
platform twice when two records spelled it in different case.

configured_emulator read the first record in the file rather than the first
member of the platform's pool, so the slot ceilings a save or load is checked
against could come from an emulator no claim ever reaches.
2026-09-17 15:28:42 -05:00
Zach Clendenen
3c310fae1c fix(streaming): report a draining container as nobody's and still saving
A drain marker holds a container key with no owner, so a 409 built from it
named no holder and the fleet list showed it as an idle container nobody
could claim.

The claim refusal now reads every pool member, reports the drain, and takes
the holder from a live session. The fleet list reports the drain as its own
state, and the settings panel calls it saving while keeping the desktop shut
until it clears.
2026-09-17 15:25:08 -05:00
Zach Clendenen
acdbcca41d fix(streaming): drop the claim when the session ended elsewhere
The player view kept its claim flag set after the backend told it the
session was gone, so the unload and unmount paths still sent a release.
By then the container had usually been handed to somebody else, and an
unnamed release reaches whatever the platform is running: their session,
not the one this tab had lost.

The ended path now clears the claim, and every release and heartbeat
from the view names the container and the stamp its claim answered with,
so a late one cannot reach a claim that replaced it. The launch-ready
handler also awaits its release before deciding the claim is gone,
instead of leaving the flag for the unmount path to act on again.
2026-09-17 15:11:55 -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
Zach Clendenen
dd6b949b6a fix(streaming): bind release and heartbeat to the caller's claim
A claim is the holder plus the moment they took it, so a tab that missed
its own takeover could still act on the claim that replaced it: its
unload release ended the new session and its beat kept it alive. Both
routes now take the claimed_at the claim answered with, and a mismatch
reads as a session the caller no longer holds: the release is a no-op and
the heartbeat reports ended, with the termination notice the displaced
tab needs.

Admin releases from the settings and activity panels end whatever is
running and send no stamp.
2026-09-17 14:50:32 -05:00
Zach Clendenen
09c8cf31f9 fix(streaming): tear a swept session down with its own container record
The stale sweep ran the teardown against the claimant's candidate, which
on a container serving several platforms is the wrong record: the stop,
the card evacuation and the state pull all went out under the emulator
the new claim wants rather than the one that was running. Resolve the
record from the session being swept and keep the candidate for the
reservation.
2026-09-17 14:46:53 -05:00
Zach Clendenen
9984f7dd27 fix(streaming): scope session lookups to the platform and skip desktops
A container can serve several platforms while holding one session, so a
lookup that starts from the caller has to match the platform it was asked
about. Otherwise a ps2 session shadows the same container's ngc row: the
claim reads as a duplicate and 409s, status reports it active on a
platform the caller holds nothing on, and an unnamed heartbeat or release
lands on it.

A desktop session is only reachable when the caller names its container,
which is what the desktop view does, so a game tab no longer beats or
releases an admin's desktop, and a desktop no longer blocks its admin's
own game claim. Occupancy is still the reservation's job: the claim walk
just fails that container's SET NX and moves on.
2026-09-17 14:44:15 -05:00
Zach Clendenen
84660d3c4b Merge remote-tracking branch 'upstream/master' into streaming-patches-5 2026-09-17 13:02:43 -05:00
Sam Dornan
c2ee769df7 fix(roms): load the parent rom alongside a rom file so the schema validates (#4593)
`GET /api/roms/{id}/files` 500'd on its success path: `RomFileSchema` reads
`is_top_level`, which needs `file.rom`, and `get_rom_file_by_id` only loaded
`track_meta` and `doc_meta`. Validation happens after `begin_session` closes,
so the lazy load raised `DetachedInstanceError`. The parent rom now comes
along in the same load, narrowed to the columns `Rom.full_path` needs.

`last_modified` is nullable in the column but was required in the schema, so
a row added outside a scan validated to nothing. It is now nullable to match,
and the regenerated frontend type follows.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-17 12:20:16 -05:00
Sam Dornan
bba15f95f4 perf(backend): resolve roms without the related load in the file and props routes (#4590)
* perf(backend): resolve roms without the related load in the file and props routes

Eleven routes opened with `get_rom(id)` to reach two scalars: `id` for the
404 and `id` plus `platform_id` for `assert_rom_visible`. `get_rom` runs the
whole `with_details` eager load, so each request paid for the platform,
files, metadata, saves, states, screenshots, rom_users, siblings,
collections and notes of the rom. The bulk delete was worse: it ran inside a
per-id loop, so an N-id delete ran the graph N times.

Three narrow projections replace it, alongside the `get_rom_visibility` that
#4587 added for the rom-note routes:

  `get_rom_visibility`        id, platform_id
  `get_rom_visibility_label`  the above plus the name pair the file-delete
                              log lines print
  `get_rom_deletion_target`   the above plus fs_path and the joined platform
                              label the bulk delete logs when a rom's file is
                              already missing from disk

`assert_rom_visible` accepts either narrow row as well as a full `Rom`, so
the check itself is unchanged for every other caller.

Statement counts per request, captured with the `executed_statements`
fixture in `tests/endpoints/roms/test_visibility_loads.py`:

  PUT  /api/roms/{id}/props                       19 ->  9
  GET  /api/roms/{id}/soundtracks/metadata        15 ->  5
  GET  /api/roms/{rom_id}/files/{file_id}/progress 20 ->  8
  DELETE manuals / walkthroughs / screenshots /
         soundtracks files                         20 ->  8 each
  DELETE /api/roms/{rom_id}/files/{file_id}        20 ->  8
  GET  /api/roms/{id}/files (hidden 404)           25 -> 13
  GET  /api/roms/{id}/files/content/{name}         25 -> 13
  POST /api/roms/delete, 1 id                      16 ->  6
  POST /api/roms/delete, 5 ids                     64 -> 14

The marginal cost of each extra id in a bulk delete falls from 12 statements
to 2.

The upload handlers on the same routers are left alone: `receive_rom_file`
hands the rom to `prepare_upload_destination`, so they need the full entity.
`Rom.fs_resources_path` moves its format string into a module-level function
so `RomDeletionTarget` can compute the same value.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* docs(backend): trim the change rationale out of the new docstrings

Greptile flagged the module docstring in the new test file, `_rom_lookup` and
`RomDeletionTarget` for carrying the reasoning behind the change rather than
describing what the code does. The rationale lives in the commit message and
the PR body, so the docstrings keep only the one sentence a reader needs.

The `assert_rom_visible` docstring loses the paragraph added alongside the
widened type union, which restated what the signature already shows.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* test(roms): share one rom factory in the visibility-load guard

Step 3 of the pr-ready gauntlet (simplify). The bulk-delete test built its
three roms from an inline `Rom(...)` literal; `test_random.py` already keeps a
module-local `_add_rom(platform, name)` for exactly this, so the guard grows
the same helper instead of a second copy of the field list.

`_flat` had one caller, so it folds into `_rom_lookup`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-17 12:18:22 -05:00
Zach Clendenen
5eb94afd6a polish(pr-ready step 4): build the lone-pool test's member once 2026-09-17 11:50:59 -05: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