Add v2 browser playback for .p8 and .p8.png cartridges, backed by the
FAKE-08 WebAssembly runtime, with canvas rendering, audio, fullscreen and
keyboard, gamepad, mouse and touch input. Wires up platform detection,
play actions, routing, localization, gallery navigation, play-session
tracking and lifecycle cleanup.
The runtime is fetched in the emulator stage of docker/Dockerfile, pinned
by source commit and verified with sha256, so it is provisioned the same
way as EmulatorJS, Ruffle and js-dos rather than committed to the repo.
DISABLE_PICO8 gates the player, matching the existing DISABLE_EMULATOR_JS,
DISABLE_RUFFLE_RS and DISABLE_JSDOS toggles.
Based on #4383.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The e2e job copied only the fixture library, not the config.yml declaring its
platform-folder-first layout, so the seeder scanned an empty library.
Reject `.` and `..` template sections: no directory listing yields either, so a
template carrying one discovered nothing and marked the platform's roms missing.
Drop the cached `full_path` when either half is set. A scan reads it and then
renames the file in place, which left the cached pair stale.
Point `build_physical_fs_name` at the index 0126 actually creates.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The docs link carries the grammar and the examples demonstrate it, so the prose
restating both goes. Thirteen comment lines become four.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rename `FirmwareTemplate.platform_path` to `firmware_dir`: it returns the
firmware folder, while the same name on `StructureTemplate` returns the platform
folder. Name the watcher's index for the segment it points at.
Fold the two reads of a raw structure key into `_raw_template`, and drop the
docstrings that only restated a one-line delegation or a signature.
Remove `footer-create-summary-default`, which no component references and whose
copy still named Structure A.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The banner and footer chips held either `roms/{platform}` or `{platform}/roms`
before, so their width was bounded. A configured template is not, and a nested
one overflowed its container at every viewport, clipping the path mid-segment.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`filesystem.structure` now spells out the whole layout rather than only the part
below a platform folder. A template is relative to the library root, `{platform}`
marks the platform folder, and `{game}` marks where a game begins.
Merge `{gameFile}` and `{gameDir}` into one `{game}` terminal. The information a
terminal carried was the depth, not the kind: at a declared level a file is a
game of its own and a folder is one multi-file game, which a stat answers. That
drops the two-template idiom for a level holding both, and `_discover_default_roms`
with it, since the default scan is now just `roms/{platform}/{game}`.
Retire the auto-detected `{platform}/roms` layout, along with
`filesystem.roms_folder` and `filesystem.firmware_folder`, which named one path
segment each that a template now contains. Both are refused at startup with the
template that reproduces the layout, so an instance that relied on either says so
instead of scanning an empty library and marking every rom missing. Firmware gets
its own `structure.firmware` key rather than following the rom layout implicitly.
`get_roms_fs_structure` keeps meaning the folder a platform's games start in, so
the `.physical` sentinel paths already in the database still resolve. Per-platform
overrides have to agree with `default` on where the platform folder sits;
relocating one platform needs platform discovery and the watcher to union several
roots, which is left out.
The setup wizard reports `library_ready` plus the configured template instead of
a `struct_a`/`struct_b` discriminator, so the banner shows the layout in force
rather than guessing it client-side.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Testing the custom library structure against a live library turned up four
defects, all of them a path being reduced to a bare file name.
Both exporters wrote a rom's `fs_name` alone, so every game a template nests
was exported as if it sat in the platform folder: ES-DE and Pegasus could not
find any of them. They now write the rom's path relative to the platform
folder, the folder the metadata files themselves live in, and copy exported
media into the matching subfolder so two identically named roms keep their own
artwork.
Merging into an existing gamelist.xml / metadata.pegasus.txt keyed entries by
file name too, so identically named roms in different folders both merged into
the first entry and produced duplicates. Entries are now keyed by path, with a
Pegasus block matched by the folder its listed files sit in.
Reading a gamelist.xml had the same collision: two roms sharing a file name
both took the metadata of whichever entry was parsed last. A rom's own path now
wins, and a bare file name stays a fallback key for the tools that write those,
dropped when two entries share it.
Default discovery surfaced hidden folders as multi-file games, unlike
structured discovery which skips them. exclude_multi_roms now owns that rule
for both.
Also validate `exclude`'s exclusion_type: an unknown value reached
`Config.__getattribute__` and returned a 500 rather than a 422.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Each worker started with --with-scheduler forks a scheduler that logs
"Scheduler sending heartbeat to <queues>" on every 1s tick. With
LOGLEVEL=DEBUG that is two lines per second, which drowns out the rest of
the log.
Generalize the existing registry-cleanup filter to cover RQ's periodic
noise and install it on the rq.scheduler logger before the worker forks
the scheduler off.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The comment block explaining `filesystem.structure` had grown to 45 lines of
prose in an example config. Keep the syntax essentials and the examples, and
point at the docs page for the rest.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Cut the comments that explain rather than note: the migration's four-paragraph
docstring, the upload-path and digest-SQL docstrings, and the mark-missing note
in the scan loop. Drop an em-dash from LocationChip's header per CLAUDE.md.
Reword 0126's downgrade error so it no longer embeds a SELECT, which bandit
reads as string-built SQL, and mark the dialect-selected backfill nosec B608 the
way the other migrations do.
Add the LocationChip test its HashChip sibling already had, covering the copy
going through useClipboard (the composable is what applies the secure-context
guard).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Key the unique roms index on a sha256 digest of the full path. Indexing
(platform_id, fs_path, fs_name) directly is 5804 bytes of utf8mb4, which MySQL
rejects with ER_TOO_LONG_KEY and MariaDB silently demotes to a hash index; the
digest column keeps it a 260-byte BTREE on every supported driver. It is derived
by the same @validates hook that maintains the other fs_name columns, and
resynced explicitly in update_rom and convert_rom_to_folder.
Migration 0126 backfills the digest in one dialect-branched UPDATE. A Python
executemany right after the ADD COLUMN silently applies only its first parameter
set on mariadb-connector, leaving the rest NULL. test_migrations pins the SQL
expression to compute_full_path_hash so the two cannot drift.
Drop the relocation pre-pass. mark_missing_roms already runs before the identify
loop, so a moved file reaches get_matching_missing_rom, which requires all three
hashes to agree (or a title_id, covering non-hashable platforms), refuses
ambiguous matches, re-parses filename tags and emits over the socket. The
pre-pass duplicated it with a weaker CRC-only check, hashed every candidate
twice, compared folder sizes against a total that excludes filtered files, and
ran on QUICK scans.
Send uploads to a folder the platform's structure will actually discover, so the
next scan does not flag a fresh upload as missing, and refuse with a 400 when
only the user can pick the folder.
Make 0126's downgrade refuse when duplicate file names exist instead of deleting
the roms (and their saves, notes and collection membership) that carry them.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`LibraryStructure` named two unrelated things: the A/B enum for which of
RomM's two folder layouts a library uses, and this branch's parsed
per-platform template. Both were imported into handler/filesystem.
The parsed template is now `StructureTemplate`, with `parse_library_structure`
and `parse_platform_structures` following it to `parse_structure_template` and
`parse_platform_templates`. `LibraryStructure` again refers only to the enum.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`system.platforms` lowercases its folder-name keys so lookups ignore case,
but `filesystem.structure` matched `fs_slug` exactly. A folder written the
same way in both blocks (`Atari - 2600`) bound its platform correctly while
its structure template silently did not apply.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A grouping folder is no longer also a game. With `{gameDir}` and
`{category}/{gameFile}` declared together, the category folder was surfaced
as a multi-file game *and* descended into, listing its contents twice. A
folder any template descends into is now treated as a grouping level.
Relocation runs for every platform, not only those with a custom structure.
Dropping a platform's template moves every game back to the platform root,
which previously read as a library of new games and orphaned all the saves,
play history, favorites and collection membership. A library whose paths are
unchanged still costs one query and no hashing. This also removes the need
for a manual "apply relocation" toggle.
Physical games are excluded from relocation candidates: they have no file, so
they read as having disappeared from their path on every scan.
A near-miss on the terminal macro (`{gameFolder}` for `{gameDir}`) now names
the offending section instead of only reporting a missing terminal.
Documents two limits the QA pass asked about: a move that also compresses or
extracts the game changes its size and is not detected (the size pre-filter
runs before hashing), and how reverting to the default layout behaves.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Conflict resolution notes:
- Locale rom.json: master sorted and reworked every file; took master's and
re-inserted `location` / `location-copied` in sorted position. Added them to
the new tr_TR locale.
- FSRom gained a required `fs_path`, so `build_hashless_fs_rom` now takes one
and both call sites pass the rom's own path.
- `get_roms` keeps this branch's `_collect_fs_roms` discovery while adopting
master's one-pass build and in-place sort.
- `mark_missing_roms` takes full paths and now also excludes physical games
(master), and the scan loop keeps master's early missing-sync plus its
restored-rom emit alongside this branch's relocation pass. The relocation
filter now applies only to the identify loop, so a relocated rom is no longer
re-flagged missing at the end of the scan.
- Relocation writes rom files through master's `sync_rom_files` (which replaced
`purge_rom_files` / `add_rom_file`), so row ids and track metadata survive.
- Master's unique index on (platform_id, fs_name) contradicts this branch's
premise that same-named files in different folders are distinct games.
Migration 0126 widens it to (platform_id, fs_path, fs_name); physical games
all share one folder, so a duplicate title is still rejected.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The genre/franchise/company/publisher/developer/collection/age-rating/
player-count filters read from `roms_metadata`, but the join was added at the
end of `filter_roms`, after the "Group ROMs" block had already derived its
dedup window from the query. The window therefore filtered on a table it never
joined: the database cross-joined `roms` against `roms_metadata` (a view over
`roms`), which SQLAlchemy reports as a cartesian product.
Besides the cost, the window then ranked every ROM in the library rather than
the matching ones, so a game whose matching version was not the group's primary
one disappeared from the gallery entirely.
Fixes#4389
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Hashing 1.96 GiB of real ROM files is 2.2x faster at 4 concurrent
workers than at 1 (108 -> 240 MiB/s on 16 cores, 108 -> 264 MiB/s
pinned to 4 cores). Pinned to 2 cores it is still 1.6x, so the new
default costs nothing on small hosts.
Metadata providers cap themselves independently of this value, so the
extra workers queue rather than exceed an allowance: ScreenScraper holds
a concurrency limiter set to the account's advertised thread count, and
the other adapters pace their own request rate. Database work in the
scan path is synchronous on the event loop, so it serializes regardless
and the connection pool is unaffected.
The compose example advised one worker per CPU, which overshoots on a
large host. Both it and env.template now say what raising this actually
buys, since metadata is paced no matter how many workers there are.
Only installs that never set SCAN_WORKERS move; any explicit value is
preserved.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Hashing runs in threads via asyncio.to_thread, and hashlib/zlib release
the GIL per chunk. At 8 KiB the threads hand the GIL back so often that
concurrent scans contend rather than overlap, which capped scan
concurrency and made high worker counts actively harmful.
Hashing 1.96 GiB of real ROM files at 8 workers goes from 154 MiB/s to
666 MiB/s (4.3x). Single-worker throughput is unchanged (108 vs 114
MiB/s), so this is not read-syscall overhead; it only bites under
concurrency. 256 KiB is the knee, 1 MiB measured no better.
The chunk bounds a streaming read, so peak memory is one chunk per
in-flight file, a few MiB at any realistic worker count.
Digests are unaffected: all 67 files in the test library produce
byte-identical crc/md5/sha1 at 8 KiB, 64 KiB, 256 KiB and 1 MiB.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Cut the docstrings back to the one paragraph the surrounding migrations use,
and drop the comments that restate the index name next to them.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ix_memory_card_versions_card and ix_devices_user_id are leftmost prefixes of a
wider index on the same table, the shape 0125 exists to remove, so move them
there rather than declaring them on the models.
Also replace the deprecated version_path_separator that path_separator was
added alongside, and cut the migration and model comments that restate each
other or explain the change rather than the schema.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The list covered firmware and the music tables but not saves.user_id,
states.user_id, screenshots.user_id, rom_file_user.user_id,
memory_cards.platform_id or streaming_container_adoptions.decided_by_user_id,
so a user delete still sequentially scanned the three largest per-user tables
on PostgreSQL, which is the case the pass set out to fix.
Add a test that recomputes the rule (a single-column foreign key whose column
leads no index, primary key or unique constraint) from the model metadata, so
the next model foreign key cannot be forgotten silently.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
env.py listed the model modules by hand so autogenerate would see them, and
this branch had already had to patch six omissions into that list. Walk the
package instead, from a helper the index-drift test can share.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A single worker was the reason a lone user loading a gallery measured
6.474 s worst-case TTFB against 1.939 s at 4 workers. The multi-worker
path is already supported: the log forwarder takes a Redis lock so
exactly one worker relays.
Only installs that never set WEB_SERVER_CONCURRENCY move; any explicit
value is preserved.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
"2 x CPU cores + 1" is gunicorn's guidance for sync workers. RomM runs
UvicornWorker with sync endpoints served from Starlette's threadpool, so
the rule does not transfer: on a 16-core host it measured 3x slower than
4 workers and cost 5.31 GB PSS.
The variable also only reaches the gunicorn API server; background tasks
run in the separate RQ worker processes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change detection needs equality, not a fingerprint, and the hash was the
only reason the tick handler was async. Comparing bytes drops the WebCrypto
call, its non-secure-context fallback, and both mid-flight liveness checks
the awaits had made necessary: the decision now runs before the upload with
nothing suspended in between.
Seeding reads the SRAM with getSaveFile(false), which skips the dump that
was firing a saveSaveFiles tick, so the subscription no longer has to be
ordered below it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The active flag and the install slot both said "this component still owns
the subscription", so the slot alone now carries it.
fnv1a64's second lane re-hashed the same bytes offset by one with the same
prime, leaving the halves correlated; distinct primes over a single load
drop the per-byte modulo too.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A tick that is mid-hash when Exit or Save & Quit closes the gate would
still issue its own upload and race theirs. Teardown during the seed
likewise re-armed the gate and subscribed to a dead emulator.
displayMessage now tolerates a torn-down emulator for all of its callers.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
EmulatorJS exposes no `off`, so a second EJS_onGameStart against one live
emulator would leave two handlers with independent trackers uploading the
same tick.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The comparison read whatever `BaseModel.metadata` happened to hold, which is
populated as a side effect of `tests/conftest.py` importing fourteen model
modules for its `clear_database` fixture. A table missing from the metadata
makes `compare_metadata` report every one of its indexes as removed, so the
test's result depended on imports that exist for an unrelated reason: shrink
that fixture and the test starts reporting drift that isn't there.
It now walks `models/` and imports every module itself, so a newly added
model is covered without anyone remembering to, and asserts up front that no
database table is missing from the metadata. Without that guard an incomplete
metadata is indistinguishable from real drift in the failure output.
Verified standalone and in the full suite on PostgreSQL 16 and MariaDB 11.4;
the guard exempts `alembic_version`, which has no model.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WgeQBXh6SJyxXVHSL5EuoF
`play_sessions.device_id` and `play_sessions.sync_session_id` were left out of
the PostgreSQL foreign-key list, which is inconsistent with the criterion 0124
states for itself: a column queried directly or walked by `ON DELETE` needs a
real index there. Every other index on the table leads with `user_id`, so
`device_id` is only ever a second column and `sync_session_id` appeared in no
index at all. Both are `ON DELETE SET NULL`, so deleting a device or a sync
session made PostgreSQL scan the whole table.
That scan grows with every session played. On a 60k-row table with 1200 rows
pointing at one device, the row lookup behind the SET NULL goes from a 7.6ms
sequential scan to a 0.14ms index probe, taking the statement from 53ms to
38ms; the remainder is row rewriting no index avoids.
The `device_id` query filter in `get_existing_session_keys` is already served
by `uq_play_session_identity`, since it leads with `user_id` too, so this is
about the delete path rather than that lookup.
MariaDB is unaffected: InnoDB already created implicit indexes on all three
columns, which is why these are dialect-gated.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WgeQBXh6SJyxXVHSL5EuoF
`trunk_check` reported `backend/utils/database.py` as unformatted. Adding the
index constants pulled the file into trunk's modified-file scope, which
surfaced a formatting deviation that predates this branch: black 26.5.1 drops
the redundant parentheses from an `except` tuple, which PEP 758 makes valid
syntax on the Python 3.14 this project requires. Three `except` clauses in
otherwise untouched helpers change as a result; the file cannot pass
`trunk fmt` without them.
Also collapses the AUTOGENERATE_EXEMPT_INDEX_NAMES assignment onto one line,
which is the same formatter's doing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WgeQBXh6SJyxXVHSL5EuoF