When extracting the largest member of a .7z failed partway, the bytes already
streamed stayed in the file and ROM-level hashers, and the raw-archive
fallback was appended on top, giving a hash that matched neither. The hashers
are now restored to their pre-extraction state before the fallback runs.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* perf(backend): pipeline multi-command Redis writes
- upload_chunk records a chunk with SADD, EXPIRE and SCARD in one
transaction instead of three round trips, so a failure between them
can no longer leave the chunk set without a TTL.
- bind_to_login_session does its SADD and EXPIRE in one transaction for
the same reason.
- close_login_sessions reads and deletes a session's socket set in one
transaction, so a socket binding in between is not dropped unseen.
- Logout deletes the session and removes it from the user's set in one
pipeline.
- complete_chunked_upload reads the chunk set once instead of SCARD then
SMEMBERS; cancel and invalidate_filter_values_cache delete their keys
in one call.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* fix(backend): refuse a socket bind that lands after its session's revocation
- bind_to_login_session checks the login session still exists in the
same transaction as its SADD. Revocation deletes the session before it
reads the socket set, so a bind that finds it gone removes itself and
authenticate treats the socket as anonymous.
- complete_chunked_upload keeps its SCARD fast path and reads the
members only to name the missing chunks.
- cancel_chunked_upload removes the temporary files before touching
Redis.
- Tests check each pipelined write executes as one MULTI/EXEC.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* fix(backend): close an upload session before removing its files on cancel
A chunk PUT that passes the session check after the temporary directory
is gone fails with a 500; deleting the session first turns it into a 404.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* fix(backend): answer a chunk write cut short by a cancel with 404
A PUT that passed the session check before the cancel removed its
directory fails writing; it now re-reads the session and returns the
same 404 as a PUT that arrives after the cancel, instead of a 500.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* chore(backend): remove a stray Redis snapshot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Recompute the folder category for rows a Quick scan reuses, so files
categorized before the anchor fix are corrected without a Complete scan,
and annotate the new tests' parameters.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Retry the exit once when a broker boots the wrong core and the first exit
fails: the broker refuses every activate while that game runs, and the
released claim leaves nothing behind to stop it.
- Stamp the launch's core tier on the session and report it through the
status poll, so a tab that missed launch-ready still warns about an
untested or broken core, once.
- Translate the core-untested and core-blocked warnings in every locale.
- 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>
- Share one watched-transaction retry loop and live/gone split in the install handler
- Emit independent socket events concurrently
- Drop the dialog's redundant close watcher and repeated current-rom checks
- Reuse the add_device_token fixture and shared header fixtures in tests
- Fix mypy errors in the socket and handler tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
category_for_path_parts matched every segment of the library-relative
path and returned the first hit in enum order, so inner dump folders
(content/Game, content/CMCmn/demo), the rom folder itself, or even the
platform folder could set a file's category, and a bare `game` segment
outranked an `update` or `dlc` folder above it.
The scanner now passes the path relative to the ROM root, and only the
top folder there decides the category; deeper files inherit it.
Fixes#4581
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ScreenScraper's dedicated "PC Win9X" system (137) holds very few games;
Win9x titles are filed under the generic "PC Windows" system (138), which
acts as a fall-through like MAME does for arcade. Searching 137 meant
Win9x games only matched when scraped by ID.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(hasheous): match multi-file roms when one file is unknown
Hasheous' /Lookup/ByHash returns 404 for a batch as soon as any one SHA-1
in it is unknown, even when the rest match. A multi-disc CHD set with an
.m3u, a readme or an off-set disc beside it therefore never matched, e.g.
Final Fantasy VII (USA), whose three MAMERedump CHD hashes match on their
own.
- Leave .m3u playlists out of the lookup.
- When a multi-file batch misses, retry each file on its own, largest
first, and take the first match.
- Read the TheGamesDB id from "TheGamesDb", the spelling Hasheous returns,
so tgdb_id is no longer always dropped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TZeLXgA178Biwj7eUReck4
* fix(hasheous): require per-file matches to agree on one game
The per-file retry took the first file Hasheous knew, so a folder holding
an unknown game next to a known file from another game (a demo disc, a
bonus CD) could take on that other game's ids. Every file is now asked
and the match stands only when all known files name the same game;
conflicting answers match nothing and leave the lookup inconclusive.
A failed per-file request still ends the lookup as inconclusive, since
agreement can't be vouched for without every answer. The largest-first
ordering is gone, as nothing depends on the order any more.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TZeLXgA178Biwj7eUReck4
* test(hasheous): expect the per-file retry after a missed batch
test_lookup_rom_sends_all_top_level_file_hashes mocks a miss for two
files, which now also asks Hasheous about each file alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TZeLXgA178Biwj7eUReck4
* test(hasheous): build lookup fixtures as real RomFiles
The lookup tests cast MagicMocks to RomFile, which would hand lookup_rom
attributes a real RomFile lacks. They now build RomFiles, so file_extension
and lookup_hashes come from the model itself.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TZeLXgA178Biwj7eUReck4
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Reject installs of a rom missing from the filesystem
- Keep a request created during a device discard indexed
- Hold a strong reference to the device socket keepalive task
- Never raise from emit_permissions_changed after a committed change
- Map only a missing install request to 404, not any KeyError
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* perf(scan): download a rom's media files concurrently
download_rom_resources fetched the cover, manual, each screenshot, each
provider media type and every RetroAchievements badge one after another,
so a single ROM never used more than one of the ScreenScraper account's
request slots.
They now download together. ScreenScraper media still goes through its
existing thread and rate limiters, and badges share a new cap of 8 in
flight across all scans. The path columns and changed provider media
dicts are written back in one update.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* style(tests): sort imports with the Trunk isort config
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* fix(scan): code-review fixes for concurrent media downloads
- Run provider media dicts one after another, since they share paths
- Await every download before raising the first failure (gather_all)
- Fetch each duplicate media or badge path once (store_ra_badges)
- Reuse store_ra_badges in update_rom
- Share the in-flight test helper and trim comments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* refactor(scan): simplify pass on concurrent media downloads
- Move gather_all to utils/concurrency and unpack its results directly
- Let write_file_streamed create the badge directory instead of every badge
- Share the in-flight test helper through tests/concurrency_stubs
- Stub downloads with AsyncMock through one fixture, drop a redundant test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* fix(scan): save the paths that landed when a provider download fails
Cover, manual and screenshot paths are written before a provider media or
badge failure is re-raised, so a failure there no longer loses them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* fix(scan): save each download group's results independently
Paths, provider media and badges each keep their own outcome, and every
change that landed is written before the first failure is re-raised. The
test builds a real Rom instead of a namespace.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(deps): bump redis to 8.1 and fakeredis to 2.38
redis-py 6.2.0 -> 8.1.0 and fakeredis 2.30.1 -> 2.38.0. RQ 2.12
(redis!=6,>=3.5) and fakeredis (redis>=4.3) both accept redis 8.
fakeredis 2.38 types FakeServer's version argument as a tuple, so pass
(7,) instead of 7. Behaviour is unchanged since fakeredis normalises an
int to a one-element tuple.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx
* chore(deps): drop types-redis in favour of redis-py's own types
types-redis only covers redis 4.6 and shadowed the inline types that
redis 8 ships, so mypy was checking calls against a stale API. Removing
it also drops its transitive stub packages (types-cffi, types-pyopenssl,
types-setuptools), which nothing else uses.
redis-py's types differ from the stubs in three ways:
- Redis, AsyncRedis and Pipeline are not generic, so drop the [str] and
[bytes] parameters.
- Responses are typed bytes | str regardless of decode_responses, so cast
at the few call sites that rely on the decoded (or raw) type.
- watch, unwatch, multi, aclose and execute_command are unannotated, so
add redis to untyped_calls_exclude, as is done for rq and apprise.
Also replace setex, deprecated in redis 8, with set(..., ex=...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx
* fix(device-auth): replace deprecated GETSET with SET ... GET
code-review step. GETSET is deprecated since Redis 6.2 in favour of
SET with GET. Using it with ex= also sets the poll key's TTL in the same
command, instead of a separate EXPIRE that a crash could skip.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* 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>
* fix(ra): keep a hash match when RA's details request fails
The hash index names the game before get_rom asks RA for its details. When
that request failed, the empty reply hit the KeyError fallback and came back
as ra_id=None, which a hashes scan read as a confirmed miss and used to clear
an existing hash_match. An empty reply now raises unavailable, so the scan
marks RA inconclusive and keeps the flag, as it already did for a failed
index download.
Also reads fs_resource_handler from its defining module, which strict mypy
requires (same change as #4821).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* style(ra): keep only the provider behavior in the empty-details comment
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>
* 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
* 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
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(ra): count RomM's own RA hash match as RetroAchievements verification
The RetroAchievements verification chip, the header Verified badge and the
library verified filter only read Hasheous' `ra_match` flag. RetroAchievements
hashes only part of some ROMs (NDS, PSP), so Hasheous never flags those from
their file hashes, and a ROM RomM matched to its RA game by RA hash still
showed a grey chip.
The RA handler now records `hash_match` in `ra_metadata` whenever the ROM's
RA hash is one RetroAchievements lists for the matched game, whichever route
found the game (hash lookup, Hasheous-supplied id, filename tag, update scan
or a manual edit). The frontend verification helper and the backend verified
filter count it alongside Hasheous' flag. Existing ROMs pick it up on their
next scan.
Fixes#4801
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
* style: satisfy trunk isort and no-emdash-in-comment
Sort imports with the repo's .isort.cfg and replace the comment em-dashes
in MetadataTab.vue that trunk flags once the file is modified.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
* fix(ra): address code-review findings on the RA hash match
- A HASHES rescan whose RA lookup ran and found nothing clears
`hash_match`, mirroring the Hasheous guard; a lookup that errored keeps it.
- A manual RA id change that can't be resolved no longer keeps the previous
game's `hash_match`.
- `_search_rom` no longer caches a failed hash-list download ({}) as an
empty index for the whole refresh window.
- Update the `verified` filter description and trim the romVerification
header comment.
Step: pr-ready code-review (xhigh --fix)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
* fix(ra): don't let a failed hash check block an RA ID lookup
`get_rom_by_id` now treats the hash-list check as secondary: on failure it
logs, keeps a match already recorded for the same game, and still returns
the game. A failed hash-list download raises "RetroAchievements
unavailable" instead of reading as "no match", so scans treat RA as
inconclusive and keep the stored flag.
Addresses the Copilot and Greptile review findings on ra_handler.py.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
* refactor(ra): simplify the RA hash-match verification
- Cache the parsed RA hash index per platform, keyed by the cache file's
mtime, so a scan parses it once instead of once per ROM.
- Check the hash only after `get_rom_by_id` has resolved the game.
- Give each frontend verification database its own `matches(rom)`, which
drops the `ra_match` special case in the shared helper along with
`matchesDatabase` and `VERIFICATION_KEYS`.
Step: pr-ready simplify
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
* style(v2): polish romVerification naming and comment
Rename the Hasheous matcher factory to `anyHasheousFlag` and trim the
VERIFICATION_DATABASES comment to two lines.
Step: pr-ready review-polish
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
* fix(ra): keep a recorded hash match only for the same RA hash
When the hash-list check fails, `get_rom_by_id` now keeps a stored
`hash_match` only if both the game and the ROM's RA hash are unchanged, so
a rehashed ROM isn't left verified by a hash nobody checked. The
romVerification tests build on the shared typed `SimpleRom` fixture
instead of casting a bare object.
Addresses the Greptile review findings on ra_handler.py and
romVerification.test.ts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LfQbq2ZUFK53NMXPNktdaM
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
compare_save_state decides a side changed from its timestamp, and
emulators rewrite a save on exit, so an untouched save looks new and a
server change elsewhere turns into a false conflict.
device_save_sync now records what each side held at the last sync
(last_sync_hash from the device, last_sync_server_hash from the server,
migration 0140). A baseline match proves that side unchanged; a mismatch
or NULL falls back to the timestamp logic, so this only removes
conflicts. It runs after the removed_at check in compare_save_state.
- Baselines are recorded only for versions the device provably holds:
confirm_download pins to the served version, update_save records the
client hash only when the file was uploaded, deduplicated uploads and
pushed saves record against the surviving save, and push-pull no-ops
record hashes only for identical content.
- Identical-content no-ops in negotiate and the watcher record a
boundary without re-tracking untracked saves.
- The SSH push-pull and file-transfer watcher paths hash device saves
through hash_save_file, matching compute_content_hash for zipped
saves, and treat unreadable saves as unknown.
Squashes rommapp/romm#4768 onto master.
Claude-Session: https://claude.ai/code/session_01WAKUdfLb6fyduEqaFbf5A8
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>