Commit Graph

11716 Commits

Author SHA1 Message Date
Georges-Antoine Assi
6161f8057d refactor(screenscraper): report a short-circuited lookup per rom
A tripped breaker answers in ScreenScraper's place, so the empty match it
produces is not a miss and must not clear the rom's stored ss_id. The scan
learned that by sampling the module-wide is_breaker_tripped() at three points,
which reads another rom's trip as this rom's evidence.

SSHandler now raises ScreenScraperExhaustedError instead of swallowing the
breaker's error, carrying the match it would have returned so the name the
filename lookup derives locally (Switch title database, MAME, PS2 OPL) still
reaches the scan. fetch_ss_rom catches it the way it already catches
ScreenScraperRateLimitError, and drops ScreenScraper from attempted_sources
from a plain local, so the signal is exactly this rom's own lookups.

Also folds in a cleanup pass over the branch: the dead default_factory arm in
_ScanState.reset(), one home for the ssuserInfos.php path, asyncio.wait_for
around the quota probe so it cannot block behind a media download holding the
concurrency slot, and shared fixtures for the ScreenScraper tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 21:35:25 -04:00
Spinnich
63d58ab65e fix(screenscraper): only resume on a readable quota reading
The re-check treated any ssuser block as fresh evidence, because it
compared limits by identity. A block whose counters are missing or
unparseable replaces the limits with an all-empty reading, so
remaining_requests is None rather than a count, and the probe cleared
the breaker and logged that the quota was back without ever learning
that it was.

Resuming now needs a count that is actually there and above zero. The
identity check stays: a body with no ssuser block at all leaves the
pre-wall limits in place, and those still show headroom.

Addresses Greptile's review comment on screenscraper.py:757-763.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 16:45:53 +00:00
Spinnich
0d7ce16d16 fix(screenscraper): let the daily-quota breaker recover
HTTP 431 means a ROM did not match and the daily cap on proposing unknown
ROMs for review is reached; scraping is unaffected, so it becomes a
not-found with one informational line per scan instead of a refusal that
takes the provider out.

HTTP 431 is really two answers at once and only one of them concerns the
scan. The scrape allowance (430) still trips a breaker, since every
remaining ROM would otherwise cost a round trip to be told the same thing,
but it now arms only after repeated refusals, ignores the ones already in
flight when a refusal was counted, and re-checks the free account endpoint
so it recovers without a scan to reset it. The account check can no longer
arm it at all.

A recoverable breaker can clear itself while a rom is still gathering its
other providers, so a complete rescan read it as having answered and wiped
the rom's id. It is now sampled where ScreenScraper is consulted.

The manual-match search gathers every provider without return_exceptions,
so it now swallows an exhausted ScreenScraper the way the scan lookups do.

Fixes #4123

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 15:08:18 +00:00
Georges-Antoine Assi
d10bae8665 Merge pull request #4355 from Spinnich/fix/v2-collections-virtual-setting
fix(collections): honor "Show autogenerated collections" on the v2 collections page
2026-09-04 22:16:28 -04:00
Georges-Antoine Assi
76f0fc6cd8 i18n: mention the collections page in the autogenerated toggle
The en_US/en_GB description gained the collections page; carry that into
the other 16 locales so the toggle doesn't describe two of its three
surfaces everywhere but English.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:08:58 -04:00
Georges-Antoine Assi
4166ca6477 test(collections): pin the ?kind=virtual reset to the URL
The fallback test only read the rendered list, so it passed whether the
view cleared the query param or merely reset its local filter, and it
seeded the preference before mount so the runtime flip went uncovered.

Hold the setting in a live ref the tests can flip after mount, assert the
router.replace that drops the param, and add the turn-it-off-while-
filtered case.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:08:13 -04:00
Georges-Antoine Assi
e57c5e471c Merge pull request #4353 from Spinnich/fix/complete-rescan-clears-attempted-ids
fix(scan): let a complete rescan clear the ids it rematched
2026-09-04 21:59:48 -04:00
Georges-Antoine Assi
6dd3353855 refactor(metadata): give the unreachable-provider error one home
The same 503 was built inline at seven sites across the metadata handlers, and
the previous commits added two more copies of it as per-handler `_unavailable`
helpers. `base_handler.unavailable(provider)` now builds it for all of them.

