Repository navigation
improve(gateway): reduce presence work for concurrent viewers - #158497
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 9:55 PM ET / September 26, 2026, 01:55 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch batches Gateway presence updates and reuses prepared session-visibility facts and roster encodings for concurrent viewers, with accompanying tests and documentation. Merge readiness✅ Ready for maintainer review Keep open. Current main still uses immediate presence broadcasts, and this fresh maintainer PR has a distinct, coherent purpose. The related typing PR does not replace it. I found no source-backed blocking defect. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives connection activity and watched-session declarations from clients. It filters the resulting presence roster for each viewer and sends it through hello snapshots, presence replies, and WebSocket events. flowchart LR
A[Client activity and watches] --> B[Gateway presence state]
B --> C[Publication queue]
C --> D[Session sharing facts]
D --> E[Per viewer access check]
E --> F[WebSocket presence events]
B --> G[Hello and presence replies]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +58, Tests +275, Docs +4. Total +337 across 37 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one Gateway-owned presence publisher while preserving immediate hello and RPC reads and checking sharing authority for every recipient before socket delivery. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main broadcasts each presence change immediately and prepares watched-session data on the presence path. The PR describes a 100-viewer before/after benchmark, which this read-only review did not rerun. Is this the best way to solve the issue? Yes. The change places batching with one Gateway publisher and keeps the access decision at each recipient, without adding configuration or a second persistent store. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against da49c7e45c4c. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Use arrow callbacks for the closure-owned presence publisher and explicitly discard the synchronous presence test handler return. Repairs the five lint errors from CI run 36205860153 without changing publication or response timing.
|
Merged via squash.
|
…aw#158497) * perf(gateway): coalesce presence publications and reuse sharing facts * test(gateway): use client registry for chat activity proof * fix(gateway): make presence callbacks safe to pass unbound Use arrow callbacks for the closure-owned presence publisher and explicitly discard the synchronous presence test handler return. Repairs the five lint errors from CI run 36205860153 without changing publication or response timing.
What Problem This Solves
Connecting or switching sessions with many Control UI viewers repeatedly rebuilt and serialized the complete presence roster and queried SQLite synchronously on the Gateway thread.
User Impact
Presence changes in the same event-loop turn share one publication. Hello snapshots and
system-presencereplies read current state immediately when sharing facts are ready, while pending topology uses the existing readiness owner. Recipient visibility, profile envelopes, connection sequence numbers, and admin access to declared incognito watches are preserved. No protocol, configuration, or database schema changes.Why This Change Was Made
All presence consumers now use committed sharing and profile facts. One Gateway-owned publisher coalesces superseded work, retains the latest state while preparation is pending, and cancels publication on shutdown. Identical projected views share their payload encoding within a publication, with authorization rechecked for each recipient. The existing client registry also removes the redundant connection scan when recording activity.
The change removes the old synchronous presence lookup path and version-mutator plumbing, corrects the presence scope documentation, and keeps unexpected background publication failures from escaping the event loop.
Evidence
Synthetic production-function benchmark on Node 26.9.0 / Apple M3 Ultra, using the same fixture, real resident session projection, and an immediate socket sink:
The burst drives publication requests in one turn; it is not a full network handshake or model-load benchmark. Shared-host contention affected timing: an earlier baseline broadcast median was 8.82 ms, and the final before/after p95 values were 103.37/26.30 ms. Frame counts, byte counts, and SQL counts are deterministic; these results do not establish a production latency SLO.
node scripts/run-vitest.mjswith--maxWorkers=1(files below), 509.67 s wall including cold worker preparation.server.auth.presence-audience.test.ts,server/presence-events.test.ts, andserver/ws-connection/connect-hello.setup-completion.test.ts, 816.47 s wall. This covers actual hello/RPC/event visibility, admin incognito watches, cold configuration publication, preparation coalescing, cancellation, and publication failure recovery.node scripts/run-vitest.mjs src/gateway/server-connection-state.test.ts --maxWorkers=1, 819.87 s wall; verifies zero host SQL for warm broadcasts/RPC/hello, dirty-row visibility, admin incognito watches, and committed revocation during fan-out.node scripts/run-vitest.mjs src/gateway/server-methods/chat.error-broadcast.test.ts --maxWorkers=1, 378.97 s wall.node scripts/check-changed.mjsattempts found three fixture/type issues, all fixed; production and 21 test graphs passed before the final fixture error. The next local run was stopped under the campaign's remote-only gate policy. Blacksmith Testboxtbx_01m3dhr0gebt51f9eq4p3k0e9r(run) then hit a source-sync timeout (351.09 s). The repository wrapper retry stalled before remote execution in localgit init; a process sample showed an OSrenamewait. The lease was stopped and the local staging process tree was terminated; its OS-blocked child remained pending termination. Neither remote attempt executed the check payload; hosted CI is authoritative for the remaining gate.Focused 100-test command
Landing validation follow-up
The first exact-head CI run (36205860153) found five lint errors: four references to closure-backed publisher methods and one intentionally unawaited synchronous-response probe. Commit
56dd0350187e9ae0241354855b37d9f3b167ec70makespublish/stoparrow callbacks and marks the probe's return as ignored, preserving its immediate-response assertions. The sibling CI cancellations followed the primary lint failure; no blind rerun was requested.Formatting and targeted lint across all five reported sites passed (lint: 236.59 s wall). Independent Codex review of the repair was scoped-clean through P1. The three publisher lifecycle tests passed. The local connection-state run remained stalled after cold worker preparation (701.31 s); runner/worker samples showed event-loop waits without an assertion failure, and the owned run was interrupted after 1,484.44 s wall. That local run is incomplete evidence, not a pass; the cause remains unresolved. Exact-head hosted CI passed on
56dd0350187e9ae0241354855b37d9f3b167ec70: run 36208552952, with a green complete check rollup.