* docs(api): document error responses for roms routes
Describe every 4xx and 5xx the rom routes and their helpers raise in each
decorator's responses=, so the OpenAPI schema lists them. A hidden rom,
platform or file is described like a missing one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): document error responses for saves routes
Describe every 4xx/5xx the saves, states, screenshots, snapshots,
play-sessions and sync routes raise in their responses=, and rewrite the
states identifiers docstring that carried Args/Returns blocks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): document error responses for devices routes
Describe the 4xx/5xx statuses that the device, device auth, install,
client token, notification, notification channel, sync channel and
heartbeat routes raise, and fill the empty install route entries.
Rewrite the setup and heartbeat docstrings that published Args and
Returns blocks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): document error responses for streaming routes
Describe the 4xx and 5xx statuses the streaming, memory card and netplay routes raise in their responses= declarations, and replace the Args: blocks in route docstrings that FastAPI published verbatim.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): document error responses for admin routes
Describe the 4xx and 5xx statuses the config, permissions, user, auth,
tasks, logs, activity and export routes raise, and rewrite their
Args/Returns docstrings as plain operation descriptions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): document error responses for library routes
Describe the 400/403/404/409/500 statuses the collection, feed, firmware,
platform, music, playlist and search routes raise, and replace route
docstrings that carried Args/Returns blocks with plain sentences.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): describe private collections and playlists as missing
Matches #5686, where another user's private collection or playlist
answers 404 and a play session on a hidden rom answers like a missing
one. The read routes drop their 403, and the write 403 now covers only
a public resource another user owns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): address Greptile review on route error docs
Fold the nine multi-paragraph route docstrings into one line, and keep
the device-scope 403 descriptions in utils/auth.py next to
resolve_device, which raises them, instead of in both saves.py and
states.py.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(api): plain-prose pass on route error descriptions
Spell out clipped error descriptions, replace internal slang (picked,
taken, live, moved past), name the parameter an ID comes from, and split
the long save conversion 400s into sentences.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(player): boot another device's save over a state from the same quit
States record no device, so the start screen could not tell a state written
by another client's core (Argosy) from one this browser wrote. When the newest
save names a device other than this browser and the newest state was written
within a few seconds of it, default to the save. This browser's own Save and
Quit still resumes from its state.
Fixes#5199
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(player): keep the newer-save warning beside a same-quit state
Addresses Greptile review on #5531: skipping a state from the picked
save's quit returned no warning even when a newer save existed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(states): record the device that wrote a state
States now carry origin_device_id like saves. POST /states and
PUT /states/{id} take an optional device_id, and new content takes the
writer's device (or none when the client names none). The web player
sends this browser's device id with every state, including held ones.
The start screen no longer defaults to a state tagged with another
device. The same-quit timing rule stays only for untagged states, which
covers states stored before this change and clients that send no device.
device resolution moves from endpoints/saves.py to utils/auth.py so
both asset endpoints share it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(player): drop the same-quit timing rule for untagged states
The start screen and the newer-progress warning now go by the state's
recorded device alone: an untagged state counts as this browser's, and
a state tagged with another device is neither the default nor a reason
to warn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(player): cover untagged states beside another device's save (code-review)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(player): simplify the resume fallback and repair a mis-collated state column (simplify)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(states): trim the origin device column comment (review-polish)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(sync): bind device tokens to their device; dial only known push-pull hosts
A client token paired to one device could read, reconfigure, delete, sync
saves for and record play sessions as any other device of the same user.
Device CRUD, sync negotiate/complete, push-pull trigger, the save device
resolver and play-session ingest now treat another device as not found for
a bound token, through a shared require_token_device helper. GET /api/devices
lists only the bound device.
Push-pull let any user with devices.write point ssh_host at any host and
port, and the connection error surfaced through the sync session, so the
worker could be used to probe the internal network. The SSH handler now
refuses a host with no trusted key or CA in the admin's known_hosts before
dialling it, which keeps LAN handhelds working while nothing else is
reached.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(device): revoke a deleted device's tokens; scope registration matches
Addresses Greptile review on #5460. Deleting a device now deletes the client
tokens paired to it, since the foreign key's SET NULL turned them into unbound
tokens that reach every device. Registration with a bound token only matches
its own device by fingerprint, so it can no longer reset syncs or overwrite
capabilities on another device.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(sync): bind heartbeat, sync session and online reads; pin push-pull ports
pr-ready step 2 (code-review xhigh --fix).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(device): one require_device helper; parse known_hosts once
pr-ready step 3 (simplify).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(sync): narrow await_args before reading known_hosts
pr-ready step 4 (review-polish).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(sync): plainer comments on the push-pull allowlist and token revoke
pr-ready step 5 (humanizer).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(device): keep bound tokens off other tokens; cascade tokens with their device
A device-bound token can no longer create tokens, or regenerate, pair or
revoke a token of another device or an unbound one. The save session_id
counter only counts a session of the caller's bound device.
client_tokens.device_id now cascades on device delete (0159), so no path
can leave an unbound token behind, and deleting a device records a
client_token.revoke audit event for each token it takes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(env): drop the push-pull allowlist note from env.template
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(client-tokens): let a client token revoke itself without me.write
A device that signs out or re-pairs had no way to revoke its own token
unless it held me.write, which also lets it mint tokens and approve
pairings. DELETE /api/client-tokens/{id} now skips the me.write check
when the id is the token authenticating the request.
Fixes#5274
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(client-tokens): code-review pass on self-revoke
Annotate raise_auth_error as NoReturn, trim the delete_token docstring, and
cover a me.write token revoking a sibling, the revoked token failing to
authenticate, and socket closure on self-revoke.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(client-tokens): revoke the calling token through DELETE /current
Self-revoke moves to an id-less route so a device never needs to know its
token id, and DELETE /{token_id} keeps me.write in its decorator and in
OpenAPI. The device-authorization token response now also returns token_id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(client-tokens): simplify pass, reuse raise_auth_error for /current
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* revert(client-tokens): drop DELETE /current and the device-flow token_id
Self-revoke stays on DELETE /{token_id} with the in-handler check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(device-auth): return the issued token's id from the device token poll
A device paired through the device-authorization flow can now revoke its
own token with DELETE /api/client-tokens/{id}, as tokens from /exchange can.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Update docs/BACKEND_ARCHITECTURE.md
* docs: format client tokens table
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- 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>
- record() takes the request as its actor, and a target can be a
function: the lookups that name it now run inside the recorder's error
handling, and for downloads only once the dedupe lets them record.
That also restores the minimal visibility query on the file route.
- One changed_fields/change pair for rom, user, collection and platform
edits, one collection helper, AuditActor.anonymous, a shared
count_in_window and current_device_id, one test helper for recorded
events and one fixture for audit events.
- The describers share simple/counted/visibility builders and the
eventData readers with notifications, join lists per locale, and treat
any *.delete as unlinked.
- EventLog builds one item list with the phase folded in, keeps each
event's sentence across pages, formats days once, and loads users
through the users store.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A socket joins its user's room, and an admin's the admin room, once at
connect time, so logging out or revoking a user's sessions left their open
sockets receiving notifications and the log stream. Each socket is now
recorded against the login session that opened it, and removing a session
disconnects those sockets on whichever worker holds them.
The main server takes one disconnect handler, so it moves next to the
connect handler and runs the activity cleanup as well.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>