Also renames the search endpoint's cover filter to say what it does and types
the scan test's lookup factory.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 21:16:07 -04:00
Georges-Antoine Assi
3b2a9e3043 refactor(scan): share one failure path across the provider lookups
Every gathered provider already resolved through a single loop that logs the
failure, drops the source from the attempted set and falls back to an empty
match. SteamGridDB, which searches on the names the other providers produce and
so cannot join that gather, hand-wrote the same three steps again, and the
search endpoint hand-wrote a third copy. Extract the loop body into
`resolve_fetch` and route SteamGridDB through it.

In the search endpoint the cover gathers now tolerate exceptions instead, so a
failed lookup costs a thumbnail rather than the whole result set. That also
covers Libretro, whose lookup had no guard at all and could fail the request.

On the test side, the platform, rom and `fs_rom` scaffolding was written out
three times across the two scan tests; it now lives in `tests/handler/scan_stubs.py`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 20:58:27 -04:00
Georges-Antoine Assi
8b2931a56d fix(scan): don't let a Hasheous outage read as a conclusive miss
`_request` swallowed a non-404 HTTP error and a timeout into an empty dict,
which `lookup_rom` then reported as conclusive: Hasheous answered and knows
nothing about these hashes. A 500 or a timeout therefore de-verified a rom on
a rehash and cleared its id on a complete rescan.

Both paths now raise, so the conclusive flag already carried by `lookup_rom`
tells the two empty matches apart on its own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 20:58:18 -04:00
Georges-Antoine Assi
4db67ff039 Merge pull request #4352 from Spinnich/fix/ra-skip-games-without-achievements
fix(retroachievements): don't match ROMs against games with no achievement set
2026-09-04 20:25:58 -04:00
Georges-Antoine Assi
09f0001aa1 Merge pull request #4345 from sdornan/feat/platform-folder-aliases
feat(scan): resolve Batocera, RetroBat and ES-DE folder names to platforms
2026-09-04 20:24:43 -04:00
Georges-Antoine Assi
d2da0c3e25 refactor(scan): trim platform resolution docstrings
Cut the prose that narrates the function bodies and the Args blocks that
restate the signatures, keeping only the non-obvious contract: when
resolve_fs_slug returns None.

Rename test_reverse_map_is_unambiguous to say what it asserts, that the
reverse map agrees with the alias table.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 19:15:08 -04:00
Georges-Antoine Assi
996d12adea feat(metadata): add RPG Maker platform and resolve easyrpg folders
Batocera, RetroBat and ES-DE all ship an `easyrpg` folder for RPG Maker
2000/2003 games, but RomM had no platform for them, so the folder fell
through as an unmatched platform that matched no metadata.

Add UniversalPlatformSlug.RPG_MAKER and wire it to the two providers that
carry the platform: ScreenScraper (system 231, "EasyRPG") for metadata and
libretro (system "RPG Maker") for thumbnails. IGDB, MobyGames and TheGamesDB
have no RPG Maker platform, so they stay unmapped, the same way DOOM is
wired.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 19:09:21 -04:00
Spinnich
69501c00a8 fix(collections): honor "Show autogenerated collections" on /collections
The v2 collections index fetched and rendered virtual collections
regardless of the `showVirtualCollections` UI setting, so users who
turned the toggle off still got them on the page the v2 UI makes the
primary home for collections. The v2 home page already gates on it,
leaving the two sibling views disagreeing about the same preference.

Read the setting (and the virtual collection type) from useUISettings
rather than raw localStorage, skip the fetch and the list entries when
it is off, drop the virtual option from the toolbar's kind cluster, and
snap a stale `?kind=virtual` back to `all`.

