`directory_exists` and `Rom.full_path` already spell out the check the
scan does at its own call site, so the path is no longer rebuilt here.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Name the candidate predicate for what it checks, trim the ordering
docstring, and drop the comments the moved guards made stale.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sort title id sources with the natural key the models already compute,
give the compressed suffixes one home, and let SigilService reject a
container itself rather than trusting every caller to.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Order discs by their number so "Disc 2" precedes "Disc 10", test one
rule for containers sigil cannot read, and drop the unreachable
OSError handler around Path.is_file.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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>
ScreenScraper catches its own rate limit and breaker, so the miss they
cause never reaches resolve_fetch and was still written up as confirmed.
Hasheous had the opposite gap: an unanswered hash lookup still counted as
attempted, so a complete rescan cleared the id the lookup could not redo,
and a disabled handler reports the same flag as an outage without ever
having been consulted.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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>
ruff ASYNC110 flags a while loop whose body is only an await sleep. The
wait is now a bounded poll that gives up with a TimeoutError once the
lock expiry has elapsed, so a stuck holder cannot hang the upload.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
redis-py releases its Lock through a Lua script, which the fakeredis CI
runs without, so every registration failed there with an unknown evalsha
command. The lock is now a SET NX EX with an owner token, released only
by its owner, the same shape the log forwarder already uses.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A folder the scanner maps to a media category now refuses files that
category cannot hold inside resolve_upload_destination, so the chunked
flow the v2 tabs use gets the same allowlist the media routes had, and
those routes drop their own copies. commit_upload records an upload
provenance for walkthrough files that arrive without one and returns the
registered row, which the walkthrough route uses for author and title.
The refresh lock moves to Redis so uploads landing on different gunicorn
workers cannot drop each other rows. An empty body filename is rejected
instead of falling back to the header.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`has_live_worker` asks RQ for the worker count and the suspension flag,
two constant-cost reads, instead of hydrating every registered worker.
The cleanup stats serialize through `dataclasses.asdict`, so a new
counter is declared in two places rather than three. The task endpoint
test takes the shared task fixture, the legacy-stats shim says when it
can go, and the two Settings specs share one axios-error helper under
`src/test-utils` while the games spec starts from a non-empty list.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9ta8rXUTP9aMdatPYKX4K
Follow-up to #4548 from the code-review pass. Stats a 5.2.0 release
stored under `platform_id` are widened to `platform_ids` when a job is
reported, so listing old finished cleanups validates again. The live
worker check moves next to the queues as `has_live_worker`, with its
own tests, and the endpoint names the queue it enqueues on so the check
and the enqueue cannot drift apart. The cleanup tasks return the typed
stats the response schemas declare. The developer setup points the RQ
commands at the backend's own Redis settings through `-c config`, and
the architecture doc mentions the 503.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9ta8rXUTP9aMdatPYKX4K
The Files tab streamed chunks through /roms/upload/* and registered the
result with the scanner listing, while each Media route (soundtracks,
screenshots, manual files, walkthrough files) carried its own copy of the
sanitize, promote, mkdir, stream, stat and DB upsert sequence. Those copies
crashed with FileNotFoundError on a file name outside Latin-1: the browser
sends the header as Latin-1 and the multipart field name as UTF-8, so the
parser target registered under the header name never received the part
and os.stat failed after the folder had been created.
handler/rom_upload.py now owns the shared ingestion (resolve and prepare
the destination, stage next to the target, move into place, refresh the
ROM's file rows through the scanner) and both the chunked completion and a
new receive_rom_file sit on it. The media routes only check the extension
and delegate; a body naming the part differently is a 400. /start gains an
optional body filename that wins over the header, so names outside Latin-1
arrive intact, and rom_id becomes optional in that body.
On the v2 frontend a single useRomFileUpload composable wraps the chunked
upload, the single-file conversion prompt, the toasts and the refetch; the
Files tab, Soundtrack panel, Screenshots subtab, Walkthrough subtab and the
manual "add to ROM folder" target all call it with their folder. The
service sends the real name in the body and a percent-encoded one in the
header. The v2-only uploadScreenshots/uploadWalkthroughFiles service
functions and the soundtrack-only toasts are gone. Media subtabs now
refuse an existing file name (409) like the Files tab, instead of
overwriting it silently.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X1FgnCzXjM3rzkxggi7g6C
The save and state delete endpoints carried the same row, file and
screenshot removal sequence inline. `remove_asset_file` and
`remove_screenshot` now live in the asset store, and each endpoint
keeps a one-line `_delete_save` / `_delete_state` over them.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
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.
Slot pruning is one locked handler query that selects only the tail of
the slot by column, so an upload no longer loads every joined version;
the retention tests share their seeding helpers. Both asset lists fold
their groups through one useGroupFold composable, render the owner chip
through one AssetOwnerChip, and AssetStrip tracks each group's newest
timestamp while it builds the group. The two upload dialogs share a
PendingFilesDropzone for the drop zone and file list. The slot title
and the newest-by-timestamp lookup live in the utils next to their
siblings. The split states layout aligns its label and content rows
with a subgrid instead of hand-matched heights, so AssetPreview loses
the consumer-driven eyebrow height. Stories take explicit ids.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Correctness: the upload dialog seeds dropped files immediately (three of
its tests ran vacuously), dedupes them by name, submits on Enter and
rejects a blank slot name; slotted manual uploads are new versions even
when the bytes match; the core picker sees the nightly cores the player
offers; clearing a state hands the boot back to the save it displaced;
a slot or core group can be folded even while it holds the selection
and reopens when the selection moves into it; the entrance stagger
counts only rendered rows; the stream save picker keeps its flat list;
slot retention orders by id as a tiebreaker for same-second uploads.
Reuse: asset helpers shared by both lists move to v2/utils/assets.ts,
the write slot follows the picked save in one place, the upload payload
carries its type, and the endpoint's delete sequence is one helper.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
lookup_rom already tells a real "nothing knows these hashes" apart from a
provider that never answered, and only the HASHES de-verify guard read it.
A 429, a 500 or a timeout therefore logged the ROM as not identified in
the same words as a genuine coverage gap, and the reporter spent two days
treating transient failures as gaps. Track the sources that gave no answer
and say so in the outcome.
Retrying in-scan, or persisting a revisit marker, would change what the
nightly QUICK scan covers, so it is deliberately not part of this.
Refs #4398
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
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.
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.
The Playmatch switch shipped its choice as a standalone `playmatch_enabled`
flag, but the backend gates the lookup on `MetadataSource.PLAYMATCH in apis`
and nothing ever read the flag, so UI-initiated scans never queried
Playmatch. Push `playmatch` into `apis` like `hasheous`, and drop the dead
flag from the payload and the scan plumbing.
Fixes#4505
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
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.
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>
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>
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>
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>
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>
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.
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.
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.