2003 Commits

Author SHA1 Message Date
Terri
e964bbec88 feat(saves): sync saves for physical games by rom_id (#5862)
**Description**

Physical games (`is_physical` ROMs, such as Steam games added by hand)
have no files. Every snapshot channel keys to a ROM file, so sync
refused saves for these games.

A channel on a physical game now keys to the game's `fs_name` at size
-1, which no file has, so it never matches a real file's key. `fs_name`
is unique per platform for physical games, so the existing key columns
hold it and no migration is needed. A push also has to match the
channel's platform, since games on other platforms can share a name.

The push, channel create, attach and channel feed routes accept `rom_id`
in place of `rom_file_id`, for physical games only. Any other game
returns 422, and a game the caller can't see returns 404. A legacy `POST
/api/saves` upload for a physical game lands in that game's channel.

Channels follow the game:

- Deleting a physical game detaches its channels, as with any ROM.
- Adding it again with the same name, or renaming another physical game
to that name, reattaches them.
- Changing its `fs_name` moves its channels to the new key.

Title extraction and sigil work don't run for physical games. A save's
identity hash is its full content hash, since the emulator rule that
leaves out `.rtc` clock members doesn't apply to files a PC game writes.

Snapshot backups left by a deleted channel only come back when a scan
finds a file with their SHA-1, so a physical game's backups don't return
when it is added again.

```mermaid
flowchart LR
    P[request] --> F{rom_file_id or rom_id}
    F -->|rom_file_id| RF[visible ROM file] --> K1["FileKey.of_file (sha1, name, size)"]
    F -->|rom_id| R[visible ROM]
    R -->|is_physical| K2["FileKey.of_physical (fs_name, size -1)"]
    R -->|not physical| E[422]
    K1 --> C[channel on the same platform]
    K2 --> C
```

> AI Disclosure
>
> Planning and implementation supported by Claude Code.

**Checklist**

- [x] I've tested the changes locally
- [x] I've updated relevant comments
- [ ] I've assigned reviewers for this PR
- [x] I've added unit tests that cover the changes

#### Screenshots (if applicable)

No UI change.
2026-12-04 08:14:35 -05:00
Georges-Antoine Assi
9ecf0656a9 refactor(scan): move missing-ROM matching out of the scan socket (#5861)
* refactor(scan): move missing-ROM matching out of the scan socket

Follow-up to #5795, addressing the review findings left open there.

The scan socket decided which filenames may identify a moved ROM and
named the identity that matched, which is scan logic living in an
endpoint. That logic now sits in handler/scan/reassociation.py:

- find_shared_fs_names lists the filenames several discovered files use.
- find_missing_rom calls get_matching_missing_rom with the parsed
  hashes and title id, and withholds a shared filename.
- matched_identity (was _reassociation_match) names the matched tier.

The socket only calls them. Behavior is unchanged.

The get_matching_missing_rom docstring drops its rationale to one
sentence plus Returns, keeping the title id reason as a short comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLHbtEToaZiMegnE1D2

* chore(pegasus): describe the owned-keys rule without naming the product

Addresses the review finding left open on #5825: the comment on
ROMM_OWNED_GAME_KEYS made the product the actor. It now states what the
merge does with these keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLHbtEToaZiMegnE1D2

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-04 06:38:17 -05:00
Georges-Antoine Assi
c75437cc01 refactor(adapters): send provider requests through httpx2 (#5851)
* refactor(adapters): send provider requests through httpx2

The metadata provider adapters (IGDB, ScreenScraper, MobyGames,
RetroAchievements, Steam, SteamGridDB, libretro thumbnails) used aiohttp
while the rest of the backend used httpx2. They now share the request's
httpx2 client through `send_request` in provider_http.py, which bounds
the whole exchange with one timeout and follows redirects, as aiohttp
did. Each provider's auth middleware becomes an httpx2.Auth flow.

aiohttp was adopted because httpx logged request URLs carrying API
keys at INFO. The log formatter now masks every credential parameter
those URLs carry, so that reason no longer holds.

Behavior changes:
- Provider requests go through the SSRF-guarded client. Only tests
  ever pointed a provider at a custom base URL.
- A dropped connection is no longer resent once by the client; it
  surfaces as the existing 503.
- SteamGridDB's default base URL is www.steamgriddb.com. The bare
  domain answers with a cross-host 301, and httpx2 drops the
  Authorization header on that hop.

aiohttp, its OpenTelemetry instrumentation, and the packages only
aiohttp needed (aiohappyeyeballs, aiosignal, attrs, frozenlist) leave
the lockfile. The scripted test server becomes an httpx2.MockTransport,
and the aiohttp-recorded cassettes are adapted to what httpx2 sends:
masked credentials in the query, empty bodies as "", and no stale gzip
Content-Encoding headers on already-decompressed bodies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(logging): keep provider API keys out of Sentry

The log formatter masks credential query parameters on stdout, but
Sentry's logging integration reads the raw record before any handler
formats it. Two paths sent provider keys to Sentry when SENTRY_DSN is
set:

- httpx2's INFO request line, which carries the authenticated URL, as a
  breadcrumb in the web process.
- An adapter's `log.error(exc)` on an error status, since an
  HTTPStatusError's message carries the same URL, as an event in the
  web and worker processes.

The `romm` logger now masks the record itself in a filter, which runs
before handlers and Sentry's hook. httpx2's request lines are no longer
emitted. Sentry's before_send and before_breadcrumb mask every string in
a payload, which covers exceptions captured directly, including their
messages and stack locals. The masking regex also stops at a single
quote, so httpx2's quoted URLs keep their closing quote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Set the RomM user agent and convert httpx2 timeouts to TimeoutError in send_request, so adapters drop their copies and send_with_retries catches a single timeout type. Read the ScreenScraper status code once in _handle_client_error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review follow-up)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(logging): keep the log template when redacting a record

RedactFilter replaced msg with the formatted text and dropped args, so
Sentry grouped each redacted URL or game id as its own issue. It now
redacts the template and each argument in place, and falls back to the
flat text only when a secret spans the template and an argument.
pprint records keep their structured msg.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(screenscraper): pin dev credentials for the cassette tests

The cassettes now record devid and devpassword, since httpx2's auth flow
runs before VCR sees the request. CI has no developer credentials, so the
requests carried a blank devid= that VCR drops when matching, and all
seven integration tests failed to find their recording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 20:43:32 -05:00
Georges-Antoine Assi
2778be8316 perf(gallery): rank only grouped ROMs in the sibling window (#5845)
* perf(gallery): rank only grouped ROMs in the sibling window

The grouped gallery numbered every ROM with row_number() to pick one
tile per sibling group, though only ROMs with a rom_sibling_groups row
can have siblings. The window now joins rom_sibling_groups as an inner
join, and each ungrouped ROM stands as its own representative:

- Representative-key sorts drop ids NOT IN (window WHERE row_num > 1).
- Aggregated rom_user sorts outer-join the window once, keep rows with
  no window row or row_num = 1, and fall back to the ROM's own
  zero-folded key when it has no group.

On a 100k-ROM MariaDB library with 16% of ROMs grouped, the uncached
grouped index went from about 1.06 s to 0.47 s (name) and 1.2 s to
0.5 s (last played), with identical ids, order and letter index. At
70% grouped it is still faster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(gallery): read the grouped window off the covering index on MariaDB

Driving the grouped-only window from rom_sibling_groups made MariaDB
fetch each grouped ROM's wide roms row by primary key. On a library
whose roms table is about 1.1 GB, that working set (~330 MB) doesn't fit
a default 128 MB buffer pool, so every request went back to disk and the
gallery ran about 3x slower than before.

On MySQL and MariaDB the window now reads roms through
idx_roms_sibling_cover with FORCE INDEX, and STRAIGHT_JOIN on the window
select keeps roms ahead of rom_sibling_groups once the base subquery
merges into it. The hint also lists the FULLTEXT index, which a search's
MATCH needs. PostgreSQL keeps its plan: TOAST keeps its rows narrow.

force_index_on_mysql takes several index names, and
straight_join_on_mysql joins the dialect helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(gallery): exclude outranked siblings with an anti-join

When FULLTEXT drives a grouped search, MariaDB ran the NOT IN over the
sibling window as a correlated subquery, rescanning the materialized
window for every outer row. A search matching 42k of 100k ROMs took
about 10 s against 1.2 s on master. An outer join on the window's id and
row_num > 1, keeping rows with no match, gets a keyed lookup instead:
about 1 s for that search, with the no-search gains kept and the same
cold-pool page reads.

The equivalence matrix gains a FULLTEXT search case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 12:05:30 -05:00
Georges-Antoine Assi
88d71bbe36 perf(gunicorn): preload the app so web workers share its memory (#5846)
* perf(gunicorn): preload the app so web workers share its memory

Each gunicorn worker imported the whole app on its own, ~160 MB private
per worker. Preloading imports it once in the master; gc.freeze keeps the
shared pages from being copied when workers collect garbage.

- gunicorn.conf.py: GC off during import, OpenAPI schema built and all
  objects frozen before fork, inherited SQL pool dropped in each worker
- Socket.IO managers renew their pub/sub host ID after fork, otherwise
  preloaded workers drop each other's emits as their own
- WEB_SERVER_CONCURRENCY defaults to 2
- Page limit capped at 1,000 (was 10,000): a worker keeps the memory of
  its largest response until recycled; select-all pages by 1,000

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(gunicorn): address Greptile review on the preload change

- Shorten the renew_host_id docstring and the gunicorn.conf.py comment
- Close the fork test's pipe in a finally block
- Test that when_ready builds the schema before freezing and re-enabling
  the GC, and that post_fork disposes the pool with close=False

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(gunicorn): WEB_SERVER_PRELOAD switch and an import fork-safety test

- WEB_SERVER_PRELOAD (default true) sets preload_app from the gunicorn
  config; false restores per-worker imports and skips every hook
- tests/test_api_import_is_fork_safe.py imports main in a fresh
  interpreter with the database on a closed port and fails if the import
  opens a connection or starts a thread (adapted from #5735)
- BACKEND_ARCHITECTURE notes the preload and what it requires of imports

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(coherence): record the invariant run for the preload change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: drop trunk-ignore comments bandit never needed in tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 09:15:50 -05:00
Georges-Antoine Assi
ec1684d2af perf(metadata): serve the metadata dumps and fixtures from SQLite files (#5844)
* perf(metadata): serve the metadata dumps and fixtures from SQLite files

The LaunchBox and Switch TitleDB stores sat in valkey, which keeps every
byte resident: about 300MB on an instance with both imported, against
roughly 1MB for an empty server. Every read is an exact-key lookup and
nothing writes between imports, so they now live in read-only SQLite
files under RESOURCES_BASE_PATH/metadata, where the OS page cache holds
only the pages lookups touch.

A build writes a temporary file and renames it over the previous one,
so readers see the old store or the new one and never a partial import.
That replaces the initial-import flag and the schema stamp: the store
revision is part of the file name. A failed import keeps serving the
previous file.

The startup fixture indexes (MAME, ScummVM, Sony serials, known BIOS)
no longer get copied into valkey on every boot. They build on first use
into a file under the cache path, named after a hash of the JSON.

Startup deletes the old valkey keys and any file of an older revision,
and queues a rebuild when a store had data, so an upgrade refills
LaunchBox and TitleDB on its own. nginx returns 404 for the metadata
folder, since /assets/romm/resources is otherwise served without auth.

Measured against the real dumps: LaunchBox builds in 22s into 263MB on
disk, TitleDB in 1.2s into 54MB, the fixtures in 0.2s into 8MB. A hit
costs 10-23us including decompression, a miss about 7us.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review fixes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the previous metadata store when a dump comes out empty

A LaunchBox or TitleDB build that writes no rows to its main table now
fails with EmptyDumpError instead of swapping an empty store over a
populated one.

Each store keeps one connection per process behind a lock instead of one
per thread. A build closes it once it swaps the file in, and any other
process closes its own on its next lookup, so a replaced file's disk
space is released instead of held by idle threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile review: trim DumpStore comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Restore valkey's own snapshot policy by default

The hourly default (48259b3a9, #3980) kept valkey from rewriting the
hundreds of MB of LaunchBox and TitleDB data it held. With those moved to
SQLite files, a snapshot holds only sessions, queues and query caches, so
an unset REDIS_SAVE_POLICY now leaves valkey's stock policy in place and
loses less on a crash. An empty value still disables snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 08:49:15 -05:00
Stu Anderson
6fc323e24b chore(api): widen indexes for filtered search, MariaDB Fix (#5824)
* chore(api): add indexes to roms

* chore(api): add additional indexes

* chore(api): widen indexes on rom table

* perf(api): fast filtered and short searches on MariaDB, plus year, rating and game mode filter

* chore(api): add ANALYZE TABLE at end of migration

* pr-ready: drop the roms_search table

* pr-ready: code-review

* pr-ready: review-polish

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

* pr-ready: prose

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

* chore(api): use hand-coded list of columns

* pr-ready: code-review

Restore the schema before asserting in the 0163 schema tests, send
platform_ids in the endpoint test, and fix two stale comments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Reword the comments code-review added to the 0163 schema tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(database): cover year_range_ms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(database): raise the sort limit on MariaDB through the mysql driver

The listener keyed on the dialect name, which is mysql when
ROMM_DB_DRIVER=mysql reaches a MariaDB server. Check the dialect's
is_mariadb instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: fix the sort limit tests on PostgreSQL and the _ms types

The sort limit tests read is_mariadb from the test engine, which
PostgreSQL's dialect lacks, so they now set it. _ms takes named date
parts again, since mypy rejects a star tuple before tzinfo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-12-02 18:58:05 -05:00
Alex Castillo González
67a233d65d fix(roms): drop a provider's old metadata when a manual rematch misses (#5841)
* fix(roms): drop a provider's old metadata when a manual rematch misses

Changing a provider id to one the provider cannot resolve kept the typed id
but left the previous game's metadata blob in place for every provider except
RetroAchievements. Apply the RetroAchievements rule to every provider: on a
miss the blob is cleared, unless raw metadata for it came with the same edit.

Fixes #5836

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

* pr-ready: code-review

Strip string match ids so a padded Flashpoint id is not read as a rematch
that misses and wipes the stored metadata, and describe the miss case in
the _refetch_changed_matches docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-12-02 18:01:34 -05:00
Georges-Antoine Assi
a3f45158e1 fix(scan): skip extracted Switch files when reading title ids (#5839)
* fix(scan): skip extracted Switch files when reading title ids

Sigil reads a Switch title id only from an NSP or XCI container, so no
file under an extracted title's exefs or romfs folder can yield one. A
scan still handed every such file to sigil, and the Switch family never
reuses stored ids while a file lacks one, so every quick scan re-read an
extracted game's whole tree (one Switch 2 game in the report holds ~160k
files) and kept each path in the scan's needs-key set for the summary.

Files inside an exefs or romfs folder of a Switch ROM are no longer
title id sources. On a 50k-file extracted game, a quick rescan goes from
50,002 sigil reads and 50,002 retained needs-key paths to none, and its
peak allocation drops from 193 MB to 110 MB.

Refs #5706

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(scan): check row reuse by identity in the extracted Switch rescan test

Unsaved rows all have a None id, so comparing ids could not tell reused
rows from rebuilt ones. Addresses Greptile's review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 08:23:01 -05:00
Georges-Antoine Assi
3b14dddd88 chore(prose): fix the prose-check findings on master (#5826)
The scheduled Trunk Check (all files) run fails on 79 prose-check issues
that predate the linter: clipped 'X, else Y' chains, 'internal id' in
API descriptions, and clipped 'Left out, ...' conditionals.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 08:17:01 -05:00
Ryan Wendell
45c934bd45 fix: Export HLTB and RetroAchievements extras in Pegasus metadata (#5825)
* Export HLTB and RetroAchievements extras in Pegasus metadata

* fix(pegasus): address Greptile review on HLTB/RA export

Skip malformed hltb_metadata and achievement values instead of failing
the export, emit x-ra-id whenever the ROM has one, shorten the comment,
and rename the loop variable that shadowed dataclasses.field (ruff F402).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Drop stale x-hltb-*/x-ra-* keys when merging into an existing metadata
file, count only well-formed achievements, and skip boolean HLTB values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review additions)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(roms): drop the old RA metadata when a manual rematch misses

Changing ra_id to a game RetroAchievements cannot resolve kept the new id
but the previous game's achievements, genres and companies, so exports
paired the new id with the old totals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: rwendell <rwendell@users.noreply.github.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 08:11:30 -05:00
Stu Anderson
6b6bd866eb fix(api): missing status comparison counts as no match (#5821)
* bugfix(api): missing status comparison counts as no match

* pr-ready: code-review

Match unknown status values as false so PostgreSQL's enum never sees them,
and cover unknown values, name case and grouped versions in the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: plain-prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(api): reject unknown statuses_logic values

Any value other than exactly 'all' or 'none' acted as 'any', so 'NONE'
returned the opposite of what was asked. The field is now limited to
'any', 'all' and 'none', and anything else gets a 422.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(api): limit every *_logic filter field to any, all or none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 21:35:55 -05:00
Georges-Antoine Assi
68709e79a7 fix(siblings): group versions by connected component everywhere (#5430)
* fix(siblings): group versions by connected component everywhere

The game page's siblings matched on any shared provider id, while the
gallery's group_by_meta_id window partitioned on the first non-null id in
a fixed provider order. A version matched by IGDB and ScreenScraper and
one matched by ScreenScraper alone were siblings on the game page but two
gallery cards. The recommendation surfaces didn't group at all: the
cold-start row ranks by rating, which every version shares, so one game
filled it.

rom_sibling_groups now stores each ROM's connected component over
rom_identity_keys, kept in step by add_rom/update_rom/delete_rom and
rebuilt after a scan. The sibling_roms view, the gallery window and the
recommendations all read it: the feed and similar games collapse each
game to one entry, exclude the other versions of a played game, and
show the version the grouped gallery shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(siblings): answer the Versions filter from rom_sibling_groups

Only a ROM with another version has a group row, so "has versions" is a
primary-key probe rather than an EXISTS over the sibling_roms self-join.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(siblings): break representative ties by id; restore Versions filter

Versions often share a filename stem and region, and without a final key
the version that represents a group could change between queries.

The "Versions" filter goes back to EXISTS over sibling_roms: measured on
a 100k-ROM library it takes the same time as the direct group-row probe
(107 ms each), since the view merges into the query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(migrations): renumber rom_sibling_groups to 0158 after master's 0157

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(recommendations): address Greptile review on sibling grouping

- Swap each recommendation to its visible representative before the
  visibility cut, so a game whose top-ranked version is hidden shows
  through a visible one instead of disappearing.
- Read candidates in batches until enough distinct games remain, so a
  game with more versions than one overfetch batch no longer crowds out
  the rest of the feed; the cold-start query pages with an id tiebreak.
- Shorten the 0158 migration and RomSiblingGroup docstrings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(recommendations): use the shared auth helpers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review fixes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(recommendations): hide only the hidden version, as the gallery does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(siblings): regroup only on identity changes and scope the post-scan repair

add_rom skips the regroup when the merge changed no identity column. The
post-scan repair regroups the scanned ROMs for a ROM-scoped scan and
rebuilds only the scanned platforms otherwise, since no group spans two
platforms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 12:07:57 -05:00
Georges-Antoine Assi
18995eaa61 Ship a single web manifest with maskable Android icons (#5820)
index.html linked a hand-written site.webmanifest ahead of the one
vite-plugin-pwa generates. Its icons had no maskable purpose and a white
background, so Android launchers (Chrome, Brave) shrank the square logo
into a white circle. Its name was also empty.

Drop site.webmanifest and its link, and configure the plugin manifest
with the RomM name, brand theme and background colours, and the
full-bleed android-chrome PNGs listed as both any and maskable.


Claude-Session: https://claude.ai/code/session_011waFLFwVe4sdqdXdJcZ37i

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-01 10:06:43 -05:00
Matt Kaatman
414fe15d5b fix(feeds): send real content IDs and RAP keys in PKGi and PKGj feeds (#5818)
* fix(feeds): send real content IDs and RAP keys in PKGi and PKGj feeds

The rap column carried the SHA-1 of the .rap file. PKGi decodes it as the
16-byte license key, so it saved a wrong license. The content ID was always
generated (UP9644-...), so even a correct license was saved under a name the
game never looks for.

Read the content ID from the package header, and the key from the rom's .rap
file named after that content ID (or its only .rap file).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(feeds): read PSN licenses through the roms filesystem handler

Move the package content ID and .rap license lookup from the feeds
endpoint into FSRomsHandler, read at most 17 bytes of a .rap file, and
trim the get_rap_data docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-12-01 10:06:17 -05:00
Georges-Antoine Assi
d1cd58e6b9 fix: bound PSP container decoding, atomic reset tokens, cap sync play sessions, redact log tokens (#5809)
* fix(psp): bound what a compressed PSP container header can make us decode

The CISO/ZISO block size, the index length and ISO9660 directory sizes
all come from the uploaded file. Cap the block size at 1 MiB, require the
index table to fit in the file, refuse out-of-order index entries, cap
deflate output at the block size, and cap directory reads at 1 MiB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: cap sync play sessions in the schema and redact token values in logs

The sync completion payload now declares max_length on play_sessions,
so an oversized list is refused while it is validated instead of after
every entry is parsed. It answers 422 like any other invalid payload.

token is added to the redacted log keys, so a reset link or any other
token=... query value is masked in the log viewer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(auth): redeem a password reset token with one atomic GETDEL

The reset JTI was checked with EXISTS and then removed with DELETE, so
two requests on different workers could both pass the check. Use GETDEL,
as invite and refresh tokens already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(psp): reject a deflate block that ends before its output cap

Addresses Greptile review on #5809: a truncated CISO/DAX block now raises
zlib.error again instead of hashing a partial EBOOT.BIN, so the scan falls
back to RAHasher. Adds tests for truncated streams and out-of-order index
entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:56:06 -05:00
Georges-Antoine Assi
c2367176c5 fix(auth): link an OIDC sign-in by email only to a password-less account (#5815)
A user with a password can set their own email to the address of someone
at the provider who hasn't signed in to RomM yet. That person's first OIDC
sign-in then linked their identity and role to the attacker's account.
Password-less accounts can't change their own email, so their email still
identifies the owner.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:23:13 -05:00
Georges-Antoine Assi
da841d20d4 fix(sockets): send scan events to signed-in sockets only (#5808)
* fix(sockets): send scan events to signed-in sockets only

The socket server accepts anonymous connections, and scan progress
events went to every socket, so a client that connected without a
session during a scan received ROM names and paths. Signed-in sockets
now join an authenticated room on connect, and scan broadcasts target it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(sockets): narrow emit await_args before reading it

Addresses Greptile review on #5808.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:22:47 -05:00
Zurdi
27780d8439 fix(management): preserve ROM metadata when files move (#5795)
* Preserve ROM metadata when files move

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(scan): keep the filename fallback from overriding stronger matches

Address Greptile and Copilot review on #5795:
- Fold the filename into get_matching_missing_rom as its weakest tier, so an
  ambiguous hash or title id match stops the search instead of falling
  through to a filename.
- Compare filenames with exact_collation, so MariaDB's case-insensitive
  collation can't match game.zip to Game.zip.
- Skip the filename tier for names several discovered files share, so one
  copy can't take an entry that another copy's hashes would have claimed.
- Fix the present-ROM test, which stored Present.zip.zip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

- Skip filename matches on entries whose stored hashes or title id show
  another file.
- Exclude physical games from reassociation.
- Keep a plain fs_name comparison so the platform/fs_name index applies.
- Match on the discovered name, before title id embedding renames it.
- Make the shared-name scan test able to fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review additions)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(scan): claim a missing entry atomically before reassociating it

Files are identified concurrently, so two files could match the same
missing entry and both move it. claim_missing_rom clears the missing
flag with a conditional UPDATE, and only the file whose claim wins moves
the entry; the other gets a new one.

The reassociation log line now names the identity that matched (file
hash, title id or filename), so a wrong filename match can be traced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(db): pass hashes explicitly so mypy accepts the call

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(streaming): run the app lifespan in the ASGITransport claim tests

The two async claim tests read app.state.aiohttp_session through the
context middleware, which only the lifespan sets. They passed only when
an earlier test on the same worker had opened a TestClient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 08:40:59 -05:00
Stu Anderson
b1e461c843 perf(api): api roms does single pass query (#5804)
* perf(roms): get roms in single pass

* perf(api): cache fixes-separate cache key

* pr-ready: code-review

Fix the PostgreSQL letter test and a strict mypy comparison in the
gallery index tests, place letters along the served id list on a
partial cache hit, reuse _gallery_order_clauses for the ranked index,
require sort_key and visibility on gallery_index_rows, and add tests
for the unscoped cache, other sorts and identical copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Share the filter arguments between filter_roms and gallery_index_rows,
branch once on the one-pass index, and settle cached-or-fresh lists in
place in get_gallery_index without materialising the result rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review follow-up)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(roms): read the gallery index through one handler entry point

get_gallery_index now takes the filtered and unfiltered queries and
returns both sidecars, replacing gallery_index_rows, the rows-based
get_gallery_index and with_char_index.

- It reads the cache before building any statement, and reuses the
  endpoint's filtered query, so filter_roms only runs again for the
  ranked PostgreSQL read on a cache miss.
- Every letter index comes from the ordered id and letter rows, so a
  letter's position is its first tile on every path, including
  ungrouped MariaDB galleries and requests without the id list. The
  separate first-tile cache key goes away.
- Only a request for the id list stores it, so pages still read the
  list an index request built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(roms): group MariaDB letters by collation weight

DENSE_RANK forced a temporary table and an extra sort, which made the
whole ungrouped library about 2.3x slower than the previous two
queries. WEIGHT_STRING gives each letter its collation key per row, so
accented letters still share a group without the window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(roms): build the ranked index from a shared sibling window

The dedup window moves out of filter_roms into _sibling_window, so the
ranked PostgreSQL read builds its own (id, letter) select instead of
filter_roms switching its return shape behind a flag and a cast. The
read filters hidden rows before the window, which keeps the same
primaries because the window ranks visible versions first.

get_gallery_index reads the cached letters and id list in one Redis
round trip and only builds an id lookup when letters follow a cached
list. search_relevance_leads becomes private, and the gallery index
tests share one query builder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 19:17:01 -05:00
Stu Anderson
5f3b983b7f perf(roms): serve the filter dropdown values from their own endpoint (#5786)
* perf(roms)!: serve the filter dropdown values from their own endpoint

GET /api/roms computed the filter dropdown lists (genres, franchises,
companies, platforms and the rest) on every gallery open and every filter
change. For a search they were 0.58 s of the 0.72 s of database time, almost
all of it reading roms_facets, and a gallery needs none of them to show its
cards.

The lists now have their own request, GET /api/roms/filter-values, which the
filter drawer makes when it opens. It takes the same scope parameters as the
gallery (search_term, platform_ids, platforms_logic, collection_id,
virtual_collection_id, smart_collection_id) and returns the same
RomFiltersDict, limited to the roms the caller can see.

On a 100,000 ROM MariaDB library with one API worker, a searched open falls
from 0.85 s to 0.10 s. Opening the drawer pays the cost instead: 0.3 s for a
search, 0.8 s for the whole library, which is no longer cached.

BREAKING CHANGE: GET /api/roms no longer accepts with_filter_values and no
longer returns filter_values. Use GET /api/roms/filter-values. The web client
is updated in this commit.

Backend:
- add GET /api/roms/filter-values
- remove with_filter_values, filter_values and the unscoped filter-values
  cache key from GET /api/roms
- with_filter_values() in the handler no longer caches; the shared cache
  version counter stays because the id list and letter caches use it

Frontend:
- the gallery store no longer asks for the lists on open, refresh or scroll
- fetchFilterValues() asks once per displayed result, and GalleryShell calls
  it when the drawer opens
- the generated response type loses filter_values

Tests:
- remove the filter-values cache tests
- read the lists from the new endpoint in the endpoint tests
- check /api/roms no longer returns them, that the lists are never null, and
  that values of a hidden rom are left out
- cover the on-demand fetch in the store tests

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

* perf(roms) docstring updates

* pr-ready: code-review

- key the filter-values dedupe by scope, not result epoch, so filter,
  sort and group changes stop refetching the lists
- empty another scope's lists while the new ones load, and refetch after
  a library change or context switch
- abort an in-flight filter-values request for a superseded scope
- send platform_ids in the filter-values endpoint tests and cover scope
  narrowing and ignored row filters
- update comments that still called the filter values cached
- test the drawer-open fetch in GalleryShell

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review follow-up)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify (code-review follow-up)

Rename the filterValuesScope state field to filterValuesScopeKey so it no
longer shares a name with the filterValuesScope() helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(roms): cache the whole-library filter values on the new endpoint

GET /api/roms/filter-values computed the unscoped lists on every drawer
open, a 0.8 s scan on a 100k-rom library. Serve them from the per-user
versioned cache GET /api/roms used, under the same key, so only a scope
(platform, collection or search) computes live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review follow-up)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(gallery): show a loading state while the filter values load

The drawer's attribute dropdowns now show a spinner, and an open dropdown
says Loading, while GET /api/roms/filter-values is in flight. The metadata
provider and status lists are fixed and never show it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(roms): cover filter-values cache invalidation and private collections

Hiding a rom after the whole-library lists are cached drops its values on
the next request, and another user's private collection or smart
collection yields no values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-28 21:10:02 -05:00
Stu Anderson
39ed3a05b6 perf(rq): Save 67MB RAM; keep the database and API out of streaming worker's parent (#5755)
* perf(streaming) lazy loading in streaming worker

* perf(rq): push _resolved to test container

* pr-ready: code-review

Move the reaper import guard into test_task_func_paths.py, reusing
BACKEND_ROOT and JOB_ONLY_MODULES, watch socket_handler and lifecycle too,
check the deferred imports still load, and surface stderr on failure.
Explain the lazy socket_handler import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Defer the lifecycle import inside _reap instead of wrapping its teardown,
share one subprocess helper between the import guards, and check every
streaming-queue task the PreloadingWorker parent would load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Keep the import-guard helper's docstring to one sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Write the lazy-import and guard comments as full sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(streaming): move session notices out of session_store

record_termination and push_to_user deliver over the socket and as
notifications, so they now live in handler/streaming/notices.py with
top-level imports. session_store keeps only the Redis tombstone write
(save_termination) and loads neither the database nor socketio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 20:30:04 -05:00
Stu Anderson
355ce188a4 perf(rq): Save 70MB+ RAM; keep SQLAlchemy out of RQ workers, cron processes (#5736)
* perf(rq): keep SQLAlchemy out of the RQ worker and cron processes

The RQ worker parents and rq cron imported SQLAlchemy and the ORM models at
start-up, through config/__init__.py (safe_* helpers in utils.database) and
config_manager (sqlalchemy.URL and the rom-converto adapter). None of them
query the database themselves; each job's work horse loads what it needs.

- Move safe_int, safe_str_to_bool and get_nested from utils.database to utils.
- Import sqlalchemy.URL inside get_db_engine.
- Import the rom-converto normalizer only when converto.platform_formats is set.
- Add a test that tasks.cron_config and handler.rq_worker start without
  loading SQLAlchemy.
- Run a killed work horse's failure callback and exception handlers in a
  short-lived child, so the job code they import never stays in the parent.

Measured on the production image: idle PSS of rq_worker, rq_scan_worker and
rq_cron fell by 98 MB in total.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(rq): move to constants file, tests prevent huge imports

* perf(rq) revert forked failure report.

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: plain-prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(db): build the database URL in utils.database

ConfigManager.get_db_engine becomes utils.database.get_db_url, so
config_manager no longer needs SQLAlchemy at all and the function-local
import goes away. Every caller already loads SQLAlchemy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(roms): clear a match id that is not a number instead of storing 0

safe_int_or_none fell back to safe_int's default of 0, so sgdb_id,
hasheous_id and tgdb_id (which have no refetch to reset them) were saved
as 0. Use utils.int_or_none instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(models): describe where each shared column limit is used

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-28 12:08:54 -05:00
MMagTech
0b1e449b0f feat(saves): convert DS, Sega cartridge and Game Boy Advance saves through sigil (#5643)
* feat(saves): convert Nintendo DS saves through sigil

Sigil now converts a DS save between melonDS's raw file and DeSmuME's
.dsv, so a download with core= gets the file that emulator reads instead
of the stored one as is. DS moves from the native list to the platforms
sigil restores; like Saturn and Sega CD it carries no title id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): accept a single-file neutral unit as sigil names it, for DS and Game Boy

Sigil names a cart's single-file unit after the content, `{stem}.srm`, and
sets the unit format; the neutral check only took `save.raw` for DS and
`save.sram` for Game Boy, so a client pushing sigil's own unit got a 422.
A SINGLE unit's one file may now carry sigil's name on those platforms;
multi-file units and every other platform keep their names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): name DS among the cartridges that take no companions

Sigil refuses companions on every cartridge platform, DS included now
that it converts DS saves, so the refusal says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(saves): convert Mega Drive, 32X, Master System and Game Gear saves through sigil

genesis_plus_gx and picodrive keep these carts' save RAM at the same
offsets but fill and size it differently. With sigil converting between
them, the four platforms move from NATIVE_SAVE_PLATFORM_SLUGS to
SIGIL_RESTORE_PLATFORM_SLUGS (sigil slugs genesis, 32x, sms, gamegear),
so a download with core= gets the file that core keeps. The companion
refusal message names the new cartridges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): accept the Sega cartridges' single-file neutral unit as sigil names it

Sigil names a Mega Drive, 32X, Master System or Game Gear unit after the
content, `{stem}.srm`. A SINGLE unit's one file may now carry that name,
as DS and Game Boy's may; RomM's `save.sram` still passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(saves): convert Game Boy Advance saves between emulators with sigil

GBA moves from the native-save platforms to the ones sigil reads at scan
time and restores for a core. The stored file doesn't load everywhere:
VBA Next keeps an EEPROM save at 128 KiB into a 136 KiB file, gpSP pads
every save to 128 KiB, and standalone mGBA appends the cart clock. The
scan stores the cart's save chip and clock in sigil_features, which sigil
uses to size a padded save. The tests that used GBA as their native
example now use SNES.

Needs a sigil pin with GBA collect and restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): accept a single-file GBA neutral unit as sigil names it

Sigil names a GBA cart's unit as it does a Game Boy's: the save alone as
`{stem}.srm`, or a clock cart's zip of `save.sram` and `clock.rtc`.
GBA now takes Game Boy's form, so the single file may carry sigil's name.
The clock-only form had no other platform left and goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): pin sigil at the DS merge, and take only a plain file name as its single unit

Both SIGIL_VERSION pins move to baa96b8 (rommapp/argosy-sigil#22), the
first sigil commit with DS. _SIGIL_SINGLE is [^/]+\.srm, so a single unit
named with a folder in it is refused; test_neutral.py checks it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at the GBA merge

rommapp/argosy-sigil#24 is merged as 4980f69. Both SIGIL_VERSION pins
(Dockerfile, docker/Dockerfile) move from baa96b8 to that commit on
sigil's main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at the Mega Drive merge

rommapp/argosy-sigil#23 is merged as be0809d. Both SIGIL_VERSION pins
(Dockerfile, docker/Dockerfile) move from baa96b8 to that commit on
sigil's main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at 650b265

Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from
be0809d to 650b265, sigil's main. It holds rommapp/argosy-sigil#23
(be0809d) and is the commit rommapp/romm#5758 pins, so the two
pull requests set the same value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at 650b265

Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from
baa96b8 to 650b265, sigil's main. It holds rommapp/argosy-sigil#22
(baa96b8) and is the commit rommapp/romm#5758 pins, so the two
pull requests set the same value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at 650b265

Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from
4980f69 to 650b265, sigil's main. It holds rommapp/argosy-sigil#24
(4980f69) and is the commit rommapp/romm#5758 pins, so the two
pull requests set the same value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): name no systems in the companion refusal

The message listed the cartridges that take no companions, so each
platform added to sigil's restores edited it, and the open save PRs
(#5643 to #5647) each edited it differently. It now says what holds for
every platform: companions go only on memory cards and volumes. All five
carry the same line, so they merge in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): name no systems in the companion refusal

The message listed the cartridges that take no companions, so each
platform added to sigil's restores edited it, and the open save PRs
(#5643 to #5647) each edited it differently. It now says what holds for
every platform: companions go only on memory cards and volumes. All five
carry the same line, so they merge in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): name no systems in the companion refusal

The message listed the cartridges that take no companions, so each
platform added to sigil's restores edited it, and the open save PRs
(#5643 to #5647) each edited it differently. It now says what holds for
every platform: companions go only on memory cards and volumes. All five
carry the same line, so they merge in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(saves): restore Sega cart saves through RomM's platform map and binding

From review: the Mega Drive, 32X, Master System and Game Gear tests mock
the binding, so a slug sigil doesn't take would still pass. A ROM on each
RomM platform now goes through stored_game and the real binding, and the
restored file is checked in the form sigil's genesis.md gives the core:
genesis_plus_gx without trailing 0xFF, picodrive's 32 KiB for Master
System and Game Gear. rom_game is the same helper in #5643 to #5647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(saves): restore a DS save through RomM's platform map and the binding

From review: the DS tests mock the binding, so a slug sigil doesn't take
for DS would still pass. A ROM on RomM's nds platform now goes through
stored_game and the real binding, and the restored file is checked in
the form sigil's nds.md gives each core: DeSmuME's .dsv ends in its
122-byte footer, melonDS's .sav is the save. rom_game is the same helper
in #5643 to #5647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(saves): restore a GBA save through RomM's platform map and the binding

From review: the GBA tests mock the binding, so a slug sigil doesn't take
for GBA would still pass. A ROM on RomM's gba platform now goes through
stored_game and the real binding, and the restored file is checked at the
size sigil's gba.md gives each core: gpSP 128 KiB padded with 0xFF, VBA
Next 136 KiB, mGBA the chip. rom_game is the same helper in #5643 to
#5647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at ef9b51e

Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main
since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758
pins now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at ef9b51e

Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main
since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758
pins now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin sigil at ef9b51e

Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main
since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758
pins now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: MMagTech <mmagtech@Mac.home>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-28 10:39:13 -05:00
Matt Kaatman
d8d9fa7884 fix(igdb): let region_mode decide the localized title (#5785)
* fix(igdb): let region_mode decide the localized title

get_igdb_preferred_locale ignored scan.priority.region_mode, so a rom
tagged (Japan) always got IGDB's ja-JP localized title, even with
prefer_config and us first in scan.priority.region. Under prefer_config
the configured regions now come first and the rom's own tags are the
fallback, matching the ScreenScraper handler since #4413. The default
prefer_rom_tags ordering is unchanged.

Fixes #5784

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(igdb): fold the region_mode note into one docstring sentence

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Log a missing IGDB locale at debug: under prefer_config every ROM asks
for the first config locale, so a missing one is routine, not a warning.
Pin SCAN_REGION_MODE in the multi-region locale test instead of relying
on MagicMock's auto attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Drop the IGDB-locale filter on the ROM's region codes; the final
lookup loop already skips codes IGDB has no locale for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Spell out the USA region in the prefer_config test docstring so it
does not read as the pronoun, untangle the fallback test docstring, and
finish the clipped Returns line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(metadata): share one region order across IGDB, ScreenScraper and LaunchBox

IGDB now tries every preferred locale in order, up to the first region
that uses the default title, instead of only the first. Under
prefer_config with [eu, jp], a (Japan) ROM whose game has no EU
localization gets the Japanese title again rather than the default.

preferred_region_codes in the filesystem base handler builds the region
order once. ScreenScraper, IGDB and LaunchBox all read it, so LaunchBox
artwork follows region_mode too, and uppercase config codes match the
ROM's tags for every provider.

European country codes map to IGDB's EU locale and ScreenScraper's ss
to the default title, so a (France) ROM no longer falls through to the
next configured region.

An unquoted no (Norway, Norwegian) in scan.priority.region or
scan.priority.language loads as false from YAML and crashed every IGDB
match. The config loader now turns it back into "no" and drops other
non-string entries with a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(igdb): drop _string_codes and spell out the EU region codes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-26 20:11:48 -05:00
Marcello Pichini
13e1a612d8 fix(launchbox): read the YouTube id from watch URLs wherever v sits and without a fragment (#5764)
* fix(launchbox): read the YouTube id from watch URLs wherever v sits and without a fragment

A video URL with v after another parameter yielded no id, and a #t= fragment was kept as part of it.

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

* fix(launchbox): ignore a trailer URL that cannot be parsed

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

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(metadata): share one YouTube id parser across LaunchBox, Demozoo and Pouet

LaunchBox now also reads ids from embed, shorts, live, /v/ and
youtube-nocookie links, and Demozoo and Pouet now accept URLs without
a scheme. Ids are checked against the 11-character format at parse time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-26 08:41:27 -05:00
Terri
a420c7da31 fix(saves): stop Pokemon scratch RAM writes from flooding save sync (#5758)
* fix(play): show the automatic Save synced toast at most once every 5 minutes

* fix(saves): let sigil decide when a Pokemon save is the same, ignoring scratch RAM

* pr-ready: code-review

* pr-ready: review-polish

* pr-ready: prose

* fix(play): hold SRAM changes in the browser and upload them once the game goes quiet

* fix(play): upload a held save before a state replaces it, and report only new snapshots

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review fixes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(play): leave a save a running session holds out of other tabs' sync passes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(sigil): pin ef9b51e

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 07:41:09 -05:00
Georges-Antoine Assi
f3ea3e498c test(api): keep helper responses in a swallowing try and resolve caught classes (#5781)
Follow-up to #5715, from the review findings posted after it merged:

- Inside a try that swallows errors, a call to a helper that returns an
  error response was dropped, so its status went missing. The analyzer
  now reads such a call in a "returned" mode that keeps the responses
  the helper builds or returns and drops what it raises.
- A handler for http.client.HTTPException was treated as catching
  FastAPI's HTTPException, since only the last name was compared. Handler
  classes now resolve through the module's imports, so the 502 that
  broker.request raises in webstation._cores_reply is kept.
- A declared raise inside a swallowing try no longer counts.
- Shorten the UNREADABLE_STATUS comment to two lines.


Claude-Session: https://claude.ai/code/session_011waFLFaNttxvn8EYtvLSwo

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-25 09:13:33 -05:00
MMagTech
695fd5a9f1 fix(users): delete a user who has play sessions on a device (#5757)
* fix(users): delete a user who has play sessions on a device

On MariaDB, deleting a user whose play sessions name a device failed with
error 1452 once play_sessions had been rebuilt, as restoring a dump does.
The cascade clears device_id on rows of the user being deleted, and InnoDB
rechecks their user through the index that also holds device_id. The user's
devices are now deleted first, while the user still exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(users): force the play_sessions rebuild in the delete-user test

OPTIMIZE TABLE can defragment instead of rebuilding when innodb_defragment
is on (MariaDB 10.11), which would leave the index order unchanged.
ALTER TABLE ... FORCE always rebuilds. Addresses Greptile review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-24 09:24:54 -05:00
Georges-Antoine Assi
c413c066c6 refactor(docker): supervise the container with s6-overlay (#4019)
* refactor(docker): supervise the container with s6-overlay

The init script was a hand-rolled supervisor: PID files, /proc polling, a
5s watchdog loop and a trap-based shutdown. Its shutdown wait was unbounded,
so a process that refused to exit stranded PID 1 and left the container up
and serving nothing, which no restart policy can detect.

s6-rc replaces it with a declared service graph. Ordering and readiness
gates that were sequential bash become dependencies, and the failure modes
become configuration:

- timeout-kill bounds SIGTERM before SIGKILL, and flag-timeout-killpg
  escalates to the whole process group.
- S6_BEHAVIOUR_IF_STAGE2_FAILS=2 exits the container when a startup step
  fails, so the restart policy retries instead of the container wedging.
- valkey gets --shutdown-on-sigterm force, so it stops refusing to exit
  when the snapshot it writes on shutdown cannot be written.

A crashed service is now restarted on its own instead of taking the whole
container down. Its leftover children are swept first, because children
reparented from a hard-killed master keep holding its listening sockets and
would make every replacement fail to bind.

Optional services have no conditional mechanism in s6-rc, so they start,
check their environment variable, and take themselves down with s6-svc -O.

Running with a read-only root filesystem now needs /run mounted exec, since
s6 executes its generated stage scripts from there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(docker): always start the RQ scheduler under s6

The s6 service carried over the four-flag ENABLE_SCHEDULED_* gate from the
init script, which #4033 has since removed on master. Since this branch
deletes that script, the fix would be lost on rebase.

Nothing else respects the condition: startup.py registers the netplay,
upload-tmp and zip-cache cleanups unconditionally, three more flags gate
periodic tasks absent from the list, and the watcher defers its rescans
through the scheduler. Any of those leaves jobs in the scheduler registry
with no process to run them, and a stuck delayed scan_platforms entry reads
to the concurrent scan guard as a scan already queued, refusing every
manual scan.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(docker): port master's init changes to the s6 services

Master reworked docker/init_scripts/init while this branch replaced it,
so carry those changes into the s6-rc services:

- Replace rq-scheduler with `rq cron` (romm-rq-cron) on tasks.cron_config.
- Add romm-rq-scan-worker (scans queue) and romm-rq-streaming-worker
  (streaming queue, down unless config.yml enables streaming).
- Run every worker with --with-scheduler and the RomMRedis connection
  class, passing the Redis URL through RQ_REDIS_URL so the password stays
  off the command line, and read REDIS_SSL as a boolean.
- Bring gunicorn's flags in line: --no-control-socket, a private-range
  FORWARDED_ALLOW_IPS default, 4 workers and a 65s keep-alive.
- Check the sync folder and SSH keys path in romm-init, and switch the
  features off through the container environment when they're unusable.
- Accept the backend's truthy values for the watcher flags.
- Point the serving-layer guard tests at the gunicorn run script and
  drop the PID-file tests, which guarded the bash watchdog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(docker): guard the s6-overlay service tree

Check that every service is in the user bundle, depends on something
that exists, and that every longrun has its finish sweep, kill timeout
and process-group flag. Also check that the dev entrypoint starts the
same RQ workers and cron scheduler as the image, since it keeps its own
launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(dev): pass the image's RQ flags in the dev entrypoint

The dev image's RQ cron scheduler and workers ran without the RomMRedis
connection class, and the workers without --results-ttl, so they kept
redis-py's maintenance notification probe and RQ's default result TTL.
The s6 guard test now compares each rq command's flags with the image's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(docker): address Greptile review on the s6 service tree

- Cut the s6 script comments to two lines, keeping the reason each
  helper exists.
- Compare the values of the dev entrypoint's RQ options with the
  image's, not only their names, allowing for the dev image's path,
  PID files and LOGLEVEL default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(docker): check every s6 service stays up after boot

The heartbeat only proves gunicorn and nginx came up. Enable both watchers
and require each longrun in the s6 tree to report up for 15s straight, so a
crashing or restart-looping worker, cron, valkey or watcher fails the job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(docker): enable streaming so its worker is checked too

The streaming worker turns itself off when streaming.enabled is false in
config.yml, which the services check read as a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-24 08:29:06 -05:00
Sam Dornan
fdba47d362 feat(filters): exclude platforms in the search filter drawer (#5756)
* Let the platforms filter exclude as well as include

The search filter drawer gains an Any/None toggle next to the platforms
select. `GET /api/roms` takes a new `platforms_logic` parameter ("any" or
"none"); "all" is rejected because a rom has one platform.

An exclusion keeps the grouped single-platform cache from answering, is
carried into the filter-values scope, round-trips through the URL, and
is stored on smart collections as `platforms_logic: "none"`. A platform
route always includes its own platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NH5s4icN79J4F1bZ15pmZG

* Rename the filter drawer's "Tags" heading to "Attributes"

The section holds genre, franchise, company, region, status and more,
with "Tag" as just one of its rows, so the heading read as if every row
were a tag. The platforms select joins it as the first row, and the rows
share one column grid so the selects line up even though the platforms
toggle has no "all" button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NH5s4icN79J4F1bZ15pmZG

* Fix three gaps in platform exclusion found in review

- A URL with platforms but no platformsLogic now includes them, so
  following an inclusion link after an exclusion no longer keeps
  excluding. Without platforms the logic is left alone, since it is
  never written to the URL then.
- Smart collection criteria give the route's platform priority, as the
  gallery request does, so a collection saved on a platform page never
  excludes the games on screen.
- The drawer's Reset button resets the platforms toggle to Any.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NH5s4icN79J4F1bZ15pmZG

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:56:48 -06:00
HadNutz
b1d7d2b57a feat(emulatorjs): expose download cache enable setting (#5737)
* feat(emulatorjs): expose download cache enable setting

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(config): move cache_limit under emulatorjs.cache and read config.yml strictly

emulatorjs.cache.limit replaces emulatorjs.cache_limit, which is still read
with a deprecation warning and is rewritten to the new key on the next save.

Every config.yml read now goes through one reader that exits with code 3 when
a parent block is not a dictionary (e.g. `netplay: true`), where get_nested
silently fell back to the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(emulatorjs): clear every EmulatorJS cache and keep nightly's cache size

The clear-cache dialog now also deletes EmulatorJS-bios (4.2.3) and
EmulatorJS-Cache (nightly), which kept serving downloaded files.

Nightly turns EJS_CacheLimit, a per-file byte cap in 4.2.3, into its total
cache size in MB, so a limit under 1 MiB gave a 0 MB cache. Passing
cacheMaxSizeMB explicitly keeps nightly at its own 4096 MB default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(utils): drop get_nested

The config loader reads config.yml through its own strict reader now, so
get_nested has no callers left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:13:18 -05:00
MMagTech
ea8aac7d5d fix(ra): hash an arcade set by its archive, not the CHD beside it (#5747)
* fix(ra): hash an arcade set by its archive, not the CHD beside it

RetroAchievements identifies an arcade game by its set's name. A folder
holding a set and its disc was hashed by the CHD, which is named after the
disc (gdl-0018.chd beside azumanga.zip).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Pass the arcade set's archive to RAHasher directly. RAHasher on Linux
does not expand a /* wildcard, so the arcade hash of <folder>/* is the
MD5 of an empty name. Prefer the archive named after the folder so a
larger BIOS or parent zip beside it does not win.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: plain-prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-23 11:13:09 -05:00
MMagTech
fdd311bdf3 fix(ra): match NAOMI, Atomiswave and Gaelco games again (#5746)
RetroAchievements' Arcade has sets for games Flycast runs (Atomiswave,
NAOMI, NAOMI 2 and NAOMI GD-ROM) and for Gaelco games FinalBurn Neo runs.
Since #5273 those folders have slugs of their own with no RetroAchievements
console, so their games get no hash.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 10:41:09 -05:00
Georges-Antoine Assi
1ab3a3625a feat(auth): use the OIDC picture claim as the user's avatar (#5730)
* feat(auth): use the OIDC picture claim as the user's avatar

On each OIDC sign-in, a user with no avatar, or one synced from the
provider earlier, gets the picture claim stored as their avatar. An
uploaded avatar is never replaced. The download goes through the
SSRF-guarded client (the configured provider's origin may reach a LAN
address), is capped at 5 MB, must sniff as a supported image, and any
failure is logged without blocking the sign-in.

Closes #4297

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(auth): address review on the OIDC avatar sync

Addresses Greptile's review on #5730:
- ask the UserInfo endpoint when the ID token has no picture claim
- keep an avatar uploaded while the picture downloaded
- allow only the OIDC provider's origins to reach private addresses
- trim docstrings and narrow await_args in the callback test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(auth): type the OIDC avatar test helpers for mypy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Bound the OIDC picture download with an overall deadline, trust the
OIDC CA bundle, catch hostname encoding errors so sign-in never 500s,
and set the synced avatar with a conditional update so a concurrent
upload wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Type the pytest fixtures and helpers in the OIDC avatar tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(auth): remove the synced OIDC avatar when the user uploads one

Once avatar_path points at the uploaded avatar.<ext>, the sync never
touches the user's avatar again, so the old oidc-avatar.<ext> file
would otherwise stay on disk for good.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:23:21 -05:00
Georges-Antoine Assi
f4504215dc feat(auth): log the attempted username on every failed sign-in (#5729)
Each failed password, token or OIDC sign-in now logs one warning line,
auth.login_failed method=... reason=... username=... ip=..., so tools
like fail2ban and CrowdSec can detect username enumeration as well as
brute force. A name that matches no account is logged as a short keyed
hash, since it may be a password typed in the wrong box.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:25:42 -05:00
Georges-Antoine Assi
dccbae50d3 fix(roms): default an uncategorised nested file to game (#5728)
A file below no category folder is part of the game, so the file schema
now reports it as game, the same as a top-level file. Clients selecting
a folder game's files by category get the whole game.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:24:55 -05:00
Georges-Antoine Assi
ece64f4ca4 feat(scan): list the ROMs a ScreenScraper breaker skipped in the scan summary (#5727)
* feat(scan): list the ROMs a ScreenScraper breaker skipped in the scan summary

A ROM whose ScreenScraper lookup was answered by the quota or credentials
breaker is now recorded, and the end-of-scan summary lists those ROMs beside
the rate-limited ones. A ROM whose name lookup still reached ScreenScraper
after a short-circuited hash lookup is not listed.

Closes #4358

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ss): list quota-skipped roms by path

Addresses Greptile's review on #5727: same-named roms on different
platforms collapsed into one entry in the skipped list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:22:56 -05:00
Georges-Antoine Assi
80eca562f7 fix(demozoo): send an API key with every Demozoo request (#5723)
* fix(demozoo): send an API key with every Demozoo request

Demozoo's API has required an API key since 2026-11-01. Add
DEMOZOO_API_KEY, sent as an Authorization: Api-Key header, and enable
Demozoo when it is set, like the other key-based providers. It replaces
DEMOZOO_API_ENABLED, since requests without a key are refused.

Fixes #5698

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:21:00 -05:00
Georges-Antoine Assi
e427d8b093 fix(scan): fetch file rows per rom on quick scans (#5725)
* fix(scan): fetch file rows per rom on quick scans

A quick scan loaded every file row of a 200-rom batch up front, so a
platform with a few extracted multi-file games held hundreds of thousands
of RomFile objects at once and the worker was OOM-killed. Each rom now
fetches its own rows inside the scan semaphore, capping the rows held to
SCAN_WORKERS roms.

Refs #5706

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style(scan): shorten the batch lookup comment

Addresses Greptile's review on #5725.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:01:51 -05:00
Georges-Antoine Assi
ee14785ad6 fix(streaming): restore only broker-pulled save archives natively (#5724)
* fix(streaming): restore only broker-pulled save archives natively

A device client (Argosy with Eden or Azahar) can sync its own zip under the
emulator name a streaming container uses. RomM treated any .zip from that
emulator as a native broker archive and pushed it as-is, so the broker
refused the restore with a 422 for members outside its save subtrees.

Only archives RomM filed from a broker pull (*.saves.zip) restore natively
now. A client zip is skipped by the default launch and, when picked, goes
through the broker's import path where it accepts saves.

Fixes #5268

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): keep a broker archive's suffix through a rename

Addresses Greptile's review on #5724: renaming a broker-pulled save to
another .zip dropped the .saves.zip marker, so the next launch stopped
restoring it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:43:41 -05:00
Georges-Antoine Assi
9b200d8696 fix(watcher): quick scan a new platform folder instead of updating the library (#5722)
A change to a platform directory scheduled an UPDATE scan of the whole
library, which only refreshes ROMs that already exist, so a new platform
showed up empty until the next quick scan. Every change now schedules a
quick scan scoped to its platform, and a folder with no platform row is
scoped by its slug so the scan creates the platform and adds its ROMs.

Fixes #5707

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:39:09 -05:00
Georges-Antoine Assi
5cd01267c0 fix(search): keep NSFW SteamGridDB covers from age-restricted users (#5721)
The cover search asked SteamGridDB for every content variant, so a user
under an age limit could browse NSFW artwork through a client. The
server now asks for SFW grids only when the caller has an age rule.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:31:42 -05:00
MMagTech
23ea65e2fe fix(snapshots): record the pushing device on a snapshot's states (#5720)
A push stored its save with origin_device_id and its states with none.
The web player counts a state with no origin_device_id as its own and
prefers a state on a tie, so after a console pushed a save and states in
the same snapshot, the web player booted the console's state instead of
its save, though that state may be another core's or older than the save.

A pushed state now carries the same origin_device_id as the save beside
it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:01:19 -05:00
MMagTech
ac9f5ab505 fix(saves): hash bytes that only end like a zip as one file (#5719)
* fix(saves): hash bytes that only end like a zip as one file

zipfile.is_zipfile is true for any file whose last 64 KB hold a zip's end
record. An emulator state can: Power Stone's Flycast (Naomi) state holds
the tail of the game's own TorrentZip archive. Reading such a file as a
zip fails, so compute_content_hash returned None, and a snapshot push
carrying the state was refused whole with "does not hash to the
manifest's value".

When the bytes cannot be read as a zip (BadZipFile), compute_content_hash,
hash_save_content and the memory card hash now hash them as one file, as
the web player's saveContentHash and the snapshot identity hash already
do. A real zip they cannot read within the limits stays unknown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Hash bytes as one file when the copied central directory points an entry
before the bytes start, as the tail of an archive longer than the state does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: plain-prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(saves): decide what is a zip archive by one rule

Bytes are a zip archive only when their entries start at the first byte.
A state or save holding another archive, whole or only its tail, after
data of its own is hashed, shaped, uploaded and unpacked as one raw file
everywhere: the content hashers, the identity hash, save_shape_of,
check_upload and unpack_save_unit. A real archive with a corrupt entry
stays unknown to the content hashers, and the identity hash falls back to
the bytes for one past the limits too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-22 10:00:16 -05:00
MMagTech
e63677ede3 fix(snapshots): keep a row's updated_at when its sharing is synced (#5718)
Pruning a channel re-syncs the sharing of the save and state rows the
deleted snapshots shared with snapshots that stay. That Core UPDATE of
is_public also ran updated_at's onupdate, so each kept row took the
prune's time though nothing in it changed. The web player resumes the
newest save by updated_at, so after a push that pruned a snapshot more
than ten back it booted an old save another snapshot still held, often
another app's.

sync_content_visibility now keeps updated_at, as touch=False does for the
sharing routes: sharing is not a write. The same holds where a push into a
public channel, a channel's sharing change and a snapshot's sharing change
sync it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:25:18 -05:00
Georges-Antoine Assi
ca8efb7a11 test(api): check returned, forwarded and stale error statuses (#5715)
* test(api): check returned and forwarded error statuses too

The route error check only saw HTTPException with a literal status. It
now also counts error responses a route returns, statuses passed to a
helper, status maps, IfExp and local variables. A status it still cannot
read fails the check instead of passing silently. Routes left out of the
schema are skipped, and 422 counts as documented only when FastAPI
documents it. The API description now names the middleware errors no
route lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(api): fail on documented statuses a route cannot raise

Add a stale check, the reverse of the undocumented one. To keep its
false positives near zero, the analyzer now follows functions run
through asyncio.to_thread and similar offloads, and skips a try body
whose handler swallows every error (keeping the responses it returns).
A new `# route-errors: raises <codes>` marker declares what a line
raises when the analyzer cannot follow or read it.

Following offloads found an undocumented 502 on save-and-exit: a
container with no broker address fails the card wipe. search_cover
declares the SteamGridDB 401 it re-raises from a gather.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: plain-prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review (best-effort broker PUT never raises)

put_binary_json looked up the broker URL outside its try, so a container
with no broker address raised a 502 from a helper documented as never
raising. Evacuation already fails first on that container, so the 502
documented on save-and-exit could not happen; drop it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: plain-prose (code-review additions)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish (build a real container in the broker test)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 16:37:42 -05:00
Marcello Pichini
084a6404e2 fix(auth): return no public base URL when ROMM_BASE_URL is malformed (#5700)
get_public_base_url promises the URL only when it is shareable, else
None, but yarl.URL raised ValueError on a value such as "http://[invalid",
so invite and notification rendering failed instead of omitting the link.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 10:05:03 -05:00
Georges-Antoine Assi
2d7b9e3c34 test(api): check that routes document the error statuses they raise (#5686)
* test(api): check that routes document the error statuses they raise

protected_route now documents the scope guard's 401 and 403 on every
route that declares scopes, appending to a route's own description when
it has one.

tools/route_errors.py follows each route's calls through imports,
handler instances, custom exception classes and HTTPException subclasses
to the statuses it can raise. test_raised_statuses_are_documented fails
on a status the route's responses= leaves out, against a baseline of
existing gaps that can only shrink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 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>

* fix(api): answer like a missing resource for hidden play sessions and private collections

DELETE /play-sessions/{id} deleted the caller's session even on a rom
hidden from them, so 204 versus 404 showed the session existed. The
handler now takes the caller's rom visibility.

Another user's private collection, smart collection or playlist
answered 403, which showed it existed. It now answers 404 on every
route; a public one the caller does not own still answers 403 on write.

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(collections): use #5693's docstrings on the routes this PR touches

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>

* test(api): follow route dependencies in the status analyzer

Addresses Greptile's review: route_errors now follows the callable in
Depends(...) and Security(...), whether it is a parameter default or
inside an Annotated alias, and the module docstring is one line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): tighten wording of route error descriptions

Give clipped responses descriptions and helper docstrings their missing
subjects and verbs, use 'the caller lacks' and 'is not allowed to'
consistently, and replace 'picked' with 'chosen'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(api): drop the route error baseline

Every status left in the baseline was one a client cannot get:

- The export routes' empty platform list check is dead, since FastAPI
  answers a missing required list query with 422. Removed.
- get_save_layouts went through _restore_error, whose 500 fallback it
  cannot reach. It raises its 400 and 503 directly now.
- The notification test and confirm routes only catch ChannelError,
  since the cooldown and email errors come from other actions.
- The analyzer now skips asyncio.gather(..., return_exceptions=True),
  which covers search_rom.
- A '# route-errors: ignore' marker, with its reason, skips code whose
  errors never reach the client: the metadata heartbeat probe, the
  force-release teardowns, and the legacy save adoption.

The check now fails on any undocumented status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 10:00:18 -05:00
Georges-Antoine Assi
20bff0830a fix(streaming): merge the webstation exit delta over the restored save archive (#5673)
* fix(streaming): merge the webstation exit delta over the restored save archive

A webstation exit export holds only the files changed since launch, but
RomM filed it as a standalone .saves.zip and the next launch restored only
the newest zip. A session that exited without an in-game save therefore
filed an archive with no save data, and the next Play booted without it.

The launch now records which native archive it restored on the session
record, and the exit pull lays the delta over that archive before filing
it, so every stored archive is a full snapshot.

Fixes #5544

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(streaming): type the stored exit archive as bytes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(streaming): skip the exit merge when the restored archive was replaced

PUT /saves/{id} rewrites a save in place under the same id, so the exit
merge could combine the session's delta with save data it never loaded.
Record the restored archive's content hash at launch next to its id, and
merge only while the base still has it; otherwise file the delta alone.

Addresses Greptile's review on #5673, including folding the
_over_restored_archive docstring into one sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(streaming): drop ensure_zipfile_writable from the archive overlay

#5678 applies the zipfile_inflate64 fix where it is imported, and removed the helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review additions)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(streaming): keep imported states, folders and the entry cap in the exit merge

A launch that imported a state left the base archive's states off the
container, so the exit merge now leaves them out too. The merge keeps
both archives' folders and refuses past the archive entry limit, so a
merged archive always gets a content hash. The webstation hydrate now
uploads the save its caller resolved instead of looking it up again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(db): query a platform id no sequence can reach

Postgres keeps id sequences across tests, so a worker that has created
about a thousand platforms hands id 999 to the fixture's own platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 08:40:47 -05:00