Fixes #4348

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:31:40 +00:00
Georges-Antoine Assi
80185b225c refactor(scan): resolve platform folder names in both directions
Fold the folder name resolution into one home and make it case-insensitive
end to end.

Config folder names are lowercased as the config is parsed, so bindings,
versions and the built-in alias table are all matched the same way. A SNES/
folder now resolves, and a binding written GameCube: matches a gamecube/
folder.

Add resolve_fs_slug(), the inverse used to recover a renamed folder, which
replaces the two swapped dicts in scan_platform. Only slugs reached by
exactly one folder name are reversible, so recovery never guesses between
amiga500, amiga600 and amiga1200.

Validate system.platforms and system.versions through one helper that
rejects empty and non-string values, and treat a null block as empty rather
than exiting.

Restore the atari800 override in the example configs: its folder name is
itself a RomM slug, so it can never be an alias. A new test derives the
needed overrides from the alias table to keep the examples honest.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 17:32:07 -04:00
Georges-Antoine Assi
78dc34bdda Merge pull request #4344 from sdornan/claude/github-issue-4226-eab53e
fix(export): write gamelist media where ES-DE and Batocera frontends find it
2026-09-04 16:53:20 -04:00
Spinnich
24bc4c221b fix(scan): don't let a failed lookup clear the id it couldn't check
A complete rescan clears the id of every source it consulted that came back
empty. That reads an outage as a conclusive miss for the providers that report
a failure as an empty match, so a rescan run while one was down wiped the id it
would otherwise have confirmed, hand-set ones included.

Each of those now reports the failure and leaves the tolerance to the caller,
which is what the gather loop's discard already assumed:

- Pouët, CSDb and Demozoo stop swallowing the 503 their own `_request` raises,
  and Pouët's title search raises it rather than answering "no unique title".
- SteamGridDB and Flashpoint stop catching `Exception` around a whole lookup;
  HLTB stops catching it around its search.
- ScreenScraper answers empty for every remaining ROM once its daily-quota or
  credentials breaker trips, so the scan reads that state off the service and
  drops it from the sources the rescan may clear.

SteamGridDB resolves outside the gather and so needs the discard at its call
site. Search keeps degrading to no thumbnail, since its cover art sits on top
of matches the other providers already produced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 20:49:51 +00:00
Georges-Antoine Assi
5837ac3df9 refactor(config): name the two default dir lists for what they exclude
DEFAULT_EXCLUDED_DIRS only ever seeded EXCLUDED_PLATFORMS, but its name
implied it was the general directory list, which is how the media folders
came to be added to it in the first place. Rename it and its superset to
DEFAULT_EXCLUDED_PLATFORM_DIRS and DEFAULT_EXCLUDED_MULTI_FILE_DIRS, and
spell out what a multi-file ROM is.

DEFAULT_EXCLUDED_FILES and DEFAULT_EXCLUDED_EXTENSIONS keep their generic
names: each still feeds both a single-file and a multi-file-parts exclusion.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:42:43 -04:00
Georges-Antoine Assi
8cc1e8bd15 style(gamelist): trim the media map comments to the non-obvious why
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:29:56 -04:00
Georges-Antoine Assi
65b2a050c1 refactor(gamelist): give the ES-DE media folder names one home
Fold the exporter's folder map and the importer's ESDE_MEDIA_MAP into a
single GAMELIST_MEDIA_DIRS, so writing, reading and skipping a media type
is one edit. This also picks up thumbnails/, which the scan exclusions were
missing, and drops the hand-appended "images" literal.

Serve the multi-file defaults pre-unioned as DEFAULT_EXCLUDED_MULTI_DIRS so
neither UI has to re-join two lists; v1 was still mapping EXCLUDED_MULTI_FILES
to DEFAULT_EXCLUDED_DIRS and rendering the media dirs as deletable.

