11 Commits

Author SHA1 Message Date
Sam Dornan
6215ab341e Disable redis-py maintenance notifications probe (#5015) 2026-10-02 07:58:20 -04:00
Sam Dornan
d828706ef9 perf(backend): pipeline multi-command Redis writes (#4858)
* perf(backend): pipeline multi-command Redis writes

- upload_chunk records a chunk with SADD, EXPIRE and SCARD in one
  transaction instead of three round trips, so a failure between them
  can no longer leave the chunk set without a TTL.
- bind_to_login_session does its SADD and EXPIRE in one transaction for
  the same reason.
- close_login_sessions reads and deletes a session's socket set in one
  transaction, so a socket binding in between is not dropped unseen.
- Logout deletes the session and removes it from the user's set in one
  pipeline.
- complete_chunked_upload reads the chunk set once instead of SCARD then
  SMEMBERS; cancel and invalidate_filter_values_cache delete their keys
  in one call.

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

* fix(backend): refuse a socket bind that lands after its session's revocation

- bind_to_login_session checks the login session still exists in the
  same transaction as its SADD. Revocation deletes the session before it
  reads the socket set, so a bind that finds it gone removes itself and
  authenticate treats the socket as anonymous.
- complete_chunked_upload keeps its SCARD fast path and reads the
  members only to name the missing chunks.
- cancel_chunked_upload removes the temporary files before touching
  Redis.
- Tests check each pipelined write executes as one MULTI/EXEC.

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

* fix(backend): close an upload session before removing its files on cancel

A chunk PUT that passes the session check after the temporary directory
is gone fails with a 500; deleting the session first turns it into a 404.

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

* fix(backend): answer a chunk write cut short by a cancel with 404

A PUT that passed the session check before the cancel removed its
directory fails writing; it now re-reads the session and returns the
same 404 as a PUT that arrives after the cancel, instead of a 500.

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

* chore(backend): remove a stray Redis snapshot

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 19:41:49 -05:00
nendo
f0c49b6a38 feat(devices): push downloads from the web UI to a device's download queue 2026-09-28 02:08:03 +09:00
Sam Dornan
7c2b049b70 chore(mypy): drop warn_return_any and validate provider responses with strict JSON (#4826) 2026-09-26 20:13:55 -04:00
Sam Dornan
bd16648c9a chore(mypy): switch to strict mode with listed exceptions (#4817)
* chore(mypy): switch to strict mode with listed exceptions

Replace the hand-picked flags with `strict = True`, turning off only the
four flags that aren't clean yet (disallow_any_generics,
warn_return_any, disallow_untyped_calls, disallow_untyped_decorators).
Any other strict flag, including those future mypy releases add to the
preset, is on by default.

That turns on no_implicit_reexport, strict_equality and extra_checks:
- Import each name from the module that defines it. About 240 test
  sites patched a dependency through the module that imported it
  (`scan_module.fs_rom_handler`); they now import the same object from
  its source, so every patch targets what it did before. Tests that
  replace a module attribute are unchanged.
- handler.streaming.memory_cards re-exports store_memory_card_version
  explicitly, since endpoints call it there and tests patch it there.
- mutagen gets implicit_reexport, as it re-exports without __all__.
- Test comparisons build typed values (CoverResult, a typed expected
  dict, enum .value) and the CORS lookup casts for its identity check.
- One ss_handler ** spread keeps a coded ignore: extra_checks wants its
  NotRequired dump_* keys spelled out, and the media dict never has them.

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

* test(upload): assert cleanup against the patched upload directory

The 409 test checked config's ROM_UPLOAD_TMP_BASE while the fixture patches
the endpoint's copy to tmp_path/uploads, so it passed even if cleanup failed.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 15:45:37 -05:00
Georges-Antoine Assi
4bcc9da844 refactor(netplay): apply simplify pass
- 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>
2026-09-25 13:03:08 -04:00
Georges-Antoine Assi
2af79c1486 fix(netplay): apply code-review xhigh findings
- 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>
2026-09-25 12:50:37 -04:00
zurdi
01483dd715 fix: disconnect a session's sockets when it is revoked
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>
2026-09-23 14:23:39 +02:00
zurdi
45fbb4fb7c fix: apply the second code-review pass
- 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>
2026-09-23 13:31:14 +02:00
zurdi
bb5769e606 refactor: apply the simplify pass
- 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>
2026-09-23 13:04:18 +02:00
zurdi
57311dc99a fix: apply the security-audit and code-review passes
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>
2026-09-23 12:47:11 +02:00