Repository navigation
perf(gateway): remove redundant chat admission metadata reads - #158586
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 26, 2026, 1:41 AM ET / 05:41 UTC (Revision 4). ClawSweeper reviewWhat this changesGateway chat admission replaces a full early session metadata check with a smaller check, retains one fresh read under the session writer barrier, and adds a SQLite read-count regression test. Merge readiness✅ Ready for maintainer review Keep open. Current main still performs the redundant admission read, and the pinned PR has credible proof for the focused optimization with no identified correctness or security blocker. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives a chat send request with a prepared session and decides whether to admit an agent run or return a rejection or replay. Its session writer barrier orders the final check against current session metadata before run registration. flowchart LR
A[Chat client] --> B[Gateway send request]
B --> C[Prepared session]
C --> D[Early admission check]
D --> E[Session writer barrier]
E --> F[Fresh session check]
F --> G[Run or response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -20, Tests +81. Total +61 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain one fresh, writer-ordered session validation while preserving early busy refusal, live caller checks, cancellation, and run registration. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source performs both metadata checks, and the PR reports a real-SQLite negative control; this read-only review did not rerun it. Is this the best way to solve the issue? Yes. The existing writer barrier remains the authority point, and the early check can stay inexpensive without introducing another cache or contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 20f3170d3672. 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
HistoryReview history (3 earlier review cycles)
|
|
Merged via squash.
|
…aw#158586) * perf(gateway): prepare chat admission reads off thread * refactor(gateway): validate chat admission once under its barrier * test(gateway): await native chat session preparation * perf(gateway): remove redundant provisional session reads * fix(gateway): preserve early exclusive admission refusal
What Problem This Solves
chat.sendreloads and decodes full session metadata in provisional lifecycle validation before reading it again under the writer barrier.User Impact
Normal pre-admission consumes the prepared session entry. The lifecycle precheck retains live caller, physical-target, and in-memory exclusive-work checks. A single fresh metadata read remains under the authoritative writer barrier, alongside the existing settings, expected-leaf, session identity, cancellation, retry, and registration checks.
Why This Change Was Made
The provisional metadata reload duplicates the authoritative read. Removing it also removes the conditional provisional/commit branches. The small warm reads remain synchronous under the campaign's measured-CPU rule; no new worker traffic, cache, configuration, protocol, schema, or durability behavior is introduced.
Related: #158026 adds admitted-entry plumbing in the same helper for SSH attachments. This change keeps metadata capture inside the final commit callback; that PR's
admittedSessionEntryassignment belongs there unconditionally once the changes are combined. It does not duplicate the attachment fix.Evidence
node scripts/run-vitest.mjs src/gateway/server-methods/chat-send-admission.reads.test.ts --maxWorkers=1: 1 passed, 10.94 s wall.e05999278be68d38527769413394a8afafb599d4, with no accepted/actionable findings.Interleaved A/B, seven warm waves per size, 50 synthetic sessions, actual Gateway exact readers: three baseline loads versus initial preparation plus one final read. Canonical per-agent store, Node 26.9.0 / Apple M3 Ultra, shared host load around 39. CPU uses
process.threadCpuUsage().That is 30–35% less main-thread CPU and wall time. Foreground statements fall 550 → 350 in every wave. These are component measurements, not ACK/first-token latency or a claim that all baseline reads occur in one event-loop turn.
Final-head proof uses Crabbox / Blacksmith Testbox
tbx_01m3e1dx8ysh9n4zegtyh4fjm3, environment run, with focusednode scripts/run-vitest.mjs … --maxWorkers=1calls andnode scripts/check-changed.mjs --base b4d60fa5edfc2713a5cb3643fa1c936fec3c3cd0. The previous lease (tbx_01m3dtdst4g4wh2e9gyzgzjcje) finished during its gate after 14 typecheck groups; that interrupted gate is not counted as passed. It was closed before acquiring the replacement. Only one box was active. The final command exited 0; optional external-portal reporting emitted a nonfatal timeout after completion. No full build or swarm run was needed for the read-count change.