Collapse the per-tag asset loop and the bespoke <mix> block into one table
keyed by tag, and skip fnmatch for the exclusion patterns that hold no glob
characters, now that the multi-file list is more than twice as long.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:19:55 -04:00
Georges-Antoine Assi
aff25e5013 Merge branch 'master' into claude/github-issue-4226-eab53e 2026-09-04 16:06:33 -04:00
Georges-Antoine Assi
250a063ae8 Merge pull request #4340 from rommapp/perf/scan-progress-coalesce
perf(scan): coalesce scan progress reports, and give the rom refetch one home
2026-09-04 16:00:52 -04:00
Georges-Antoine Assi
5cc6a98c1b refactor(v2): name the rom refetch for what it touches
`refetchCurrentRom` no longer reads or writes `currentRom`: `syncCachedRom`
owns that write and applies the identity guard. The name promised a function
that acts on the open rom; it fetches the rom it is given and applies it
wherever it is cached, so `refetchRom` is what it does.

Also trims the two comments that had grown past what they explain.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 15:54:44 -04:00
Georges-Antoine Assi
ccc950f72e refactor(scan): let the terminal event own the progress flush
`scan_platforms` ends in four places, and three of them had to remember to
flush the counters a coalesced increment held back. The fourth, the early
return on a folder structure it cannot read, did not, and was correct only
because it sits above the first report. `finish` pairs the flush with the
emit so every exit gets both, including that one.

The failure path's guard around the flush goes with it. It was protecting
against an emit that fails, one line above an emit that would fail the same
way and is not protected, and `update_job_meta` already swallows its own
errors, so it bought nothing.

Also: `refetchCurrentRom` wrote `currentRom` twice, once directly and again
through `syncCachedRom`, which owns that write and applies the same identity
guard. `useRomScanRefresh` kept an `alive` check that `useSocketEvent`'s
unsubscribe already covers; its test was passing on the check rather than the
unsubscribe, so the socket mock now actually unsubscribes. DeleteManualDialog
was the tenth surface still spelling out the refetch by hand, and seven
components kept a rom store binding nothing reads any more.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 15:42:20 -04:00
Spinnich
0d497018c7 fix(scan): let a complete rescan clear the ids it rematched
A complete rescan is documented as wiping every external id and matching
again from scratch, but it only wrote NULL for deselected sources. Selected
ones were assumed to reset implicitly by staying out of rom_attrs, which
merge then skips rather than nulling, so a provider that searched and found
nothing left its old (wrong) id in place.

Track the sources whose lookup actually ran and clear those too. A source
skipped because the platform carries no id for it never enters the set, so
hand-set ids on unmapped platforms survive, and a provider that raised or
hit the ScreenScraper rate limit is discarded again since it ruled nothing
out. SteamGridDB resolves after the reset block, so it clears its own id.

Fixes #4346

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 19:28:41 +00:00
Georges-Antoine Assi
534033773e fix(scan): report a scan's progress on the paths that skipped it
Two gaps the coalesced reporting left open.

A scan that fails between a held-back increment and its end never
published the counters that increment held, so the task meta and the
progress view kept a stale snapshot of a scan that had gone further. The
failure path now flushes before it says the scan failed, and a flush
that cannot be delivered is logged rather than raised in place of the
error the scan is reporting.

`_published_at` also started at `0.0`, which reads as a report that has
already happened. A monotonic clock counting from boot can sit under the
interval, and the first increment would be coalesced away against a scan
that had never reported at all. It starts at `None` instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 15:27:55 -04:00
Georges-Antoine Assi
51e0f0fc2e Merge remote-tracking branch 'origin/master' into perf/scan-progress-coalesce
# Conflicts:
#	backend/endpoints/sockets/scan.py
2026-09-04 15:23:43 -04:00
Sam Dornan
7a54b1c6b0 Merge branch 'master' into feat/platform-folder-aliases
Master moved UniversalPlatformSlug to utils/platform_slugs.py so that naming
a platform no longer imports the metadata stack. The alias table and its
test now import the enum from there, and utils/platforms.py keeps both the
new leaf import and the resolver import.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 14:05:13 -05:00
Spinnich
b45a410991 test(retroachievements): cover the hash index cache filename bump
Nothing failed if the cache filename went back to ra_hashes_v2.json, which
would leave upgraded installs serving the unfiltered index until its mtime
aged past REFRESH_RETROACHIEVEMENTS_CACHE_DAYS.

