- Move connect-time user resolution and login-session binding into
SocketHandler.authenticate, shared by the /ws and netplay servers.
- Add SocketHandler.get_session and drop the per-module copies.
- Fold disconnect into leave-room, and the user load into the ROM gate.
- Read the room password only from the field EmulatorJS sends.
- Close both servers' sockets for a revoked session concurrently.
- Correct the join-room password rule in the architecture doc.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Bind netplay sockets to their login session, keying the socket set per
channel so revoking a session closes sockets on both servers.
- Read the room password from the top-level field EmulatorJS sends, and
compare it in constant time.
- Namespace Socket.IO room names so a room id cannot collide with a sid.
- Refuse a duplicate player id on join, and leave the current room before
opening or joining another.
- Coerce client-supplied maxPlayers and names, and store the resolved ROM id.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A socket joins its user's room, and an admin's the admin room, once at
connect time, so logging out or revoking a user's sessions left their open
sockets receiving notifications and the log stream. Each socket is now
recorded against the login session that opened it, and removing a session
disconnects those sockets on whichever worker holds them.
The main server takes one disconnect handler, so it moves next to the
connect handler and runs the activity cleanup as well.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The shared write manager passes the server's json_module, which a
manager never attached to a server doesn't inherit; streaming pushes
lost it when they moved onto that manager.
- The inbox drops a list requested before a reset, so a slow response for
the previous user can't fill the next user's inbox.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- One home for pushing to a user's room: `SocketHandler.emit_to_user`, on a
write-only manager kept per event loop and on the server's own channel.
Streaming's push_to_user and the sync and scan emitters use it too.
- Notifications are stored in one transaction per send, so a broadcast is one
commit, and pushed concurrently. Recipients are resolved from id and
enabled only, and the actor is loaded with just the fields it shows.
- notify_user_or_admins holds the "whoever started it, else the admins"
rule both the scan and the task runner applied by hand.
- A scan notifies from finish(), so no exit path can forget it.
- `data` is never null, dropping its guards; the toast host, the inbox and
the admin form share one tone icon map; the inbox icon uses RAvatar.
- The store keeps its list when a socket echo changes nothing, and small
dead parameters and duplicated lists are gone.
- The socket reconnect after a logout moved from the inbox to AppLayout,
since every v2 feature depends on the socket's identity.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Security:
- The netplay socket server shared the main server's Redis channel while
letting unauthenticated clients name their own rooms, so a netplay socket
in room `user:N` or `admin` received that user's pushes and the admin log
stream. Netplay now has a channel of its own.
- Notifying other users also requires users.write on the token, so an admin
token scoped to me.write can only notify its owner.
- The create payload rejects NUL characters, NaN/Infinity in data and an
empty recipients list instead of failing in the database; mark-read takes
at most as many ids as an inbox holds.
Correctness and cleanup:
- The inbox is cleared whenever the signed-in user changes, so a failed
fetch can't leave the previous user's notifications on screen.
- Enter no longer sends the admin form, where an unfinished title would go
out to everyone.
- A notification without its own icon shows its level's, in the list and in
a pushed toast alike, from one LEVEL_ICONS map.
- One write-only Redis manager per event loop instead of one per push.
- Tests for the inbox socket wiring; em-dashes and long docstrings trimmed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(backend): make type ignores match what mypy reports
Third in the staged series clearing the errors #4655 made visible.
Whole-project mypy: 91 errors in 26 files -> 64 in 23.
Twenty `# type: ignore[assignment]` comments in
endpoints/responses/rom.py never suppressed anything. The request-scoped
values `from_orm_with_request` attaches to a Rom (rom_user, has_notes,
user_saves and the rest) are not declared on the model, so mypy reports
`attr-defined`; it does so under 1.19 as well as 2.3, so the code was
wrong when the comments were written rather than drifting since. They
now name the error they were meant to silence.
Seventy-nine ignores across 24 files suppressed nothing at all under
`--warn-unused-ignores`, and are removed. One of them,
`utils/zip_cache.py`, keeps its `attr-defined` code for the private
`zipfile._get_compressor` and drops only `assignment`. The unused set is
identical under mypy 2.3.0 and 2.3.1, and removing them leaves the error
count unchanged under both, so none was quietly needed.
The two `filter` helpers typed as `[QueryT: Select | Update | Delete]`
bound the TypeVar to the union, so `query.filter(...)` returned the union
and could not be assigned back to `QueryT`. Constraining it to the three
types lets mypy check each one separately, and the callers are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPpv6W2ygP9tQ61fTQxdYp
* fix(backend): replace mypy and ASYNC240 trunk-ignores with real fixes
A `trunk-ignore` only suppresses when Trunk runs the linter. Plain mypy
does not read them, so the 13 on mypy findings were all still errors to
`mypy .` and would fail a whole-project check. Each now has a fix.
endpoints/tasks.py: `common_data` was a plain dict literal unpacked into
eight TypedDict constructors, so mypy saw `dict[str, Any]` and could not
match its keys. It holds exactly the fields of BaseTaskStatusResponse and
is now annotated as one, so the unpacking is checked.
handler/metadata/gamelist_handler.py: both media maps were inferred as
`dict[str, str]`, so indexing the TypedDict with their keys was
unprovable. Their keys are now typed `GamelistMediaKey`, the Literal of
the TypedDict's fields. A misspelt map key is now an error at the entry;
before, only the index site could have noticed, and it was suppressed.
handler/metadata/playmatch_handler.py: `attr` was a bare `str`. A TypeIs
guard narrows it to the five lookup attributes, and the frozenset is
derived from that Literal so the names live in one place. mypy now checks
that each name is a real PlaymatchRomMatch key. It does not check that
each takes an int, since mypy is lenient about value types on a union key;
that still rests on which five names are listed.
endpoints/search.py: the per-source tuples mixed ROM-list and handler
types, which mypy joined to `object`. The dict is now annotated with what
the loop uses: Mapping rows and the MetadataHandler base.
tests/handler/metadata/test_launchbox_handler.py: `Path.stat()` inside an
async test (ASYNC240) now goes through `anyio.Path`, as the rest of the
codebase already does.
Whole-project mypy: 64 errors in 23 files -> 51 in 20, identical under
2.3.0 and 2.3.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPpv6W2ygP9tQ61fTQxdYp
* fix(backend): keep gamelist media keys in one place
Review pointed out that `GamelistMediaKey` repeated all fourteen fields
of GamelistMetadataMedia. Python has no `keyof`, so any Literal of a
TypedDict's keys is a second declaration of them, and a field added to
the TypedDict would be left out of it without any error.
The three index sites go back to suppressing `literal-required`, now as
`# type: ignore[literal-required]` so plain mypy reads it as well as
Trunk. The TypedDict stays the only declaration of the key set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPpv6W2ygP9tQ61fTQxdYp
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Similar to how `engineio` provides a JSON-compatible module, this change
adds a custom JSON encoder with support for additional types.
Changing SocketIO's JSON module fixes the encoding issue when the
scanning process tried to send a datetime, failing and the frontend not
displaying the scanned game (commonly, when it had sibling games)
This change replaces the creation of Redis URL, from a simple string
interpolation, to using `yarl.URL`. The main benefit, besides not
forgetting to set all five different variables on every Redis client
initialization, is that user credentials are correctly URL-encoded, if
present.
Up until now, if a password had special characters, it could break the
generated URL.
This change also introduces support for a `REDIS_SSL` setting, which
allows the user to specify if the Redis connection should use SSL or not.