Repository navigation
perf(gateway): avoid duplicate recipient row lookup - #159595
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 changes before merge. Reviewed September 27, 2026, 6:40 AM ET / 10:40 UTC. ClawSweeper reviewWhat this changesThe Gateway reuses a captured session row and shared presentation options when preparing session events for each connected client. Merge readiness⛔ Needs changes before merge - 1 item remains Keep open. Current main still performs the redundant recipient lookup, and the proposed change retains the existing freshness and recipient presentation checks. No actionable patch defect was found. Priority: P3 Review scores
Verification
How this fits togetherThe Gateway turns session changes into recipient-specific WebSocket events for Control UI and other clients. It selects a session row, checks each recipient, and presents current row details before delivery. flowchart LR
A[Session change] --> B[Gateway row projection]
B --> C[Captured session row]
C --> D[Recipient scope check]
D --> E[Freshness and sharing presentation]
E --> F[WebSocket session event]
Before merge
Agent review detailsSecurityNone. PR surfaceSource 0. Total 0 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the existing recipient presenter and freshness checks as the single owner of session-row display, then land this focused lookup removal when the draft is ready. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows the captured row followed by a recipient snapshot that describes the row again; the PR body reports a controlled before/after Gateway workload, though this review did not execute it. Is this the best way to solve the issue? Yes. Calling the existing presenter with the captured row removes the extra lookup while retaining its current-row validation and recipient-specific shaping. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 87248d78d6e8. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
* commit '69809d7a94277d01be964bd1cbbb7aa0ebc58c9b': (219 commits) perf(agents): serialize large model requests once (#159574) refactor(cli): share capability agent-selection test cases (#159616) fix(workers): restore installation type checks (#159629) test(channels,qa,providers): remove low-value tests (batch d065) (#159627) test(doctor): run isolated migration cases concurrently (#159609) feat(apple): show agent identities in native chat (#159528) chore(i18n): refresh native locales (#159635) fix(gateway): keep node provisioning's installation contract after overlapped preparation fix(models): keep shared catalog requests alive for remaining callers (#157191) feat: let agents query online people and device activity (#159117) perf(gateway): first cloud dispatch prepares worker artifacts one after another (#159520) refactor(android): deslop Android app third pass (#159589) test(qa-lab,openshell,slack,reef,team-reports): remove low-value tests (batch d064) (#159607) fix: align process liveness checks (#151107) thanks @ekinnee fix: sessions model default does not clear the override (#159587) fix(ios): preserve typing during reentrant SwiftUI updates fix(ci): frozen 2026.8.33 validation fails on inherited test clock (#159594) perf(gateway): avoid duplicate recipient row lookup (#159595) refactor(gateway): deslop gateway fourth pass (#158786) test(agents): split subagent task-settlement test support under the line cap (#159584) ...
* commit '69809d7a94277d01be964bd1cbbb7aa0ebc58c9b': (219 commits) perf(agents): serialize large model requests once (#159574) refactor(cli): share capability agent-selection test cases (#159616) fix(workers): restore installation type checks (#159629) test(channels,qa,providers): remove low-value tests (batch d065) (#159627) test(doctor): run isolated migration cases concurrently (#159609) feat(apple): show agent identities in native chat (#159528) chore(i18n): refresh native locales (#159635) fix(gateway): keep node provisioning's installation contract after overlapped preparation fix(models): keep shared catalog requests alive for remaining callers (#157191) feat: let agents query online people and device activity (#159117) perf(gateway): first cloud dispatch prepares worker artifacts one after another (#159520) refactor(android): deslop Android app third pass (#159589) test(qa-lab,openshell,slack,reef,team-reports): remove low-value tests (batch d064) (#159607) fix: align process liveness checks (#151107) thanks @ekinnee fix: sessions model default does not clear the override (#159587) fix(ios): preserve typing during reentrant SwiftUI updates fix(ci): frozen 2026.8.33 validation fails on inherited test clock (#159594) perf(gateway): avoid duplicate recipient row lookup (#159595) refactor(gateway): deslop gateway fourth pass (#158786) test(agents): split subagent task-settlement test support under the line cap (#159584) ...
What Problem This Solves
Session-row fanout repeats a row lookup for every recipient while many Control UI clients share one Gateway.
User Impact
The measured 100-client / 50-active workload used less main-thread CPU per completed turn and reached the first text delta sooner. Current recipient authorization, row freshness, ancestor receipts, and delivery ordering continue through the existing owners.
Why This Change Was Made
The publication already captures a row and checks its generation.
presentation.snapshot(query)looked it up again, then calledpresent, which independently refreshes and validates that captured row. Callpresent(record, enrichment)directly and allocate the constant enrichment options once per publication. This adds no cache or invalidation state.The original profile attributed 6.465 s inclusive / 1.461 s self to the recipient callback. Final-frame serialization and socket send are sibling work outside that total. A proposed envelope-copy rewrite was discarded after representative object-shape benchmarks failed to show a reliable win.
Evidence
Same Blacksmith Testbox, 4 AMD EPYC cores, Node 26.9.0, pnpm 12.5.0. Exact baseline
3fb66f0aa4e41e605d65f5dcfb93cbef89f6bb81and candidate0d09190d400af40f696226f73d5718675f6711f5, separate builds, sequential A1–B1–B2–A2 runs. Each run: 100 protocol clients, 50 actively prompting, 120 s, seed 1, mock provider paced at 25 ms word chunks, CPU profile enabled, fresh isolated state. Builds and checks finished before measurement. Testbox run.Both pairs improved CPU per completed turn. Two-run medians: 342.49 → 308.41 ms/turn (-9.95%), 9,022.28 → 7,039.20 ms first-delta p50 (-21.98%), and 19.24 → 17.35 sampled callback ms/completed turn (-9.81%). The directly affected describe/revalidation subtree fell from 2.881 → 2.043 sampled ms/completed turn (-29.09%).
All four runs completed with zero failed/pending turns, protocol errors, disconnects, integrity errors, active executions at close, or unattributed executions. Exact main CPU counters cover load plus drain; profile weights cover the load window and are sampled elapsed intervals, not independent function CPU counters. Raw callback load-window totals were roughly flat (6.636 → 6.668 s) while completed throughput increased. These are two pairs with cold first turns, not a stable capacity guarantee or evidence that the small lookup change alone explains every end-to-end difference.
Remaining limits: burst stalls did not consistently improve: median ELD max was 241.57 → 256.90 ms and >100 ms counts were 4/2 versus 3/5. Median peak RSS was 3,184 → 3,275 MiB. Host samples showed zero CPU steal and approximately 49–51% idle across four cores; A1 recorded 12 KiB of swap-in and subsequent runs recorded none. No browser contexts or live provider were involved.
Validation:
node scripts/run-vitest.mjs src/gateway/session-row-presentation.test.ts src/gateway/session-row-event-parity.test.ts src/gateway/session-row-event-trees.test.ts --maxWorkers=1: 3 files, 7 tests passed, 49.68 s wall. Existing coverage exercises recipient roles, source getters/proxies/mutations, active-run replacement and in-place changes, permission-pending changes, ancestor receipts, and list/event parity.node scripts/check-changed.mjs --base 3fb66f0aa4e41e605d65f5dcfb93cbef89f6bb81: passed, 20:49.53 wall, including selected type graphs and lint with 0 warnings / 0 errors.pnpm build: baseline 7:07.08, candidate 6:46.19, both exit 0. Both print the same pre-existing TypeScript experimental notices, startup CSS advisory, and startup JS gzip budget violation (362.7 KiB vs 362.6 KiB); these are outside the touched source and are reported without suppression.git diff --check: passed. Diff-scoped deslop: no findings. Independent Codex autoreview through P2: scoped-clean, no accepted/actionable findings.The first remote invocation stopped before builds because a scratch assertion expected the wrapper's synthetic carrier HEAD to equal the candidate SHA. The corrected script verified the exact source tree and restored the original commit identity only in the isolated build clones. No workload retry masked a failed sample. All recorded child processes and isolated state were verified removed; the owned Testbox is stopped. No open PR touching the production file was found in the pre-publication overlap check.