Back the resources directory with a real temp directory so the freshness
check reads a real mtime, and assert a v2 index on disk is refetched rather
than reused.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 18:49:17 +00:00
Spinnich
bbc1e63d69 fix(retroachievements): don't match ROMs against games with no achievement set
The hash index was built with RA's f=0, so it mapped hashes of games that
exist on RetroAchievements but have no achievements. Those ROMs came out of
a scan with an ra_id set, which lit up every RA signal (achievements tab,
match chip, has_ra filter, smart collections) while answering the only
question those signals are asked: no, there is nothing to earn here.

Measured live against N64 (system 2), 45% of indexed hashes pointed at
set-less games; NES and PlayStation are above 60%.

Switch to f=1 and bump the cache filename, since the freshness check is an
mtime test and installs would otherwise keep the stale index for up to
REFRESH_RETROACHIEVEMENTS_CACHE_DAYS.

Fixes #4343

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 18:49:17 +00:00
Georges-Antoine Assi
2dce598db0 Merge pull request #4333 from rommapp/feature/sigil-title-ids-followups
Follow-ups to the sigil title ID branch
2026-09-04 14:43:03 -04:00
Georges-Antoine Assi
eec574b49b fix(metadata): give UniversalPlatformSlug a leaf home
Both CI failures came from one import cycle. RQ could no longer resolve
`endpoints.sockets.scan.scan_platforms`, and the e2e seed script failed the
same way, because `sigil` imports the platform slug enum, importing anything
under `handler.metadata` runs its `__init__`, that reaches `gamelist_handler`
which imports `handler.filesystem`, and `roms_handler` there imports `sigil`
back while it is still half-initialised.

The cycle predates this branch. It stayed hidden because `scan.py` reached
the enum through `utils.switch`, imported late enough that
`handler.filesystem` was already loaded; naming the adapter directly moved
that import to the top of the module and the ordering luck ran out.

So the enum moves to `utils/platform_slugs.py`, which imports nothing but
`enum`. Naming a platform no longer drags in httpx, redis and the titledb
task, and the 29 call sites point at the module that owns it rather than
picking it up from a 1000-line metadata handler that happens to re-export
it. `import adapters.services.sigil` now also works on its own, which it
did not before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 14:28:49 -04:00
Sam Dornan
7512aea057 docs: name the emulation frontends whose folder names resolve automatically
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 11:08:08 -05:00
Sam Dornan
994fddcbe5 feat(scan): resolve Batocera, RetroBat and ES-DE folder names to platforms
Frontend system folders such as gamecube, megadrive or n3ds only became
RomM platforms after the user copied a 100+ line system.platforms map into
config.yml. A built-in alias table now covers the folder names those
frontends use, seeded from the two example configs and cross-checked
against the upstream system lists.

Resolution order is unchanged for existing users: config bindings and
versions win, a folder name that already is a slug keeps matching itself,
and only then is the alias table consulted. The two call sites that
resolved folder names by hand share one resolver.

The example configs shrink to genuine overrides. The Batocera example
also mapped odyssey2 to the original Odyssey; the alias points at
Odyssey 2.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 10:59:20 -05:00
Georges-Antoine Assi
c4ff894741 fix(scan): keep a rom's title id consistent with the bytes just read
Three problems the review pass turned up, all in the title id path.

A HASHES rescan re-reads every byte but `_should_extract_title_ids` only
exempted COMPLETE, so replacing a file in place left the previous binary's
title id and save target beside the new hashes. That row is
self-inconsistent, and the stale save target points saves at the wrong
game's folder. A scan that re-reads the bytes now re-reads the id too.

