Commit Graph

934 Commits

Author SHA1 Message Date
Georges-Antoine Assi
4d74c05e1d 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>
2026-11-24 10:15:48 -05:00
Georges-Antoine Assi
cf18cc9799 pr-ready: code-review
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 09:46:38 -05:00
Georges-Antoine Assi
4c5a088d6b Merge remote-tracking branch 'origin/master' into fix/consistent-sibling-groups
# Conflicts:
#	backend/handler/database/roms_handler.py
#	backend/handler/recommendation/serving.py
2026-11-24 09:14:56 -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
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
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
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
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
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
MMagTech
a2ac57959d fix(saves): keep a slot's channel when an added file moves the sync file (#5697)
A legacy upload to a slot files its save under the channel of that name,
found on the game's sync file when no earlier upload links the slot. A
snapshot client keys a game's channels to that file and its saves carry no
slot, so once a file added to the game becomes the sync file (a cue beside
a chd), the next upload to autosave made a second, empty default channel
on the new file instead of joining the player's.

When the sync file holds no channel of that name, the slot now takes the
game's own channel of that name on another of its files still on disk,
before making one on the sync file. The sync file's channel still comes
first, and a channel on a file the game no longer holds, or on another
game's copy of the file, is not taken.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 08:13:34 -05:00
MMagTech
f2986597d5 fix(scan): read title ids from zipped games (#5694)
A scan skipped every archive before asking sigil for a title id, but sigil
reads a .zip in place: a Vita dump through its sce_sys/param.sfo, any other
platform through the largest member. So a zipped game got no title id and
no cart facts, which left its saves nothing to convert between emulators by.
PS Vita is the common case, since a zip is the usual Vita dump.

Let .zip through both checks and keep skipping every other archive, which
sigil doesn't open. A hashed single-file archive also never queued its file
for extraction, so that branch now does, as the others do.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 07:19:11 -05:00
Henrique Reis Neves
a936e661dd fix(resources): inflate gzip-encoded metadata media downloads (#5670)
store_media_file streamed the raw response body without decode_gzip, so
media served with Content-Encoding: gzip (the LaunchBox image CDN does
this whenever the client accepts gzip) was written to disk still
compressed. Covers, screenshots and manuals already inflated it.

Fixes #5669

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:24:27 -05:00
Stu Anderson
0941b3033e feat(roms): load roms by an array of ids (#5663)
* feat(roms): load roms by an array of ids

GET /api/roms accepts up to 256 rom_ids and returns those roms in the
order given. Ids the caller can't see, or that don't exist, are left out.

Closes #5659

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

* fix(roms): code-review pass on rom_ids window

Reuse RomIdScope (dedupe, shared 500 cap), skip sidecar and grouped page
cache reads for a window by id, report offset 0 and the id count as limit,
and rename the shadowed rom_ids local in _transform.

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

* refactor(roms): simplify pass on rom_ids window

Return early for rom_ids before building the filtered query, the sidecars
or any cache key, through a shared _hydrate helper, so the paged path is
back to its prior shape. Tests use the headers fixture.

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

* test(roms): review-polish pass, cover a hidden platform in the rom_ids window

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

* fix(collections): refuse malformed virtual collection ids, require page-row visibility

A malformed virtual_collection_id raised an uncaught decode error (500) on
the gallery, random and bulk download routes. It is now a 422 at the query
boundary, and GET /collections/virtual/{id} answers 404.

get_page_rows_query takes visibility as a required argument, since it is
the access check on caller-supplied rom ids.

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

* feat(gallery): load scroll windows by rom id

Once the bootstrap holds the whole ordered id index, a window fetch sends
that slice as rom_ids, so the backend skips the filtered, offset-paged
query. Items are placed by id, since ids that went missing or hidden are
dropped from the response.

On a 100k-rom MariaDB library, a filtered grouped window went from
0.8-2.0 s to ~50 ms, and a deep ungrouped window from 106 to 50 ms.

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-20 11:12:57 -05:00
kynrek
f9c8c8ab2a perf(roms): page grouped galleries from the cached id index (#5636)
* perf(roms): page grouped galleries from the cached id index

With group_by_meta_id, every gallery page ran the sibling-dedup window
over the whole library, because the frontend fetches pages with
with_rom_id_index=false. Grouped pages for the whole library or a plain
platform list now slice the versioned, cached id index instead, so only
the first page after a change pays for the window. Filtered, searched and
collection pages still run live.

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

* fix(roms): share one cached key for grouped platform sidecars (pr-ready: code-review)

Grouped platform-only sets read their char index, id index and pages
from one key, deleting a platform invalidates the cached lists, and the
platform-only gate derives from has_scope().

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

* refactor(roms): simplify grouped sidecar caching (pr-ready: simplify)

Add RomFilterParams.has_only_platform_scope, share one str key base
between the sidecar key builders, collapse the total and index
branches, and dedupe the platform-key tests.

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

* test(roms): cover has_only_platform_scope (pr-ready: review-polish)

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

* perf(roms): page grouped galleries from a Redis list, bump on deletes

- Store the cached id index as a Redis list. A grouped page reads its
  window with LRANGE/LLEN instead of decoding the whole list.
- Page requests only read the cache; on a miss they run the live page
  query, so only the index request rebuilds the list.
- Cache grouped platform sets only for a single platform, and never
  store an empty list, so client-chosen platform ids can't grow Redis.
- delete_rom and delete_platform queue the after-commit version bump,
  replacing the hand-placed calls in the endpoints and cleanup task.

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-18 18:48:02 -05:00
Georges-Antoine Assi
866d95640f fix(auth): check a dummy hash when the username is unknown (#5633)
* fix(auth): check a dummy hash when the username is unknown

Password sign-in skipped bcrypt for usernames with no account, so a
failed login answered far faster for an unknown name than for a real one.
Verify against a throwaway hash in that case so both take the same time.

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

* fix(auth): run the dummy bcrypt check for accounts without a usable hash

OIDC-provisioned and empty-hash accounts skipped bcrypt, so a failed
password sign-in for them answered faster than for an unknown username.
verify_password now falls back to the dummy hash whenever the stored one
is unusable, and the tests assert bcrypt ran on a valid hash.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:00:36 -05:00
Georges-Antoine Assi
00e40bdeb1 fix(sync): bound PSP PARAM.SFO size and TITLE length before ROM search (#5631)
A PARAM.SFO up to the upload limit was parsed in full, and its TITLE,
of any length, became the ROM search term. The search builds one SQL
condition per word, so a title of millions of words exhausted the
worker's memory before any query ran.

Reject PARAM.SFO files over 64 KiB (real PSP saves are under 5 KiB) and
ignore a TITLE longer than the 128-byte field the format defines.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:48:05 -05:00
Georges-Antoine Assi
494b4b4291 fix(auth): issue a new session id when the session changes identity (#5630)
* fix(auth): issue a new session id when the session changes identity

Logging in (password or OIDC) wrote the user into the session named by
the request cookie, so a session id set in the browser beforehand kept
working for whoever held it after the login. The session middleware now
writes the session under a fresh id whenever its user changes, and
deletes the previous record and closes its sockets.

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

* fix(auth): leave the session cookie alone when a refresh finds it gone

A request still in flight on a session that a concurrent login rotated
away failed its refresh and answered with an expiring session cookie,
which wiped the fresh cookie the login had just set. A failed refresh
now sends no Set-Cookie at all.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:46:01 -05:00
Stu Anderson
220226feba fix(hasheous): map Neo Geo MVS to the Hasheous Neo Geo platform (#5616)
* fix(hasheous): map Neo Geo MVS to the Hasheous Neo Geo platform

Without an entry, get_platform("neogeomvs") returned no Hasheous id and
scans never sent MVS hashes, leaving sets like mslug.zip unidentified.

Fixes #5614

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

* test(hasheous): drop arrange/act/assert comments to match the file

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:53:45 -05:00
Marcello Pichini
9bbfc41a7a fix(export): encode filenames in ROM content URLs (#5596)
* fix(export): encode filenames in ROM content URLs

* refactor(export): share one ROM content URL builder (pr-ready: code-review)

Move the quoted get_rom_content URL into utils.urls.rom_content_url and use it
from both exporters and the feeds. Match the test route to the real
{file_name} converter and drop an unused fixture.

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

* refactor(export): share the ROM file URL builder too (pr-ready: simplify)

Move feeds' romfile download URL into utils.urls next to rom_content_url,
with the same encoding. Resolve the test's URLs against the real app router
and drop the branching that re-checked local paths.

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

* test(urls): cover the ROM and ROM file content URL builders (pr-ready: review-polish)

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

* fix(export): match URL re-exports by ROM id and decode URL paths on import

A URL-mode gamelist or Pegasus export never matched its own earlier entries,
so each re-export appended every game again. Entries whose path is a RomM
content URL are now matched by the ROM id it carries, which also covers
unencoded URLs and other hostnames from older exports. The gamelist importer
decodes a URL path's last segment before matching it to a file name. Both
exports pass visibility=UNRESTRICTED explicitly, since they write the
library's shared metadata file.

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

* style: format romfile_content_url

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-17 07:17:05 -05:00
alexcastgonz
631a1a3763 fix(roms): parse TOSEC compound region and language tags (#5582)
* fix(roms): parse TOSEC compound region and language tags

* test(roms): use unrecognized compound tag components

* fix(roms): limit TOSEC compounds to two-letter codes (pr-ready: code-review)

Single-letter GoodTools codes made (SW-R) read as Sweden and Russia,
and old-style [T-Br] translation tags read as Taiwan and Brazil.

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

* test(roms): drop prefix test the compound branch never reaches (pr-ready: simplify)

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

* docs(roms): clarify _resolve_every docstring (pr-ready: humanizer)

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

* fix(roms): give exact-case codes precedence in compound tags

Addresses Greptile: "Nl-No" read as Netherlands and Norway instead of
Dutch and Norwegian.

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-14 15:33:31 -05:00
Georges-Antoine Assi
e813e4d666 chore(coherence): adopt Coherence with specs, invariants and a PR report (#5584)
* chore(coherence): adopt Coherence with specs, invariants and a PR report

Install @posthog/coherence as a frontend dev dependency and wire its
Claude Code hooks into the committed .claude/settings.json, so every
agent session in the repo gets the vocabulary, specs, journal and checks.
The hooks call the binary under frontend/ through $CLAUDE_PROJECT_DIR.

Declare 23 components and the entrances that carry outside trust, and
six invariants, each refuted with a deliberate break before it counted:

- every /api route requires auth and its scopes, except a named public
  list (new route sweep in tests/endpoints/test_route_guards.py)
- a hidden rom, platform or firmware answers every id route exactly as
  a missing id would (new sweep over every method of every id route)
- the unscoped save, state and screenshot fetches by id are reached only
  from their own routers (chokepoints)
- validate_path never resolves outside its base folder

The PR workflow runs in comment mode: one report comment, failing only
when Coherence itself breaks. Trunk skips Prettier and markdownlint on
*.spec.md and *.practice.md, since Prettier escapes their globs.

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

* test(routes): satisfy mypy in the route guard sweep

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

* chore(coherence): record the worktree test database enactment

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

* fix(roms): answer a hidden rom like a missing one on file routes; tighten route sweeps

Addresses Greptile's review on #5584.

The rom file delete and reading-progress routes answered "File not found"
for a hidden rom but "Rom with id N not found" for a missing one, so a
caller could tell them apart. They now raise the same not-found.

The route sweeps now reach the checks they claim to test: a protected
route with no scopes counts as public (its guard admits anyone), write
requests carry a body and upload name so validation can't answer first,
RomFile-keyed routes get a real file id, error bodies are compared with
the id normalized, and the rom routes are swept with the rom hidden
directly, through its platform, and by the unrated filter.

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

* fix(coherence): tighten route guard sweeps and isolate oracle test databases (code-review)

- Count a route as protected only when its endpoint is the scope-checking
  wrapper with non-empty scopes, not just when it declares the bearer scopes.
- Treat 401 and 403 like 422 as never reaching the visibility check, and
  sweep /api/streaming/states/{rom_id}.
- Run pytest oracles with a per-run ROMM_TEST_DB_TAG unless one is set.
- Use the shared setup-frontend action and ubuntu-24.04 in the workflow.

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

* refactor(tests): simplify route guard sweeps and path tests (simplify)

- Mark scope-guard wrappers with required_scopes so the auth sweep reads a
  public attribute instead of the private closure.
- Derive the entity regex from one segment list, ask each missing id once,
  and run the three hide scenarios through one sweep helper.
- Fold the new validate_path inputs into the existing valid, traversal and
  absolute path tests.

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

* chore(coherence): trim workflow comments (review-polish)

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

* test(filesystem): restore the validate_path property test the paths invariant cites

Filesystem.spec.md names test_validate_path_never_escapes_its_base as the
invariant's evidence, and Coherence selects it by name.

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

* chore(coherence): run hooks from the local binary instead of npx

Each hook calls frontend/node_modules/.bin/coherence directly and exits 0
when it isn't installed, so sessions without frontend deps (fresh
worktrees, backend-only setups, cloud setup still installing) don't report
a hook error on every tool call, and no hook pays npx's startup.

Also commits the journal and run records left by earlier sessions, which
.coherence/.gitignore keeps as durable records.

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

* refactor(tests): share the bearer, user token and hide helpers

Tests built the same Authorization headers and HiddenEntity rows in about
40 local copies, and two modules imported private helpers from other test
files. They now use bearer, user_headers and hide from tests/auth_helpers.py.

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

* refactor(endpoints): one 404 for a missing or hidden rom, platform or firmware

Each route wrote the missing-row 404 and the hidden-row 404 separately and
had to keep them identical by hand. visible_rom_or_404,
visible_platform_or_404 and visible_firmware_or_404 take the lookup result
and raise one answer for both, either the standard not-found or a bespoke
detail. Re-reads after a write keep a plain not-found check, so an edit that
hides the row doesn't turn into a 404 after it succeeded.

The RomFile-keyed routes (/roms/{file_id}/files, .../files/content/{name},
/roms/{file_id}/patch) name their path parameter file_id instead of id, so
the route sweep reads which id a route takes from its path and drops its
hand-kept list. URLs are unchanged.

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

* docs(setup): develop inside WSL on Windows

@posthog/coherence installs only on Linux and macOS, so npm install in
frontend/ fails on native Windows.

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

* chore(coherence): record the whole-repo chokepoint run

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

* chore(types): regenerate API types for the file_id patch route

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 10:53:46 -05:00
alexcastgonz
c56d27be7b fix(roms): read full country names in filenames as regions (#5578)
* fix(roms): read full country names in filenames as regions

No-Intro writes full country names, e.g. (Poland) or (Czech Republic).
parse_tags only resolved the names listed in REGIONS, so the regions added
from the provider vocabulary were stored as other tags. Add those names to
the filename region aliases, skipping any that a language vocabulary claims.

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

* chore(roms): shorten region alias comment per Greptile review

Addresses Greptile's comment-length finding on #5578.

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-14 10:29:59 -05:00
Henrique Reis Neves
17d184f4b6 fix(config): warn about platform bindings to unknown slugs (#5580)
* feat(config): warn about platform bindings to unknown slugs

A config.yml binding whose value is neither a platform slug nor a
folder alias (a typo such as `snes-test: snse`) silently made a custom
platform with no metadata. Nothing pointed at the binding: the scan only
logged "Platform snse not identified", like any unknown folder.

Startup and the platform scan now log a warning that names the
system.platforms or system.versions key, the bound value and the
closest known slugs. Unbound folders are not checked, so custom
platforms stay quiet.

Closes #5464

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

* fix(config): treat IGDB version slugs as known bindings (pr-ready: code-review)

Bindings to IGDB platform-version slugs such as amiga-a-1200 are
identified by the scan, so they no longer warn. Startup reuses the
config that migrate_retired_filesystem_keys just loaded.

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

* refactor(config): share the binding lookup with resolve_platform_slug (pr-ready: simplify)

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

* chore(config): tighten binding warning docstrings and test typing (pr-ready: review-polish)

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-14 07:57:35 -05:00
Terri
8a1e6280b1 feat(saves): add save channels and snapshots (#5198)
* feat(saves): add save channels and snapshots

* feat(saves): close spec gaps in save channels and hash with sigil

* feat(saves): play snapshots in the v2 player, which pushes snapshots

* fix(saves): code review: authorization, retention losses, held-save sync, batched responses

* refactor(saves): simplify pass

* refactor(saves): review-polish pass

* docs(saves): humanizer pass

* feat(saves): run every EmulatorJS page on the v2 player

* feat(saves): per-user snapshot pins

* feat(sigil): store the identity a save restore needs and pin sigil 0f05f25

* fix(saves): meet type-aware lint in the v2 player

* feat(sigil): store N64 header and playlist title ids, pin sigil 0847fda

* feat(saves): convert saves for a core on download and list save layouts

* feat(saves): prune unreachable archival snapshots and empty detached channels on delete

* feat(saves): device sync from the token, held snapshots and shared-card pushes

* feat(saves): arc restores past abandoned snapshots and color channels by age

* fix(saves): code-review and security-audit fixes

* refactor(saves): simplify pass

* chore(saves): review-polish pass

* docs(saves): humanizer pass

* fix(sync): file RetroArch autosave versions as their channel's next snapshot

* fix(saves): address review findings and trim docstrings

* fix(saves): share-lock planned rows by id so PostgreSQL accepts the lock

* test(saves): stub the detached-channels fetch in SaveDataTab stories

* feat(saves): carry the full current snapshot in a 409, pin sigil 2071dff

* chore(sigil): pin 5d4ddb4, which reads .cue and .gdi sheets

* docs(saves): drop v2 wording now that one UI remains

* chore(sigil): pin 0190443, which reads PS2 raw BIN images and cue sheets

* fix(sigil): treat a file too short for its format as routine during scans

* chore(migrations): renumber save channel migrations after upstream's 0154

* fix(snapshots): a hardcore switch on unchanged content makes a new current

* fix(sync): decide a channel's slot from its history and the device's snapshot

* chore(docker): pin sigil at 794d99f for PSP Store release save prefixes

* refactor(db): squash the save channel migrations into 0161

Fold the slot linking (0162) and the rom_files sigil identity columns (0163)
into 0161_save_channels, so the feature ships as one revision.

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

* fix(saves): close visibility and input gaps found in review (pr-ready step 2)

code-review --fix:
- negotiate_sync drops channel slots on ROMs hidden from the caller
- channel PATCH/attach/DELETE answer 404 when the channel's ROM is hidden
- a push copying a save from a hidden ROM answers 404
- _own_device applies require_token_device to bound client tokens
- adopting a legacy save syncs its sharing with the channel it joins

security-audit follow-ups:
- another user's detached public save or state is no longer downloadable
- profile and option values must be a single path segment
- companions are de-duplicated and capped at 8

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

* refactor(saves): share channel and asset lookups, drop duplicates (pr-ready step 3)

simplify:
- readable_channel_or_404 and channels_on_files replace four copies of the
  channel 404 check and two copies of the file-fed channel listing
- readable_rom_asset_or_404 serves both public save and state downloads
- _own_device resolves through require_device; _clone_origin takes the source
- reuse _unprocessable, DESCRIPTOR_EXTENSIONS, SAVE_SLOT_MAX_LENGTH, uniqueBy
  and uuidv7; neutral forms default their required pattern to the allowed one
- RetroArch delete checks held rows in one query, a guarded upload lists the
  slot only without a channel head, and uploads are read off the event loop
- snapshotSession builds push requests once; player comment cleanups

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

* docs(saves): trim two docstrings to two lines (pr-ready step 4)

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

* fix(saves): answer held RetroArch paths with 423, mirror slot labels

- RetroArch Cloud Sync answers 423 Locked for a PUT over a held unslotted save
  and for a DELETE where only held rows sit at the path, instead of 409 and 404
- channelLabelForSlot returns null for blank and state_ slots, as the backend's
  channel_label does, so the player files them under no channel either
- document that sharing a channel lets every user read and push into it

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

* chore(docker): pin sigil at 85f88a8 for Switch .nup containers

* fix(snapshots): a save pushed in another shape or format makes a new current

* refactor(saves): drop the always-true SAVE_SYNC.SNAPSHOTS heartbeat flag

Nothing reads it, and the SAVE_SYNC block's presence already tells a
client the server speaks the snapshot API. Also trim the rom detail
channel field comments to one line each.

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

* refactor(frontend): use uuidv7 for every client-generated id

Drop the randomToken wrapper and the notification inbox's Math.random tab
id, so uuidv7 is the one helper that works outside a secure context.

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

* refactor(saves): trim redundant snapshot API surface, dead code and duplicate logic

API:
- Drop PUT /snapshots/{id}/devices/{device_id}; GET /snapshots/{id}?hold=true holds.
- GET /snapshots is history only (channel_id required); GET /channels serves currents.
- A snapshot carries channel_id instead of an embedded channel.
- POST /saves/{id}/content takes the same query parameters as the GET, plus container_path.

Backend:
- Remove the archival write path, clone.py, DBStatesHandler.get_state, the sigil
  identity-hash path, unused relationships and composite snapshot indexes.
- One held/frozen lookup, one bulk-delete guard, SQLAlchemy dialect upserts, and
  the shared reserve_version_name in the writer.
- The writer takes a visibility filter and checks the channel and parent itself.
- The restore handler picks per-game or merge; fewer wrapper types and tables.

Frontend:
- Channel delete uses the shared typed confirm; DeleteChannelDialog is gone.
- Held offline pushes go through a per-channel SnapshotSession.
- Remove the slot-based pending upload path.
- The timeline shares the fan's badge logic.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* refactor(saves): release archival backups through module functions

The saves and states handlers each built a private DBSnapshotsHandler to
call release_backup and refresh_backup_digests, since they can't import
the shared instance. Both only ever ran inside the caller's session, so
they are now module functions taking it, like channel_for_slot.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* refactor(saves): share one deleted-assets handler instance

The saves handler built its own DBDeletedAssetsHandler because it can't
import the package's instance. The instance is now built in
deleted_assets_handler.py and re-exported by the package, so both use it.

Co-Authored-By: Claude Fable 5.2 <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-13 21:59:19 -05:00
Tyler Vigario
3c5bab7a7f fix(hltb): send the search's platform in the form HowLongToBeat filters by (#5569)
* fix(hltb): send the search's platform in the form HowLongToBeat filters by

HowLongToBeat's search ignores a platform sent as a bare name, so every
search covered every platform: "gran turismo" for the PSP came back with
the PlayStation game first, and the retry on a subtitle alone could match
a game on any console. Its site sends the platform as
{"mode": "include", "values": [...]}, which the search does filter by, and
the payload now sends it that way. With no platform name the list is
empty, which searches every platform.

A name outside HowLongToBeat's platform list filters out every game. It
lists PlayStation VR games under PlayStation 4, so that is what a
PlayStation VR ROM searches, and it has no PlayStation Now, so that
platform no longer maps to HowLongToBeat.

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

* fix(hltb): key HowLongToBeat's VIC-20 on the VIC-20, not the Plus/4

The VIC-20 entry was keyed on the Plus/4, which made no difference while
HowLongToBeat ignored the platform. Now that the search filters by it, a
Plus/4 ROM would be searched among VIC-20 games. HowLongToBeat has no
Plus/4, so that platform no longer maps to it.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 12:07:29 -06:00
Henrique Reis Neves
34117694ac fix(scan): read revision tags written without a separator (#5559)
GoodTools sets name a revision with no space or dash after "Rev", as in
"Sonic The Hedgehog (W) (REV01) [!].gen". REVISION_TAG_REGEX required a
separator, so "(REV01)" and "(Rev1)" left the revision empty and landed
in the free-form tags instead.

The regex now also takes "Rev" followed directly by a digit. A letter
right after "Rev" still does not count, so tags such as "(Revenge)" and
"(RevB)" stay plain tags.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 08:25:52 -05:00
Tyler Vigario
d96ec82e05 fix(scan): name a game by metadata priority, whatever order the scans ran in (#5546)
* fix(scan): name a game by metadata priority, whatever order the scans ran in

An unmatched scan asks only the sources a ROM has no match from yet, and
merges just their answers. A stored name that looks like a placeholder was
replaced by whatever name that subset gave, and a provider's name often looks
like one: LaunchBox calls Super C (USA).nes "Super C". So an unmatched
HowLongToBeat scan renamed it "Super Lucky's Tale", though LaunchBox ranks
above HowLongToBeat in scan.priority.metadata, and once a name no longer
looked like a placeholder no refresh could correct it.

Every source now keeps the title it gave in its own blob, as hash sources
keep their dump tags. On an unmatched, update or hashes scan the name goes to
the highest-ranked source among this scan's answers and the stored titles of
the sources the ROM is still matched to. A source matched before titles were
kept outranks the rest unknown, so the stored name stays. A stored name equal
to some source's title counts as derived, so a better-ranked source can
replace it; any other name is the user's and stays.

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

* fix(scan): count only a string as a source's kept title

The raw metadata editor stores any JSON, so a blob's name can be a list or an
object, which broke a refresh with an unhashable set element. kept_title now
reads a stored title for both settle_name and keep_base_fields, and anything
but a string counts as no title. settle_name's docstring is one sentence.

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

* fix(scan): settle names across Hasheous-filled IGDB columns and pre-existing rows

code-review (xhigh) pass: stamp every blob a source fills, treat only ids the
row already held as stored matches, count this scan's titles as derived, and
drop non-string kept titles from responses.

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

* refactor(scan): share one priority ordering for the name settle

simplify pass: order_merge_sources returns the full ordering so settle_name
skips its own config read, kept_title moves next to NAME_CLAIM_KEY and backs
the response filter, keep_base_fields' comments fold into one, and the name
priority tests share constants and parametrize their near-duplicates.

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

* chore(scan): reword settle_name's unknown-title comment

review-polish pass.

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

* fix(scan): settle slug and artwork by priority too, under a scan_claims key

Each source's blob now keeps the name, slug, cover and screenshots it gave
under one namespaced scan_claims key (a ScanClaims TypedDict) instead of a
bare name key that shared the providers' own key space. settle_claims ranks
every claimed field by its own priority list, so a partial scan no longer
writes a lower-ranked source's cover over a better-ranked one. A matched
source with no claims on record holds the stored value only when that value
is set. The artwork orderings are computed once and shared with
apply_artwork_priority, so no config read is added.

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

* refactor(scan): hide scan_claims from the API

The claims stay in each source's blob, but the provider metadata types no
longer declare them, so they're out of the OpenAPI schema and the generated
frontend types. Responses strip the key, and a raw metadata edit keeps the
stored claims while the source's match stands instead of taking the client's.

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-11 07:30:20 -05:00
Georges-Antoine Assi
03636ec156 fix(player): boot the base game, not a patch or translation (#5538)
* fix(player): boot the base game, not a patch or translation

Files in a game's translations/ or hacks/ folder were mixed in with the
base game: a .ups or .bps there counted as a bootable translation, a
tagged variant sorting first became the default, and "All discs" zipped
every file so EmulatorJS booted a translation's playlist.

Patch files are now recognised by extension wherever they sit, the
default and the selector's order favour the top-level (base) files, and
"All discs" requests only the base set through file_ids. The content
endpoint generates its playlist when the served files carry none, rather
than when the rom has one anywhere.

Fixes #5462

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

* fix(player): apply code-review fixes

Share the m3u check through has_playlist, memoise the boot file ids, and
correct the playerDisc comments.

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

* refactor(player): simplify the base-set helpers

One allDiscFiles helper backs offersAllDiscs, defaultDisc and bootFileIds,
and isPatchFile alone owns the patch rule.

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

* fix(player): keep variants and media out of playlists; classify patches on the backend

The backend's disc rule now leaves out patches, media and cheats, and a
playlist covers only the base game's discs, so whole-rom downloads, the
native shell and the streaming disc swap stop listing translations, hacks
or a selected manual. A selection with no disc gets no generated .m3u.

The scanner files any patch format as a patch, and the file schema does
the same for rows scanned before, so the frontend trusts the category.
The heartbeat now carries the supported patch extensions, which replaces
the frontend copy, and one fileExtension helper replaces three.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:56:17 -05:00
Georges-Antoine Assi
903ed64d94 fix(scan): hash compressed ROMs by their content in every format (#5537)
* fix(scan): hash compressed ROMs by their content in every format

Files inside a game folder and standalone single-stream files picked a
reader from a hand-written extension/MIME chain that treated plain .gz as
tar, missed .tgz/.txz/.xz and the application/gzip MIME spelling, and
called max() on empty archives. One suffix-then-MIME lookup in
utils/archives now picks the reader, plain gzip/bz2/xz streams are
decompressed (or read as a tarball when they hold one), and an empty or
unreadable archive falls back to hashing its raw bytes.

Fixes #5328

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

* fix(scan): don't read a zero-prefixed compressed stream as an empty tar

Addresses Greptile review on #5537: tarfile.is_tarfile accepts a
zero-filled opening, so a plain .iso.bz2 or .iso.gz starting with zeros
fell back to its compressed bytes. A tarball now needs a first member.
Also moves hash_largest_member's failure contract into Returns:.

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

* fix(scan): fall back to raw bytes on more unreadable archives (code-review)

Catch ValueError from corrupt Deflate64 members and undecodable zip
names, treat an archive with empty content as unreadable, route zips
with methods zipfile can't decode through 7zz, and drop the zlib.error
handlers no reader raises any more.

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

* refactor(scan): route 7z and undecodable zips through one largest-member reader (simplify)

Replace hash_largest_7z_member with a read_7z_file iterator built on the
shared 7zz listing and streaming helpers, probe zips with
_undecodable_zip_method instead of inspecting the exception cause, share
one decompression error tuple, snapshot only the ROM-level accumulators,
and reuse the archive-writing test helpers.

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

* fix(scan): bound, single-pass and RAR-aware largest-member hashing

- Every Python-side archive read (zip, tar, gzip, bz2, xz, and the
  composite zip/tar readers) now shares the SEVEN_ZIP_TIMEOUT budget the
  7zz and bsdtar paths already had, so a decompression bomb falls back to
  the raw bytes instead of tying up a scan thread.
- Compressed tarballs are read in one streaming pass: each member larger
  than every one before it is hashed into a copy of the hashers as it
  passes, instead of listing the whole archive and then decompressing it
  again to reach the largest member.
- gzip is decompressed member by member and ignores trailing bytes the
  way gunzip does, instead of discarding the content when padding follows
  the last member.
- RAR members inside game folders hash by their largest member through
  bsdtar.
- ARCHIVE_FORMAT_BY_SUFFIX moves to utils.filesystem and is the single
  suffix list: COMPRESSED_FILE_EXTENSIONS, RAR_FILE_EXTENSIONS and the
  handler's ARCHIVE_READERS are built from it.
- _calculate_rom_hashes detects the MIME type once per file and reads the
  embedded CHD hash in the same thread, so libmagic no longer runs twice
  per file or on the event loop.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 16:58:59 -05:00
Georges-Antoine Assi
0183cae8ad fix(retroachievements): ride out rate limits during the progress sync (#5532)
* fix(retroachievements): ride out rate limits during the progress sync

The progress sync asks RetroAchievements for each changed game's
achievements, one request per game. A single 429 that outlasted the one
2s retry became a 503 that aborted the whole sync and discarded every
game already read, so a large first sync never completed.

- send_with_retries honours Retry-After (capped at 60s) and doubles its
  backoff on each 429; rate limits can get their own attempt budget so
  timeouts are not retried more often.
- RetroAchievements gets five attempts against a 429.
- get_user_progression stops asking for game details once RA refuses
  one, keeps the stored entry for the remaining changed games, and
  returns what it read so it is saved and the next sync resumes.

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

* fix(retroachievements): keep stored progress on full refreshes and read pages first

Addresses Greptile review on #5532:
- a full refresh now passes the stored progression with refresh_all, so
  a refusal keeps the games it could not read instead of dropping them
- every completion page is read before any detail request, so a
  throttled later page fails before details are fetched and discarded
- docstrings trimmed to the comment rules

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

* fix(retroachievements): apply code-review fixes

pr-ready step 2 (code-review xhigh --fix): drop the synced progression
when the RA username changes, keep the award kind current on refused
games, read HTTP-date Retry-After values, and honour an explicit zero
rate_limit_attempts.

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

* refactor(retroachievements): apply simplify cleanups

pr-ready step 3 (simplify): reuse to_utc for HTTP-date Retry-After,
fold the None checks into _retry_after_seconds, drop the result=None
seed and the award-kind compare in get_user_progression, and share the
refusal setup and call() asserts across the new tests.

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

* chore(retroachievements): review-polish comment trim

pr-ready step 4 (review-polish): drop a comment that restated the code.

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

* fix(retroachievements): run the sync as a job and tell rejects from outages

- A non-429 error status or unreadable reply for one game keeps that
  game's stored progress and the sync moves on; only a throttle or an
  outage defers the remaining games.
- The five-attempt 429 budget applies to the progress sync's two
  requests, not every RetroAchievements call.
- A 429 holds the shared RA rate limiter through its wait and halves its
  pace, which steps back up as requests go through.
- Timeouts and 429s each count against their own attempt budget, and
  the 429 backoff doubles per 429.
- /ra/refresh queues the sync as a background job and answers 202; the
  job reports its outcome over the ra:synced socket event, which the
  settings section uses to reload the user or show the failure.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 07:56:45 -05:00
Georges-Antoine Assi
fa3654dd79 fix(platforms): stop filing sgb folders as Game Boy Color (#5530)
* fix(platforms): stop filing sgb folders as Game Boy Color

ES-DE and Batocera name their Super Game Boy system sgb (Game Boy games
on the SNES adapter). Mapping sgb and sgb-msu1 to gbc gave those folders
Game Boy Color provider ids and limited IGDB searches to the wrong
platform. RomM has no Super Game Boy slug and IGDB, TheGamesDB,
RetroAchievements and LaunchBox list none, so leave the folders
unidentified; a config binding can still map them.

Fixes #5506

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

* fix(scan): keep a missing platform folder unless its alias exists

Addresses Greptile review on #5530: with the sgb aliases gone,
gbc2players became the reverse folder for gbc, and a rescan with the gbc
folder missing saved that nonexistent folder on the platform.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:10:44 -05:00
Nathan Alcantara
e8fa1d5f20 chore(scan): recognize Brazilian Portuguese as a language (#5499)
* feat(scan): recognize Brazilian Portuguese as a language

Add "Pt-BR" (Brazilian Portuguese) to the filename language table, so
"(Pt-BR)" and "(T-Pt-BR)" no longer fall back to an unrecognized tag or
to European Portuguese, and show the Brazilian flag for it in the UI.

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

* fix(scan): read the regional variant ahead of a translation's version

"[T+Pt-BR1.1_Grp]" kept the version in the lookup and fell back to
Portuguese. Match only the two-letter variant that opens the patch, and
cover the Brazilian flag in the frontend tests.

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

* style(scan): apply black formatting

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 07:42:56 -05:00
Tyler Vigario
bbb7d98f53 fix(scan): look a file named by several titles up by each of them (#5478)
* fix(scan): look a file named by several titles up by each of them

No-Intro and Redump name a game released under several titles by all of
them, joined by " ~ ". Each file-name lookup now tries the full name
first and then each title, tags and extension kept, until one matches;
SteamGridDB searches the titles too. Only the title is split, never a
tag group.

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

* fix(scan): search each SteamGridDB name once

From Greptile's review: a title can repeat a name a provider already
gave, so SteamGridDB's candidate names are deduplicated, first position
kept, with a test. The new test module's docstring is one sentence, as
AGENTS.md asks.

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

* fix(scan): keep the full-name answer on a miss and cap title lookups

pr-ready step 2 (code-review xhigh --fix): return the full name's result when
every title misses, dedupe and cap titles at 4, and stop wrapping CSDb, whose
lookup only reads a (csdb-N) tag.

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

* refactor(scan): give SteamGridDB the bare titles and inline lookup args

pr-ready step 3 (simplify): add compute_titles so SteamGridDB stops re-attaching
and re-stripping tags, inline the Moby and SS platform ids, and merge the two
all-miss tests.

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

* fix(scan): keep the narrowed Moby and SS platform ids for mypy

pr-ready step 4 (review-polish): the locals inlined in step 3 narrow the
optional platform ids, which a lambda body cannot do; restore them.

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

* docs(scan): reword the title cap comment

pr-ready step 5 (humanizer).

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-08 16:40:43 -05:00
Sam Dornan
48c1e8a311 perf(scan): stop quick scan re-reading unchanged ROMs (#5516) 2026-11-08 11:12:28 -06:00
Georges-Antoine Assi
a688676de7 fix: enforce ROM visibility on assets, sync, collections, stats and scan events (#5498)
* fix(sync): cap play sessions on sync completion and require roms.user.write

The completion endpoint fed an unbounded play_sessions list to the same
ingest as POST /api/play-sessions, which allows 100 per batch and requires
roms.user.write. Apply both rules before the session is completed.

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

* fix(config): reject empty platform binding and version values

config.yml exits on load when a platforms or versions value is empty, so
the API must not write one.

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

* fix(collections): require smart collection criteria to be a JSON object

Any other JSON value was stored, then failed the response schema and broke
the smart collection list for every user who could see the collection.

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

* fix(stats): require roms.read on /api/stats

Anonymous callers were served counts over the whole library, including
platforms and ROMs hidden from users. The UI only calls it after login.

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

* fix(permissions): apply ROM visibility to filters, saves, play sessions and collection removal

/api/roms/filters aggregated facet values over the whole library, GET
/api/saves/{id} and GET /api/play-sessions returned the caller's own rows on
hidden ROMs, and removing ROMs from a collection could drop members hidden
from its owner. The facet visibility clauses move onto RomVisibilityFilter so
stats and filters share them.

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

* fix(webhooks): keep non-admin webhooks off the admin's internal metadata origins

The SSRF exception for a self-hosted Playmatch or Hasheous applied to every
request, so a user's webhook could reach any path on that private origin.
Non-admin webhooks now validate and connect with an empty allowlist.

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

* fix(saves): bound total decompressed size when hashing zip archives

Zip content hashing capped each entry but not the archive, so many
entries each under the cap could still decompress and hash far more
than any real save or memory card holds. Budget the decompressed bytes
across the whole archive and cap the entry count; callers keep treating
an over-budget archive as an unknown hash.

The chunked, budgeted entry reader is shared with the memory card
archive check, and the RetroArch store path now hashes off the event
loop like its siblings.

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

* fix(psp): clamp LZ4 literal and match copies to the ZISO block size

The ZISO block decoder appended literals and copied matches for their
full encoded length before checking the output size, and an LZ4 length
can be extended without bound by 0xFF bytes. A small crafted block
could therefore expand far past the block size before being truncated.

Clamp each copy to the room left in the block, stop once it is full,
end the block on a truncated match offset, and copy matches with slices
instead of a per-byte loop (overlapping matches repeat their pattern).
Output for valid blocks is unchanged.

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

* fix(auth): revoke OAuth tokens when a user's credentials change

A password change, admin reset, reset-link reset or rename cleared the
account's web sessions, but its OAuth access tokens kept working until they
expired and its refresh tokens could still be exchanged at /api/token.

Revoking a user's credentials now also records a per-username revocation
time in Redis, kept for the longest token lifetime. Bearer validation and
refresh consumption reject any token whose iat is at or before it. OAuth
tokens now carry a sub-second iat, so a login right after the change still
works; a token without iat counts as older than any revocation.

The revocation is keyed by the token's sub, the same username sessions are
keyed by, so a rename revokes tokens issued under the old name even if
another account later takes it. Client (API) tokens are left alone.

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

* fix(api): reject local file URLs for user-supplied covers and manuals

file:// and launchbox-file:// URLs are meant for covers and manuals that
a scan records from gamelist.xml or LaunchBox metadata. The collection
create/update endpoints and the ROM update endpoint passed a user-supplied
url_cover (and url_manual) straight to the resource handler, which copied
whatever library file it named into the entity's resources. That let any
user with collections.write or roms.write pull files they cannot otherwise
read, including those of hidden platforms and ROMs.

These endpoints now answer 400 for a local file URL, unless it is the value
already stored, which the edit forms echo back on every save.

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

* fix(resources): bound cover downloads and decodes

Remote covers, screenshots, manuals, badges and media files were streamed
to disk with no size limit, and a gzip-encoded body was read whole and
inflated in memory. Downloads now go through one helper that counts bytes
against MAX_ASSET_UPLOAD_SIZE_BYTES, inflates gzip incrementally under the
same cap, and aborts past it, so the partial file is removed and any
earlier copy kept.

Covers are also bounded once on disk: a still image whose header declares
more than MAX_COVER_PIXELS is discarded before it is decoded (and an
uploaded one is refused with a 400), and a DecompressionBombError while
deriving the small cover now discards the download instead of failing the
request and leaving the file behind.

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

* test: fix mypy errors in the new tests

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

* fix: address Greptile review on permission and input hardening

- Date OAuth tokens to before the credential check, so a password change
  that lands during the check revokes the tokens it issues.
- Apply ROM visibility to play sessions in SQL, before the page slice.
- Reject truncated gzip bodies and inflate every gzip member.
- Shorten the zip budget comment; stream real httpx2 responses in tests.

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

* fix: apply code-review findings on permission hardening

Revoke OAuth tokens and sessions on user deletion, apply ROM visibility to
GET /states/{id}, validate update_collection rom_ids, run get_rom_filters off
the event loop, and reuse the shared httpx client factory for webhooks.

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

* refactor: apply simplify pass on permission hardening

Read the OAuth revocation stamp through the async cache, share the
play-session batch-size check, raise a plain OSError for oversized downloads,
and drop a dead slice in the LZ4 decoder.

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

* style: apply review-polish pass on permission hardening

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

* docs: state that ROM visibility is enforced as access control

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

* fix(assets): hide saves, states, screenshots and memory cards on hidden ROMs

Visibility is access control, so per-id save/state/screenshot routes now 404
when the save's ROM is hidden from the caller (hidden ROM, hidden platform or
age limit), and the save/state lists and identifier lists leave those rows
out in SQL. GET /api/saves/summary 404s on a hidden ROM. Memory cards on a
hidden platform 404 on every per-id route, drop out of both lists, and can't
be created against a hidden platform.

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

* fix(saves): answer a hidden ROM's save summary like a missing one

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

* fix(permissions): enforce ROM visibility in sync, installs and feeds

Hidden ROMs/platforms and age-limited ROMs are access control, so the
paths that skipped the caller's visibility now apply it:

- sync negotiate: saves on hidden ROMs are neither offered, paired nor
  reported as conflicts; a client save on one negotiates like an unknown ROM
- push-pull SSH sync: resolves the device owner's visibility and skips
  saves on hidden ROMs in both directions
- device installs: list and claim leave out requests whose ROM became
  hidden (they stay pending), and outcome notifications don't name it
- recommendations: a hidden seed ROM is no longer named
- music playlists: track_count counts only tracks on visible ROMs
- audit events: firmware targets on hidden platforms are filtered
- setup library: supported platforms honour the caller's visibility
- feeds: a hidden platform found by slug reads as missing

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

* fix(visibility): hide ROMs from virtual collections, stats and scan events

Virtual collections apply the caller's visibility in SQL: a collection with
no visible member is left out (404 by id), member ids and covers skip hidden
ROMs, and the limit counts only visible collections.

Stats save, state and screenshot totals skip assets of hidden ROMs.

Scan events no longer broadcast to every socket. Progress and end events go
to a scan room that sockets of users holding platforms.write or tasks.run
join on connect. scanning_rom and scanning_platform go to the user rooms of
those followers who can see that ROM or platform, resolved once per scan
and grouped by visibility. get_rom_audience now builds on a shared
get_user_visibilities.

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

* fix: apply code-review findings on ROM visibility enforcement

Match virtual collection members by ROM id, build the cover visibility clauses
once, filter feed platforms by visibility in SQL, resolve every id before a
batch save or state delete, filter push-pull saves in the query, and narrow the
hides query to the requested users.

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

* refactor: apply simplify pass on ROM visibility enforcement

Require an explicit visibility filter on the saves, states and memory card
queries, share one roms_facets visibility join and one owned-asset helper,
filter virtual collection members by hidden ids, batch the scan audience's
scope lookup, and move the empty-room emit guard into socket_handler.

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

* test: start the scan audience before emitting from scan_rom

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

* docs: apply humanizer pass on the visibility rule

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

* fix(streaming): don't mount a memory card on a hidden platform

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

* fix: address Greptile review on ROM visibility enforcement

Refresh a running scan's audience after a permission change, fix the precedence
of the scan-room join assertion, and narrow mock await_args before reading them.

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

* revert: drop per-visibility scan event audience

Scan events go back to every socket. Removes handler/scan/audience.py,
the scan room join on connect, the permissions generation bump and the
batched OAuth scope resolution that only the audience used.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 14:33:11 -05:00
Georges-Antoine Assi
37e4ca304d fix: permission, validation and resource-limit hardening (#5496)
* fix(sync): cap play sessions on sync completion and require roms.user.write

The completion endpoint fed an unbounded play_sessions list to the same
ingest as POST /api/play-sessions, which allows 100 per batch and requires
roms.user.write. Apply both rules before the session is completed.

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

* fix(config): reject empty platform binding and version values

config.yml exits on load when a platforms or versions value is empty, so
the API must not write one.

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

* fix(collections): require smart collection criteria to be a JSON object

Any other JSON value was stored, then failed the response schema and broke
the smart collection list for every user who could see the collection.

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

* fix(stats): require roms.read on /api/stats

Anonymous callers were served counts over the whole library, including
platforms and ROMs hidden from users. The UI only calls it after login.

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

* fix(permissions): apply ROM visibility to filters, saves, play sessions and collection removal

/api/roms/filters aggregated facet values over the whole library, GET
/api/saves/{id} and GET /api/play-sessions returned the caller's own rows on
hidden ROMs, and removing ROMs from a collection could drop members hidden
from its owner. The facet visibility clauses move onto RomVisibilityFilter so
stats and filters share them.

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

* fix(webhooks): keep non-admin webhooks off the admin's internal metadata origins

The SSRF exception for a self-hosted Playmatch or Hasheous applied to every
request, so a user's webhook could reach any path on that private origin.
Non-admin webhooks now validate and connect with an empty allowlist.

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

* fix(saves): bound total decompressed size when hashing zip archives

Zip content hashing capped each entry but not the archive, so many
entries each under the cap could still decompress and hash far more
than any real save or memory card holds. Budget the decompressed bytes
across the whole archive and cap the entry count; callers keep treating
an over-budget archive as an unknown hash.

The chunked, budgeted entry reader is shared with the memory card
archive check, and the RetroArch store path now hashes off the event
loop like its siblings.

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

* fix(psp): clamp LZ4 literal and match copies to the ZISO block size

The ZISO block decoder appended literals and copied matches for their
full encoded length before checking the output size, and an LZ4 length
can be extended without bound by 0xFF bytes. A small crafted block
could therefore expand far past the block size before being truncated.

Clamp each copy to the room left in the block, stop once it is full,
end the block on a truncated match offset, and copy matches with slices
instead of a per-byte loop (overlapping matches repeat their pattern).
Output for valid blocks is unchanged.

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

* fix(auth): revoke OAuth tokens when a user's credentials change

A password change, admin reset, reset-link reset or rename cleared the
account's web sessions, but its OAuth access tokens kept working until they
expired and its refresh tokens could still be exchanged at /api/token.

Revoking a user's credentials now also records a per-username revocation
time in Redis, kept for the longest token lifetime. Bearer validation and
refresh consumption reject any token whose iat is at or before it. OAuth
tokens now carry a sub-second iat, so a login right after the change still
works; a token without iat counts as older than any revocation.

The revocation is keyed by the token's sub, the same username sessions are
keyed by, so a rename revokes tokens issued under the old name even if
another account later takes it. Client (API) tokens are left alone.

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

* fix(api): reject local file URLs for user-supplied covers and manuals

file:// and launchbox-file:// URLs are meant for covers and manuals that
a scan records from gamelist.xml or LaunchBox metadata. The collection
create/update endpoints and the ROM update endpoint passed a user-supplied
url_cover (and url_manual) straight to the resource handler, which copied
whatever library file it named into the entity's resources. That let any
user with collections.write or roms.write pull files they cannot otherwise
read, including those of hidden platforms and ROMs.

These endpoints now answer 400 for a local file URL, unless it is the value
already stored, which the edit forms echo back on every save.

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

* fix(resources): bound cover downloads and decodes

Remote covers, screenshots, manuals, badges and media files were streamed
to disk with no size limit, and a gzip-encoded body was read whole and
inflated in memory. Downloads now go through one helper that counts bytes
against MAX_ASSET_UPLOAD_SIZE_BYTES, inflates gzip incrementally under the
same cap, and aborts past it, so the partial file is removed and any
earlier copy kept.

Covers are also bounded once on disk: a still image whose header declares
more than MAX_COVER_PIXELS is discarded before it is decoded (and an
uploaded one is refused with a 400), and a DecompressionBombError while
deriving the small cover now discards the download instead of failing the
request and leaving the file behind.

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

* test: fix mypy errors in the new tests

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

* fix: address Greptile review on permission and input hardening

- Date OAuth tokens to before the credential check, so a password change
  that lands during the check revokes the tokens it issues.
- Apply ROM visibility to play sessions in SQL, before the page slice.
- Reject truncated gzip bodies and inflate every gzip member.
- Shorten the zip budget comment; stream real httpx2 responses in tests.

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

* fix: apply code-review findings on permission hardening

Revoke OAuth tokens and sessions on user deletion, apply ROM visibility to
GET /states/{id}, validate update_collection rom_ids, run get_rom_filters off
the event loop, and reuse the shared httpx client factory for webhooks.

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

* refactor: apply simplify pass on permission hardening

Read the OAuth revocation stamp through the async cache, share the
play-session batch-size check, raise a plain OSError for oversized downloads,
and drop a dead slice in the LZ4 decoder.

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

* style: apply review-polish pass on permission hardening

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

* fix(play-sessions): filter rom_id and device_id on PlaySession after the visibility join

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 11:39:30 -05:00
renovate[bot]
3224220a1f chore(deps): update dependency rq to v3 (#5493)
* chore(deps): update dependency rq to v3

* fix: adapt the RQ worker and job types to rq 3

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

* fix: update worker tests and task status map for rq 3

The worker tests pass the Execution to perform_job and patch the
module-level execute_failure_callback. TaskStatusItem covers the new
rate_limited and ready_to_enqueue statuses, shown as queued.

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

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Sam Dornan <sam.dornan@athleticgreens.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-05 10:39:35 -05:00
Georges-Antoine Assi
f66950551a fix(sync): bind device tokens to their device; dial only known push-pull hosts (#5460)
* fix(sync): bind device tokens to their device; dial only known push-pull hosts

A client token paired to one device could read, reconfigure, delete, sync
saves for and record play sessions as any other device of the same user.
Device CRUD, sync negotiate/complete, push-pull trigger, the save device
resolver and play-session ingest now treat another device as not found for
a bound token, through a shared require_token_device helper. GET /api/devices
lists only the bound device.

Push-pull let any user with devices.write point ssh_host at any host and
port, and the connection error surfaced through the sync session, so the
worker could be used to probe the internal network. The SSH handler now
refuses a host with no trusted key or CA in the admin's known_hosts before
dialling it, which keeps LAN handhelds working while nothing else is
reached.

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

* fix(device): revoke a deleted device's tokens; scope registration matches

Addresses Greptile review on #5460. Deleting a device now deletes the client
tokens paired to it, since the foreign key's SET NULL turned them into unbound
tokens that reach every device. Registration with a bound token only matches
its own device by fingerprint, so it can no longer reset syncs or overwrite
capabilities on another device.

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

* fix(sync): bind heartbeat, sync session and online reads; pin push-pull ports

pr-ready step 2 (code-review xhigh --fix).

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

* refactor(device): one require_device helper; parse known_hosts once

pr-ready step 3 (simplify).

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

* test(sync): narrow await_args before reading known_hosts

pr-ready step 4 (review-polish).

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

* docs(sync): plainer comments on the push-pull allowlist and token revoke

pr-ready step 5 (humanizer).

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

* fix(device): keep bound tokens off other tokens; cascade tokens with their device

A device-bound token can no longer create tokens, or regenerate, pair or
revoke a token of another device or an unbound one. The save session_id
counter only counts a session of the caller's bound device.

client_tokens.device_id now cascades on device delete (0159), so no path
can leave an unbound token behind, and deleting a device records a
client_token.revoke audit event for each token it takes.

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

* chore(env): drop the push-pull allowlist note from env.template

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 08:57:33 -05:00
renovate[bot]
77757301ba chore(deps): update backend dependencies (#5449)
* chore(deps): update backend dependencies

* fix: keep empty form values cleared under FastAPI 0.162

FastAPI 0.149 started parsing an empty form string as a missing field, so
the field's default (None) applied. Clients clear a user's email, a
collection's description or remote cover, and ROM fields by sending them
empty, and those updates were silently ignored. keep_empty_string restores
the submitted "" from the raw form.

The CSRF and session tampering tests set a cookie next to the one the
TestClient jar already held for the response domain; the client now sends
both and the original wins. Clear the jar first, as a browser would replace it.

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

* chore(deps): hold fastapi below 0.149

FastAPI 0.149 parses an empty value in a form model as a missing field, so
PUT /api/users/{id} with email="" kept the old address. Stay on 0.148 and
stop Renovate from proposing 0.149+ until the update endpoints can tell an
absent field from an empty one.

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

* chore(deps): hold fastapi at 0.146

FastAPI 0.147 started reading a missing bool field in a form model as
false, so PUT /api/users/{id} with only a role also disabled the account.
Keep the version master runs and cap Renovate below 0.147 until the update
endpoints tell absent, empty and false apart themselves.

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

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@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-11-02 11:29:49 -05:00
Georges-Antoine Assi
900fe515ea fix(sync): match RetroArch saves named after a ROM's files (#5445)
* fix(sync): match RetroArch saves named after a ROM's files

RetroArch names a save after the file it launched, so a disc or a
translation inside a multi-file game folder uploaded a save that matched
no ROM. When no ROM carries the name, saves now resolve to the ROM owning
a file with that stem. Those saves stay unslotted under their own name,
since a ROM's autosave lineage holds one save per core and the discs
would overwrite each other. States keep matching on the ROM name only,
because their slots are advertised under it.

Fixes #5364

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

* fix(sync): write a case-variant reupload to the stored save's own file

Addresses Greptile review on #5445.

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

* fix(sync): match a stored save's name in any case on PostgreSQL

The RetroArch save lookup relied on MariaDB's case-insensitive collation, so
on PostgreSQL a reupload in another case created a second save instead of
replacing the stored one.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 08:48:42 -05:00
Georges-Antoine Assi
3fc0740c02 fix(tasks): re-register RQ workers whose registration expired (#5443)
After a host suspend longer than the worker TTL, the worker key lapses and
the registry sweep drops the worker, or the next heartbeat recreates the key
with only last_heartbeat. register_birth() only runs at startup, so the scan
worker stayed invisible and every scan was refused with "No scan worker is
listening" until a restart.

RomMWorker.heartbeat() now checks the key still carries its queues and sits
in the worker registries, and writes the registration back when it does not.

Fixes #5327

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 07:55:43 -05:00
Sam Dornan
183ee3b89f feat(platforms): enrich discovery cards and preserve AVIF animations (#5433)
Fetch original launch years and current platform logos during scans, retain curated platform icons, and show launch year and type on responsive discovery cards. Preserve animated AVIF frames during thumbnail and WebP conversion.

Closes rommapp/romm#5432

Authored with Codex assistance, including implementation and tests.
2026-11-01 19:23:51 -06:00
Sam Dornan
4393b70973 feat(media): JPEG XL library images and cover uploads (#5438)
* feat(media): serve JPEG XL library images inline

Add .jxl to the image extensions the download endpoint serves inline,
with an explicit image/jxl type since mimetypes doesn't know it, and to
the frontend lists that pick artwork and folder screenshots out of
rom.files. AVIF was already covered; the new test pins both.

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

* feat(media): accept JPEG XL cover uploads through a Pillow plugin

Pillow 13 reads AVIF but not JPEG XL. pillow-jxl-plugin registers a
JXL codec with Pillow (imported once in utils/images, which the cover
and WebP-conversion code already load). It ships musllinux wheels for
the image's amd64 and arm64 builds.

ROM and collection artwork uploads now accept image/jxl and store it
re-encoded as PNG, since covers are served in their stored format and
not every browser renders JPEG XL. Avatars, stored as uploaded, keep
the PNG/JPEG/WebP/GIF allowlist.

The plugin is GPL-3.0, which is compatible with RomM's AGPL-3.0.

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

* test(roms): expect JPEG XL in the artwork rejection message

Artwork uploads now also accept JPEG XL, so the rejection message lists
it. The collection tests were updated with the change; this ROM one was
missed.

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

* fix(media): list library JPEG XL images only where the browser renders them

Library files are served as stored, and Chrome and Firefox render no
JPEG XL, so .jxl artwork and folder screenshots showed as broken tiles
there. A one-time probe decodes a 22-byte JPEG XL image and the artwork
and screenshot lists only include .jxl files once it succeeds (Safari),
updating reactively when the answer arrives. Chromium 153 fails the
probe, so the files stay hidden there as before.

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

* fix(media): size-check JPEG XL before decoding and keep it out of screenshot uploads

pillow-jxl decodes every pixel in _open(), before Pillow's
decompression-bomb check sees the size, so a small, highly compressed
JXL declaring a huge canvas could exhaust memory. utils/jxl reads the
width and height from the codestream SizeHeader (bare or inside a
container) and runs Pillow's own bomb check on them first, then
registers this guarded decoder in place of the plugin's.

The decoder raises RuntimeError on a corrupt file, which escaped
store_artwork as a 500. The guard turns it into SyntaxError, so Pillow
reports UnidentifiedImageError and the upload takes the same path as a
corrupt PNG.

POST /api/screenshots validated against the library inline list, so it
started accepting .jxl, but the asset endpoint serves those as
attachments. Screenshot uploads now use their own list without JPEG XL.

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

* style(media): one-sentence jxl docstring and a narrowed mock call in the JXL test

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

* style(media): one-sentence canRenderJxl doc comment

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:14:06 -06:00
Georges-Antoine Assi
2f2f6cd144 Merge remote-tracking branch 'origin/master' into fix/consistent-sibling-groups 2026-11-01 10:54:42 -05:00
Georges-Antoine Assi
f8ad3ad5b9 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>
2026-11-01 10:25:33 -05:00