Repository navigation
perf(gateway): pace typing requests with prepared sharing facts - #158552
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, 11:56 PM ET / September 26, 2026, 03:56 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch paces Control UI draft-preview requests and uses prepared Gateway session-sharing facts when deciding whether to broadcast typing updates. Merge readiness✅ Ready for maintainer review Keep open. Current main still uses the older typing path, and the merged presence work does not supply this PR’s distinct typing improvements. The introduced patch has no supported blocking finding. Priority: P2 Review scores
Verification
How this fits togetherThe Control UI sends typing requests for the selected session to the Gateway. The Gateway checks session and sharing authority, then sends eligible previews to subscribed collaborators. flowchart LR
A[Chat composer input] --> B[Control UI request pacing]
B --> C[Gateway typing request]
C --> D[Session and sharing facts]
D --> E[Live authority check]
E --> F[Recipient filtering]
F --> G[Collaborator preview]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +99, Tests +158, Docs 0. Total +257 across 12 files. View PR surface stats
Review metrics
Mantis proof suggestionA two-client Control UI chat capture would directly show the preview behavior left open by the boundary traces. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Technical reviewBest possible solution: Keep live caller and session checks at the Gateway broadcast boundary, with recipient filtering owning disclosure and UI pacing scoped to the current connection. Do we have a high-confidence way to reproduce the issue? Yes. Current main still sends typing requests without UI pacing, and its Gateway handler uses synchronous target resolution; the PR supplies a registered-handler benchmark, though this review did not execute it. Is this the best way to solve the issue? Yes. The branch reuses the existing session projection and sharing owner, adds no storage or protocol contract, and checks authority again before broadcast. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 15a0f34487b5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Clear the existing typing-state owner at each fixture boundary, including its pending timers before restoring real timers. Reusing the session key and resetting the clock otherwise makes the later delayed-refresh cases inherit the first case throttle window.
The positive incognito typing case loaded the real presence provider before the shared mock registered. Load the handler after mock initialization so the existing assertion reaches delivery with its two synthetic viewers.
Initialize the existing test-owned session read context before the direct typing handler call. Production startup already owns this projection; the presence fixture must satisfy the same requirement.
|
Merged via squash.
|
…claw#158552) * perf(gateway): pace typing requests with prepared sharing facts * test(gateway): reset typing state between handler tests Clear the existing typing-state owner at each fixture boundary, including its pending timers before restoring real timers. Reusing the session key and resetting the clock otherwise makes the later delayed-refresh cases inherit the first case throttle window. * test(gateway): register suggestion mocks before loading handlers The positive incognito typing case loaded the real presence provider before the shared mock registered. Load the handler after mock initialization so the existing assertion reaches delivery with its two synthetic viewers. * test(gateway): prepare typing projection in presence fixture Initialize the existing test-owned session read context before the direct typing handler call. Production startup already owns this projection; the presence fixture must satisfy the same requirement.
What Problem This Solves
Typing in the Control UI repeatedly blocks the Gateway main thread on session reads, even when nobody else can receive the preview.
User Impact
Draft previews retain the latest text while typing requests are paced to the existing 250 ms preview cadence. Stop requests cancel queued UI previews immediately. Delayed Gateway emissions recheck the live connection, session generation, and current sharing authority.
Why This Change Was Made
Typing now consumes the existing session projection and prepared sharing owner instead of resolving session targets twice through synchronous SQLite. Undeliverable attempts retain their throttle window, and prepared event authorization no longer allocates unused legacy lookup maps. Authorized incognito typing keeps the existing transient exact-read path.
Related: #158497 already contains the identical client-presence lookup cleanup, so that change is left with the presence PR. No protocol, configuration, or database schema changes.
Evidence
handleGatewayRequestmicrobenchmark, 50 independent lone-viewer sessions, 30 interleaved A/B pairs after 10 warmups, Node v26.9.0. Fresh attempts: median wall 15.521 → 2.053 ms, main-thread CPU 13.305 → 1.823 ms (86.3% less). Retained throttle: wall 19.446 → 1.721 ms, CPU 13.365 → 1.332 ms (90.0% less).node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-methods.config.ts src/gateway/server-methods/session-typing-state.test.ts src/gateway/server-methods/sessions-typing.test.ts src/gateway/server-methods/sessions-suggestions.test.ts src/gateway/server-methods/sessions-suggestions.visibility.test.ts --maxWorkers=1 --reporter=verbosehit the repository's 120-second no-output watchdog (150.17 s wall, exit 143). The UI owner config withui/src/pages/chat/chat-pane-typing.test.ts --maxWorkers=1did likewise (148.63 s wall, exit 143) after a Lit warning. Earlier aggregate/owner attempts built worker-test caches and were canceled without verdicts. These remain explicit Vitest validation gaps; no assertion or timeout was weakened.tbx_01m3djxhdjzsc6813837598nsw(run). The default-base attempt stopped on an unrelated assertion ratchet because the shared localorigin/mainref was stale. Repeatingnode scripts/check-changed.mjs --base bfabd8e3f7b77cf01cb792becc019ac557c9cac1failed during Blacksmith source sync before checks executed (outer five-minute stall guard, then native two-minute sync timeout). The box is stopped. Full changed-lane lint/typechecking remains a hosted-CI validation gap.Landing validation
Hosted CI run 36209775208 exposed four deterministic failures in the delayed-refresh table in
sessions-typing.test.ts. The first case retained the process-wide typing throttle; subsequent cases reused the same session key while resetting the fake clock, so their initial broadcast was incorrectly throttled. The fixture now clears the existing typing-state owner before and after each case, cancelling its pending timers before restoring real timers. Production behavior and all assertions remain unchanged.The full pre-fix typing file reproduced the same four failures locally (13 passed, 4 failed; 811.59 s process wall on the I/O-saturated host). After the fixture repair,
node scripts/run-vitest.mjs src/gateway/server-methods/sessions-typing.test.ts src/gateway/server-methods/session-typing-state.test.ts --maxWorkers=1passed all 26 tests in both files (505.53 s process wall; Vitest 470.93 s). Hosted failing shard duration was 137.56 s across 64 files. This extends existing lifecycle coverage and adds no test cases or production seams. Formatting and whitespace checks pass; independent Codex review of the repair is scoped-clean through P2. Subsequent hosted CI found the separate fixture issue below.The next exact-head run 36211649369 exposed the positive incognito typing case in
sessions-suggestions.visibility.test.ts. This was a second fixture defect: the file eagerly imported the handlers before the shared presence mock registered. A local reproduction failed identically (146.05 s process wall); temporary diagnostic evidence showed two configured fixture viewers but an empty presence set in the real typing owner. The handler import now follows shared mock registration. The diagnostic was removed, and neither product code nor assertions changed.node scripts/run-vitest.mjs src/gateway/server-methods/sessions-suggestions.visibility.test.ts src/gateway/server-methods/sessions-suggestions.test.ts --maxWorkers=1now passes all 27 tests (188.00 s process wall; Vitest 154.66 s). The failing hosted shard took 164.74 s across 57 files. The existing positive incognito assertion is the regression; no new tests or production seams were added. Formatting and whitespace checks pass. Independent Codex review of this fixture repair is scoped-clean through P2. A later CI run exposed the remaining direct-caller fixture below. A two-client Control UI/WebSocket demonstration remains unrun; existing boundary and registered-request proof is described above.Run 36213463084 then reached
server-request-context.presence.test.ts, whose direct typing call still used an uninitialized session projection. The other direct typing callers already prepared their test context. This fixture now awaits the existing test-owned session-read initializer once before typing, preserving the handler's production startup requirement and the activity/presence assertions. The unchanged case reproduced locally with the same startup error (60.15 s process wall).node scripts/run-vitest.mjs src/gateway/server-request-context.presence.test.ts --maxWorkers=1passes all 10 tests after the repair (44.73 s process wall; Vitest 37.29 s). The failing hosted child shard took 89.11 s across 46 files. Formatting and whitespace checks pass. The existing typing/presence integration case is the regression; no new test cases were added. Independent Codex review of this fixture repair is scoped-clean through P2. Final exact-head hosted CI is green forbfe8ce1f01ad95fc23c0821940349c530525e46e: run 36214896942, verified by the repository CI watcher. The three fixture repairs preserve all production code and assertions; 63 focused tests pass across their owning files.