`refresh_rom_files` extracted title ids and then dropped `parsed.identity`
on the floor. Since only Switch populates `content_type`, the parse of every
changed file on PSP, PS2, PSX, Wii and the rest had no observable effect at
all, and a rom with no stored id never gained one from a quick scan or an
upload. The identity it reads is now persisted, guarded so a parse that read
nothing leaves the stored triple alone.

The Tinfoil feed keyed its titledb index on `str(index_entry.get("nsuId"))`
and then tested that for `None`, which `str()` had already turned into the
string "None". Entries without an nsuId were stored under that literal key,
each one overwriting the last, instead of being skipped.

Also revert the heartbeat to `cm.get_config()`. Reading the last-parsed
config avoided a YAML re-parse, but the same request already triggers
several through `get_platforms()`, so it bought nothing and left the
endpoint reporting a stale flag after a config edit.

`tests/endpoints/feeds.py` is renamed to `test_feeds.py`. It never matched
pytest's `test_*.py`, so all 15 feed tests, `test_tinfoil_feed` among them,
have been dormant since they were written.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 11:38:57 -04:00
Sam Dornan
ca4e6d28b4 fix(config): keep scraper media folders out of platform exclusion
DEFAULT_EXCLUDED_DIRS feeds both EXCLUDED_PLATFORMS and
EXCLUDED_MULTI_FILES, so listing the gamelist media folders there also
hid any platform directory that happened to share a name. The media
folders now live in DEFAULT_EXCLUDED_MEDIA_DIRS and only join the
multi-file exclusions.

The config response exposes the new list so the settings UI keeps
treating those entries as read-only defaults instead of offering a
remove action that the next config load would undo.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 10:24:15 -05:00
Sam Dornan
5bce157765 refactor(export): trim the gamelist media comments to the non-obvious why
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 10:19:17 -05:00
Sam Dornan
475abfbcc2 fix(export): write gamelist media where ES-DE and Batocera frontends find it
ES-DE ignores media paths inside gamelist.xml and only looks in
<MediaDirectory>/<system>/<mediatype>/<rom>.<ext>. The exporter wrote to
<platform>/assets/<mediatype>/, which that scheme cannot reach, and used
"boxes" and "physical" where ES-DE expects "3dboxes" and "physicalmedia".
Media now lands directly in the platform directory under ES-DE's folder
names, matching what the gamelist importer already reads, so media scraped
by ES-DE is reused instead of duplicated.

The folder map moves to config_manager so the default scan exclusions are
derived from it and the exported folders are never picked up as multi-file
ROMs. RetroBat's "images" folder is excluded for the same reason.

RetroBat and Batocera read paths from gamelist.xml but under their own tag
names, so <cartridge>, <titleshot> and <mix> are written alongside the
ES-DE tags.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 10:15:58 -05:00
Georges-Antoine Assi
fbbadb7c86 refactor(scan): give the title id one resolver and one identity shape
The Tinfoil feed was left behind when `_switch_productid_format` changed
from taking a `re.Match` to taking a `str`, so `/feeds/tinfoil` raised a
TypeError for any Switch rom carrying a product id in its filename but no
titledb id. It went unnoticed because `feeds.py` sits outside the changed
files mypy sees.

That call site was reachable only because "prefer the id the scan read over
the one scraped from the filename" lived in a second helper above the lookup,
leaving each caller to remember it. The resolution now happens inside
`_switch_productid_format`, so the three providers and the feed all get it
without repeating a preamble.

Also:

- Move `SWITCH_PLATFORM_SLUGS` to the sigil adapter so `utils/switch.py`
  stops importing the metadata base handler. The cycle that import created
  was papered over with a function-local import, and `normalize_identity`
  now takes the fact it needs rather than the whole slug set.
- Merge a partial identity update onto the stored identity before
  normalizing it. Normalizing rewrites the whole triple, so a client sending
  only a title id was getting the derived base id next to its old save
  target.
- Add `RomIdentity.from_rom` so the triple has one home on the read side
  too, and drop `asdict` from `as_rom_attrs`.
