43 Commits

Author SHA1 Message Date
Spinnich
60703be09c chore(platforms): split arcade aliases into per-emulator-family slugs (#5273)
* feat(platforms): split arcade aliases into per-emulator-family slugs

Give MAME, AdvanceMAME, FBNeo, FBA, Daphne, Singe and the arcade boards
that need their own emulator (NAOMI/NAOMI 2/NAOMI GD-ROM, Model 2/3,
Hikaru, Triforce, Lindbergh, Namco System 246/3xx, Gaelco, ...) their own
slugs with verified provider IDs. Providers without a dedicated entry fall
back to their Arcade platform via arcade_fallbacks(). MAME-only boards
(CPS1-3, System 16/32, Model 1, Namco 22) stay aliases of arcade.

Refs #5272

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

* fix(platforms): code-review pass on arcade slugs

- Retry IGDB on unmatched scans for every platform IGDB resolves, not
  just slugs in IGDB_PLATFORM_LIST.
- Resolve config binding/version values through the alias table, so a
  binding to a retired slug (cps2, model1, ...) still lands on a platform.
- Alias the Batocera `typex` folder to type-x.
- Build provider id->slug reverse maps before merging Arcade fallbacks.
- Share one MAME title lookup between base_handler and libretro.

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

* refactor(platforms): simplify pass on arcade slugs

- Alias the three RomM-keyed IGDB versions inside IGDB_PLATFORM_VERSIONS,
  dropping IGDB_VERSION_SLUGS and _version_slug.
- Derive EmulatorJS arcade entries from ARCADE_SET_PLATFORMS.
- Remove the unused provider id->slug reverse maps, so the Arcade
  fallback merge no longer has an ordering constraint.

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

* docs(platforms): humanizer pass on arcade slug comments

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

* fix(platforms): settle arcade slug review decisions

- Migration 0154 moves platforms still on a retired MAME-only board slug
  (cps1-3, model1, system16, system32, system-32) to arcade, so no row
  carries a slug the enum no longer has.
- MAME shortname expansion keys off the RomM slug via
  MAME_SHORTNAME_PLATFORMS instead of per-provider arcade ids, so Daphne,
  Singe, Type X and Lindbergh sets are no longer read as MAME sets. Neo Geo
  now expands at ScreenScraper too, as it already did at IGDB and Moby.
- fba offers fbneo before the FinalBurn Alpha CPS cores.
- AdvanceMAME leaves the WebRcade feed; EmulatorJS and WebRcade share
  PLAYABLE_ARCADE_SET_PLATFORMS.

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

* fix(platforms): code-review pass (xhigh) on arcade slugs

Verify arcade-board BIOS files against the known list's arcade entries,
and make migration 0154 match retired slugs case-insensitively.

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

* refactor(platforms): simplify pass on arcade slugs

Apply IGDB family overrides once in get_platform instead of on each
return path.

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

* test(platforms): use a slug with no shipped icon

singe now ships an icon, so the no-icon prefetch test needs a slug that never will.

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

* feat(platforms): add a teknoparrot arcade slug

TeknoParrot runs PC-based arcade boards outside the MAME/FinalBurn family,
so its folder gets its own platform (RetroBat and ES-DE both use
`teknoparrot`). Providers fall back to their Arcade entry, MAME shortname
expansion skips it, and it gets a placeholder icon copied from `arcade`.

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

* feat(platforms): give each arcade-family icon its own marquee title

Redraws the ARCADE marquee on the copied cabinet icons with each
platform's name, in the Bungee typeface with the original inline and
extrusion styling. Sega boards use Sega blue, Namco systems Namco red,
and Type X Taito blue; the rest keep the original amber.

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

* fix(platforms): code-review pass (xhigh) on arcade slugs

Neo Geo BIOS lives under arcade in the known BIOS list, so map
neogeoaes and neogeomvs there too.

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

* refactor(platforms): simplify pass on arcade slug tests

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-10-28 19:53:06 -04:00
Zach Clendenen
a5b3054270 fix(streaming): let a container's broker_secret override STREAMING_BROKER_SECRET (#5259)
* fix(streaming): let a container's broker_secret override STREAMING_BROKER_SECRET

STREAMING_BROKER_SECRET replaced every container's broker_secret, so a pool
of containers with different BROKER_SECRETs could not authenticate: each
broker after the first answered 403 "bad broker secret". A container's own
broker_secret now wins, and the env var is the fallback for containers that
set none. A blank broker_secret also falls back instead of becoming the
literal secret "None".

* test(streaming): cover a blank broker_secret with no env secret

Addresses Greptile review on #5259: the fallback cases all set the env
secret, so none pinned that YAML null no longer becomes the secret "None".

* Update examples/config.example.yml

---------

Co-authored-by: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com>
2026-10-28 12:16:30 -04:00
Claude
258b87de0d fix: satisfy mypy and isort, and trim comments
The reaper test now reads HOLD_CEILING_SECONDS from handler.streaming.config,
where it is defined. Merges the duplicate handler.auth.base_handler imports
the rewrite left in two test files, and shortens the comments on the hold
ceiling, the LaunchBox spec and the registry module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gh1SRMfuK7BZmf6YxMqSyT
2026-10-01 01:44:09 +00:00
Claude
1e6dd1a2ac perf: keep task code out of the cron scheduler and idle RQ workers
The registry imported every task module to read each task's title,
schedule, queue and timeout, so `rq cron` and every RQ worker parent
loaded the whole app. Task metadata now lives in the registry as
`TaskSpec`s with a dotted path to the implementation, which `get_task`
imports only when a job runs. Cron, the tasks API, enqueueing and the
worker's failure reporting read specs only.

Every log line also imported handler.metadata.base_handler, and with
it every metadata provider, for the redaction regex. The sensitive keys
and their regex now live in logger.formatter.

A test pins that importing the cron config or the worker class loads
neither handler.database, the auth handlers nor fastapi.

Measured RSS at LOGLEVEL=INFO, master -> this branch:
- rq cron: 164 MB -> 72 MB
- idle RQ worker (x3): 133 MB -> 68 MB
- gunicorn web worker: 214 MB -> 206 MB

Each job's work horse now imports its task module itself, 0.1-0.5s
more per job on an x86 host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gh1SRMfuK7BZmf6YxMqSyT
2026-10-01 01:32:21 +00:00
Zach Clendenen
3fbb746ded test(streaming): review-polish pass, assert the core reaches the tier warning 2026-09-27 14:44:09 -05:00
Zach Clendenen
8336f127b6 refactor(streaming): simplify pass on the RetroArch core override 2026-09-27 14:39:13 -05:00
Zach Clendenen
2d25618ee2 fix(streaming): code-review pass on the RetroArch core override 2026-09-27 14:29:47 -05:00
Zach Clendenen
cd813caeba fix(streaming): tighten core override edge cases from review 2026-09-27 09:49:31 -05:00
Zach Clendenen
cdf2aba0da feat(streaming): per-platform RetroArch core in the streaming config 2026-09-27 09:49:01 -05:00
Zach Clendenen
e2305e09e0 fix(streaming): address Greptile review on #4796
- A label longer than the request limit no longer becomes a container's
  name, so every published name is one the desktop endpoint accepts. The
  limit moves to handler.streaming.config as CONTAINER_NAME_MAX_LENGTH.
- A label equal to another container's key in any case no longer names
  its container, matching the case-insensitive lookup.
- An oversized broker manifest now fails the import build instead of
  being dropped, which lost the state typing of the base's entries.
- A broker error body is read against a 5 second deadline, like every
  other broker read.
- Type the _labelled test helper.
2026-09-25 22:12:50 -05:00
Zach Clendenen
9ade9dfdb8 simplify(pr-ready step 3): collapse duplicated branches and dead code
- config: one _keys_by_label grouping serves both the unique-label map
  and the shared-label warning.
- claim_session: one abort-and-raise for either refused pick; the
  newest-save lookup is a single conditional expression.
- launch: pick refusal fields off one optional ImportRefusedError.
- imports: skip_state is always true for a foreign save archive; drop an
  unreachable KeyError and the unused str form of _read_member.
- webstation: ImportSpec.state_channel is a Literal.
- Stream.vue: the 400 refusal hint folds into the generic server branch;
  pickableStates drops a guard nativeStreamStates already has.
2026-09-25 19:20:30 -05:00
Zach Clendenen
cf4353e9e2 Merge branch 'feature/streaming-container-names' into streaming-patches-8
# Conflicts:
#	backend/endpoints/streaming.py
#	backend/handler/streaming/config.py
2026-09-25 18:04:31 -05:00
Zach Clendenen
6e491beeda feat(streaming): name containers by their own label when it is unique 2026-09-25 15:18:02 -05:00
Georges-Antoine Assi
22aa445d27 fix(streaming): hold the reaper off for a stale window after a restart, schedule it only with streaming on, and warn about later pools once across processes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 09:29:48 -04:00
Georges-Antoine Assi
ffdbe79032 Merge remote-tracking branch 'origin/master' into streaming-patches-5
Port the branch's emulator labels and live-state flag onto master's typed
streaming schemas, and carry the labelled state reason into
useSaveStateTabs now that the EmulatorJS view delegates to it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:37:10 -04:00
Georges-Antoine Assi
93681f459c Merge pull request #4596 from LoneAngelFayt/streaming-patches-4
fix(streaming): put every container in a pool, and reach later pools by key
2026-09-22 08:09:52 -04:00
Sam Dornan
4ffc7c5ce1 style: apply the formatting requires-python already implies (#4638) 2026-09-19 12:33:45 -04:00
Zach Clendenen
6464325a1f fix(streaming): hide the in-game Save and Load buttons for DuckStation and RPCS3, which only write a state on exit 2026-09-19 07:21:52 -05:00
Zach Clendenen
19793bd3f2 fix(streaming): resolve DuckStation and RPCS3 exit states and resume them from the save archive instead of pushing a state file 2026-09-18 22:36:33 -05:00
Zach Clendenen
11eabe6431 docs(streaming): fit the branch's comments and docstrings in two lines
The repo caps a comment at two lines and a docstring at one sentence plus Args and Returns. Several comments and docstrings this branch wrote or edited ran to three lines or more, so they are tightened, with parameter notes moved under Args.
2026-09-18 12:03:10 -05:00
Zach Clendenen
157df721c6 refactor(streaming): list /config rows from the pools a claim walks
The config endpoint re-derived the key filter and case-insensitive platform grouping that the pool helpers own, so the Play button row and the claim could drift apart. It now reads the first container of each platform's first pool from the same helper.
2026-09-18 11:28:03 -05:00
Zach Clendenen
4f2d1198f2 docs(streaming): tighten the comments this branch grew
Several notes had run to four or more lines, a couple of them recounting
how the code was reordered rather than what it does now.
2026-09-17 16:59:38 -05:00
Zach Clendenen
85079be5c5 fix(streaming): name RetroArch in the emulator labels
The labels map covers the ids a surface is handed rather than resolves,
and a save written under RetroArch carries "retroarch". With no entry
the asset chip showed the bare id.
2026-09-17 16:50:31 -05:00
Zach Clendenen
5021ef2fa0 fix(streaming): label the Play! emulator and the asset chips
Play! served PS2 sessions under the raw id "play", since it was missing from
the emulator display names, and the save and state chips showed whatever id
the broker recorded because the names never reached the frontend.

/config now ships the display names, and the chips and core group heads label
an id through them, falling back to the id for one the backend does not name.
2026-09-17 16:09:13 -05:00
Zach Clendenen
c2e599439f fix(streaming): answer with the container a claim would win
/config listed containers with no key, so a platform whose only container is
misconfigured showed a Play button that could never stream, and it listed a
platform twice when two records spelled it in different case.

configured_emulator read the first record in the file rather than the first
member of the platform's pool, so the slot ceilings a save or load is checked
against could come from an emulator no claim ever reaches.
2026-09-17 15:28:42 -05:00
Zach Clendenen
08f1e0001e simplify(pr-ready step 3): group dialable containers per platform in one place, point the claim comment at interchangeable_with 2026-09-17 11:46:22 -05:00
Zach Clendenen
9c1e9f4d75 fix(streaming): put every container in a pool, claim from the first
A platform's containers are now grouped into pools of interchangeable
members (same emulator, memory card sync, save picker and protocol), so a
lone container is a pool of one instead of a skipped non-member. Game claims,
status, heartbeats and joins still walk only the first pool, which matches
the containers they reached before.

The "not a pool member" warning fired on every lookup, one container at a
time. It now fires once per config and names every container a game claim
can never reach. Named lookups (desktop, admin release, named heartbeat)
already reach a container in any pool.
2026-09-17 11:42:18 -05:00
Zach Clendenen
e2e35835db simplify(pr-ready step 3): run a named heartbeat through the pool's lookup, reuse the store heartbeat and entry_for_platform
A named container is a one-entry candidate list, so the heartbeat has one lookup
and one status answer instead of a closure branching on the key, and it no longer
reads the session twice. The desktop view beats through the store wrapper, and
configured_emulator shares the platform match.
2026-09-17 09:41:31 -05:00
Zach Clendenen
bdd661d30a simplify(pr-ready step 3): share the per-platform entry lookup, build the state line in one place
entry_for_platform backs both container_for_session and
resolve_named_container, and the fleet row's state line is assembled in
sessionState instead of split across template blocks.
2026-09-17 08:14:41 -05:00
Zach Clendenen
4e327fd72e simplify(pr-ready step 3): cut the clears_stale_saves comments to the why
Each of them had grown a paragraph explaining where the broker flag lives
and when to reach for it, which the config example already covers.
2026-09-15 23:33:39 -05:00
Zach Clendenen
9cef7f2f29 review(pr-ready step 2): pool on the picker capability, not the raw flag
Two legacy broker containers serving the same emulator stopped pooling when
one carried a clears_stale_saves the resolver had just logged as having no
effect. Comparing supports_save_picker folds in the webstation gate, so it
is the same test for a webstation pair and inert for the rest.
2026-09-15 23:31:52 -05:00
Zach Clendenen
5e217c7f64 feat(streaming): let an operator declare whether their broker clears saves
The save picker was gated on a hardcoded set of emulators mirroring the
webstation broker's `clears_stale_saves`, a value that lives in another
repo. A broker release that turns it on for a new emulator needed a RomM
code change before the picker appeared, and an operator on a fork or a
newer broker could not turn it on at all. The other direction was worse
because it was silent: if the broker stopped clearing, the pick still
validated, the archive still uploaded, and the container's own newer
files overwrote it with no error anywhere.

`clears_stale_saves` now joins `memory_card_sync` in
PLATFORM_OVERRIDE_KEYS, resolved per container in `_resolve_one`, which
leaves the emulator table as the default rather than the authority. It
also joins the pool-interchangeability check, since the picker is
advertised from the head of the pool and a member that keeps its own
files would take the pick and discard it.
2026-09-15 23:22:27 -05:00
Zach Clendenen
f58a7ad7e0 polish(pr-ready step 4): trim the comments and name the resolve helper for its answer
Cut the docstrings and comments this branch added down to the one non-obvious
fact each, in the resolver and in the tests alike, and rename the new helper to
_claimable_broker_host so it says what it returns next to _derive_broker_host.
2026-09-15 17:09:59 -05:00
Zach Clendenen
1b3caebabf simplify(pr-ready step 3): flatten the container resolve and compare protocols by name
Move the three ways a raw entry fails to resolve into one helper with a guard
clause each, so none of them has to unset a broker host a sibling branch set.

The subfolder match moves onto WebstationProtocol, next to the normalization it
has to agree with, and interchangeable_with compares protocol names, the
discriminator the record already uses elsewhere.
2026-09-15 17:05:08 -05:00
Zach Clendenen
9a4b644c01 review(pr-ready step 2): let a player reclaim their own stale container
The holder gate added with the pool ran before the stale-takeover walk, so a
player whose tab crashed was refused their own container until its TTL lapsed.
Block only on a live holder, and when the holder's own session is stale narrow
the candidates to that container so the existing takeover path reclaims it.

Also widen the proxy path check to compare the host's URL path, so a container
on another origin mounted at a path that disagrees with its subfolder is
refused the same way a bare path already was.
2026-09-15 16:57:37 -05:00
Zach Clendenen
df6ded2786 fix(streaming): refuse a proxied container whose host and subfolder disagree
A same-origin entry sends the browser to `host`, but activate answers with
the room URL the broker built from its own SUBFOLDER, and that is an
absolute path, so urljoin lets it replace the path `host` carries. The two
values are therefore not independent: both have to be the container's own
SUBFOLDER.

Get them wrong and nothing complains. A container mounted at /streaming-2
while declaring /streaming resolves, claims its own key, and hands the
player a URL the proxy routes to whoever owns /streaming: a different
container, mid-session, with no trace of it in either log. The likeliest
way in is a second pool member proxied at its own path with `subfolder`
left to its default.

Resolve the entry, log it, and clear broker_host so it cannot be claimed,
matching how the other unusable configurations are handled. It stays in
the fleet view, where the operator can see what is wrong with it. A full
URL `host` is untouched; it carries an origin of its own for that absolute
path to land on, so there the two are free to differ.
2026-09-15 13:30:34 -05:00
Zach Clendenen
50027b64ed fix(streaming): pool same-origin webstation containers across subfolders
interchangeable_with() compared protocol by instance identity, and
WebstationProtocol is interned per exact subfolder — so two containers
proxied at different subfolders, the normal way to run a same-origin
pool, were never recognized as pool members. Compare by type instead;
capabilities are class-level constants, so type equality is what
"same shape" actually means.
2026-09-15 12:49:08 -05:00
Zach Clendenen
fb0b389adb style(streaming): trim the save-picker comments to the facts
review-polish pass over the save-picker change.

The comments explaining why an older pick only lands where the broker clears
the save tree said the same thing in four places, so each one now carries only
what its own reader cannot get from the code. The save fixture in the launch
screen test becomes a typed factory, which the emulator-scoping case it did not
cover yet now uses.
2026-09-14 03:02:03 -05:00
Zach Clendenen
107d797292 feat(streaming): let the launch screen pick which save to restore
Containers whose broker clears the save tree before restoring can land an
archive older than the container's own files, so offer the pick there and
validate it at claim time.
2026-09-13 23:57:21 -05:00
Georges-Antoine Assi
7443b690be fix(streaming): keep the container's answers inside its own origin
A broker's launch, join and desktop replies name the URL the browser loads
in an iframe, and urljoin keeps an absolute (or `javascript:`) URL verbatim,
so a container that answered with one could run script in RomM's origin
instead of its own. The three sites now share one resolver that drops a room
URL leaving the configured host, the stage refuses a source that is not
http(s), and the frame is sandboxed without allow-top-navigation so a
container page cannot steer the tab it sits in.

Also drop the shared secret from the config entry a resolution warning
prints, which named the misconfigured container by dumping it whole.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:53:43 -04:00
Georges-Antoine Assi
e85fce8e80 fix(streaming): close the holes a review pass found
Session ownership and lifecycle, mostly around who a teardown belongs to:

- file the exit state, save states and state frames under the session's
  owner rather than the caller, so an admin driving someone else's session
  no longer collects their saves
- beat the heartbeat from the admin desktop view, which the stale sweep was
  tearing down three minutes in
- take the claim through release_own_session when a launch aborts, instead
  of deleting a key another player may already hold
- require the same claim to stamp a launch, so a late activate cannot revive
  a drain marker with a six hour TTL
- pull the in-game save archive on every teardown path, not just the two
  that remembered to
- skip draining keys in the admin force-release sweep

Plus: pool members must share a protocol, since the head's capabilities are
what the frontend renders; a claim clears terminations across the whole pool;
multiplayer is only recorded where the broker can actually seat a joiner; and
an unserializable config no longer caches forever on a repr() that repeats.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:33:44 -04:00
Georges-Antoine Assi
eccafd13d1 refactor(streaming): polish pass over the new modules
- The five new modules each defined `log = logging.getLogger("romm")`, which is
  what `logger.logger` already exports; they import it now.
- `ACK_TIMEOUT` had two homes. It is a protocol fact, so `protocol.py` owns it
  and the endpoint imports it from there; the unused
  `BROKER_LOAD_STATE_TIMEOUT` copy goes.
- Module and function docstrings trimmed to what the code cannot say: the
  change history and the justifications belong in the commit messages they came
  from.
- `asset_store` takes the union `write_file` accepts rather than `Any`.
- Four hand-rolled `setInterval` pairs (presence beat, session poll, exit
  chord, live sessions, activity tick) become `useIntervalFn`, which also
  cleared a real gap: the presence composable's timer had no scope teardown.
- The launch pushes are matched on the container the claim's 202 named, not on
  the platform: a pool serves one platform from more than one container, so a
  second tab could otherwise act on the first's launch.
- Test helpers typed: the push capture and the resume-claim tuple carry real
  types, and an unused `_claim_ready` helper goes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 13:13:02 -04:00
Georges-Antoine Assi
1246d18fe3 refactor(streaming): resolve containers once, behind a broker protocol
Two shapes of streaming broker were branched on at 19 call sites, and every
consumer re-derived a container's host, key, emulator, capabilities and card
sync from the raw YAML on each call. `_containers_for_platform` re-ran host
parsing and the operator's misconfiguration warnings on every request, and
`_container_label` re-read config.yml once per listed row.

`handler/streaming/`:
- `protocol.py` gives each broker shape a class owning its route prefixes,
  timeouts, response dialect, stream-URL assembly and capability flags. A call
  site now asks `protocol.supports_disc_swap` or `protocol.save_state_accepted`
  instead of re-testing `protocol: webstation`. Instances are interned per
  subfolder so identical configs share one object.
- `capabilities.py` holds the per-platform and per-emulator slot tables and the
  state transfer limits, keyed purely by platform and emulator.
- `config.py` turns the raw list into frozen `ResolvedContainer` records with
  every question already answered, memoized until the config changes, so the
  warnings fire once per config rather than once per lookup. A container RomM
  cannot dial still resolves, with an empty key: unclaimable, but visible in
  the admin fleet view where the operator can see why.

`endpoints/streaming.py` drops ~700 lines and takes records rather than dicts
throughout; `container.emulator` and `container.protocol.session_route(...)`
replace the derivations that used to run per call.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 10:13:46 -04:00