- Hold the `SigilExtractionResult` on `TitleIdEmbedCandidate` instead of
  copying two of its fields.
- Drop a guard in `_rom_level_identity` that could not fire, derive once in
  `normalize_identity`, and return only the parse from `_rebuild_rom_files`,
  which already owns `fs_rom["fs_name"]`.
- Read the parsed config in the heartbeat rather than forcing a YAML
  re-parse per request, and make `SigilService.is_enabled` a classmethod
  like every other one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 10:57:36 -04:00
Georges-Antoine Assi
8db38f3322 Merge remote-tracking branch 'origin/master' into feature/sigil-title-ids-followups
# Conflicts:
#	backend/handler/filesystem/roms_handler.py
#	backend/tests/endpoints/sockets/test_scan.py
2026-09-04 10:33:45 -04:00
Georges-Antoine Assi
2c0fb08795 Merge pull request #4329 from tmgast/fix/zip-cache-readable-and-locked
fix(download): make cached zips readable by nginx and serialize their builds
2026-09-04 10:25:44 -04:00
Georges-Antoine Assi
2d89f12b1f refactor(download): tighten the zip cache comments and test typing
Cut the docstring paragraphs down to the one fact each reader cannot get
from the code, name the readability test after the helper it exercises, and
give the flock stand-in and the zip factory real signatures.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:58:30 -04:00
Georges-Antoine Assi
9946256301 Merge branch 'master' into fix/zip-cache-readable-and-locked 2026-09-04 09:56:59 -04:00
Georges-Antoine Assi
0a0ed62a4c refactor(download): return the stat alongside the cached ZIP path
get_cached_zip already stats the archive to decide whether it exists, so
hand that stat back instead of making head_rom_content take another one for
Content-Length. A HEAD on a cached multi-file ROM now costs one stat.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:49:50 -04:00
Georges-Antoine Assi
352473d28c refactor(download): share the served-file mode and slim the zip cache
Give 0o644 a single home in utils/filesystem as SERVED_FILE_MODE, used by
both the ZIP cache and FSHandler._atomic_write. Collapse the mode repair to
one call site behind a single stat per cache hit, close the temp descriptor
unconditionally, and log the build where the namespace is already in scope.

Deduplicate the test fixtures and drive the concurrency test with a barrier
on flock instead of a sleep, so the race is guaranteed rather than timed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:48:03 -04:00
Georges-Antoine Assi
ffb076f22e Merge pull request #4327 from rommapp/claude/rate-limit-metadata-heartbeat
Rate limit the unauthenticated metadata heartbeat endpoint
2026-09-04 09:18:14 -04:00
Georges-Antoine Assi
dcd1589a8a Collapse concurrent metadata heartbeat misses into one probe
Callers that arrived while a probe was still running all read an empty cache
and started a probe of their own, so the cache only bounded outbound traffic
once a result had landed. Serialise the miss path on a per-source lock.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:11:50 -04:00
Georges-Antoine Assi
62ab9eb772 Tighten heartbeat rate limit comments and test assertions
Trim the constant comments down to the non-obvious facts, and relax the two
exact-TTL assertions that would flake if a second elapsed mid-test.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 08:49:26 -04:00
Georges-Antoine Assi
7ffbc258cc Cache metadata heartbeats and make the rate limit window atomic
Two review findings on the heartbeat rate limit.

The client IP comes from a forwarded header the caller controls, since the
container runs uvicorn with --forwarded-allow-ips="*", so rotating that header
defeated the per-IP cap outright; a distributed flood has no single IP to key
on either. Caching each source's result for the length of the window bounds
outbound provider probes at one per source, whatever the inbound rate. The
per-IP cap stays as the cheap first gate.

The window's INCR and EXPIRE were separate round trips, so a call interrupted
between them left a counter with no TTL that later calls never repaired,
locking that key out for good. Both now run in one transaction, with EXPIRE NX
so a live window is never extended and a counter can never lack a TTL.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 07:59:20 -04:00