Repository navigation
perf(gateway): acknowledge idle chat after one durable input commit - #170376
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs real behavior proof before merge. What this changesEligible idle chat sends acknowledge after one atomic transcript and restart-claim commit while existing pending inputs retain their recovery path. Example: An idle conversation receives “Hello” with run ID chat-42.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open: it provides a focused, maintainer-directed latency improvement, and source review found no concrete introduced bug. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway chat admission receives authenticated chat.send requests, selects input custody, durably records the user turn and recovery claim, and acknowledges acceptance before detached dispatch. flowchart TD
A[Chat request] --> B[Session and caller admission]
B --> C[Input actor snapshot]
C --> D[Existing pending input recovery]
C --> E[Fresh transcript admission]
D --> F[Atomic transcript and restart claim]
E --> F
F --> G[Acknowledge and dispatch]
Technical reviewBest possible solution: Retain the existing transcript owner and older pending-row recovery path, with current authority enforced before transcript commit and provider dispatch. Do we have a high-confidence way to reproduce the issue? Current main visibly performs staging before transcript acceptance, and the supplied matched WebSocket workload measures its latency cost; no target code was executed during this read-only review. Is this the best way to solve the issue? Reusing the existing atomic transcript transaction is focused and preserves durable acceptance before ACK, while retaining staging for older pending rows avoids stranding approved input. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e4f463159d0a. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: No concrete authorization bypass was found, but the changed authority path still needs final-effect negative controls. EvidenceWhat I checked:
PR surfaceSource +51, Tests +84. Total +135 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 7:49 PM ET / 23:49 UTC (Revision 2). |
Recheck retained current session authority at fresh transcript admission and commit. Cover unhooked idle sends with profile replacement and session access revocation before the durable effect.
|
The direct-idle authority gap is fixed in 15bcdee. Fresh transcript admission now rechecks the retained current session authorization at the transaction/commit boundary without reopening history preparation. The added unhooked-idle controls exercise the real request route and SQLite transcript owner. Unchanged authority succeeds. Replacing the selected profile or revoking access rejects the send with no transcript append, restart claim, pending staging, or provider dispatch. All 11 preparation/ACK tests and all 15 profile-binding tests pass. The ACL-revocation control failed against the earlier direct-admission patch, exposing the missing check. The PR body now includes the terminal result, final-source ABBA measurements, correlated FIFO attribution, limitations, and passing exact-head CI. The independent review of the complete corrected patch is clean at P0–P2. |
…penclaw#170376) * perf(gateway): acknowledge idle chat after one durable input commit * fix(gateway): retain idle chat admission authority Recheck retained current session authority at fresh transcript admission and commit. Cover unhooked idle sends with profile replacement and session access revocation before the durable effect.
What Problem This Solves
Fresh idle
chat.sendrequests waited for two durable writes before acknowledging one message: pending-input custody, then the transcript and restart-recovery claim.User Impact
Eligible idle sends now acknowledge after the existing atomic transcript/recovery commit. The response still proves durable acceptance. Existing queued inputs, active/steered sends, and sends outside restart-safe admission retain their custody path. Current authority, retry identity, and message order remain enforced.
Why This Change Was Made
Use the admitted input actor's existing, writer-invalidated snapshot to select the custody path. A fresh input goes directly to canonical transcript admission. A pending row left by an older Gateway still goes through its original recovery owner, preserving both the original message identity and approval. No new cache, configuration, schema, or migration.
Production delta: +50 lines. The routing change retains the real crash/upgrade contract for already-durable pending rows; deleting staging wholesale would strand them. The existing authority guard construction moves intact into the work-admission owner to keep the handler within its line limit. The handler itself shrinks by 12 lines.
Evidence
The initial direct-admission patch relied on the staging path for ordinary idle-send ACL checks. Direct-idle negative controls exposed that gap. Fresh admission now rechecks the retained, current session authorization inside the existing composed commit assertion. The original source preparation stays unchanged, preserving history-independent ACKs; the owner invokes the assertion at fresh transaction admission and commit.
chat-send-preparation-ack.test.tspasses all 11 tests, including real request-dispatch and SQLite coverage that pauses immediately before the transcript owner:Focused terminal result (synthetic fixtures):
Changed-file formatting and lint pass. The focused preparation file passed in 54.22 s wall. Independent review of the complete corrected patch found no actionable P0–P2 findings. The profile-binding sibling passed all 15 tests after the correction (38.94 s runner wall). Previous retry and work-admission focused checks also passed. No Testbox/Crabbox was used.
Measurements
Final head
15bcdee97467655bc0e4dbd17cd4c17913935856versus baselineed97ab7d2c749b945bdaaf67475fd87cc0d6ff5f, in an isolated Linux sandbox: four ABBA blocks, 320 measured ACKs per variant (640 total), all followed by successful final replies. Each Gateway has 5,000 synthetic sessions; 20 WebSocket clients send the next turn after its final reply. Both instances stay warm. Each leg contains 40 ACKs. The configuredopenai/gpt-5.6-lunalabel targets a synthetic loopback provider with 100 ms chunks; no real model is called; loopback clients use operator scopes and auth-none. No production data or services were used.All four blocks improve p99; block 1 and block 4 medians regress by 6.6% and 12.1%. The pooled tail improvement is 2.1×, with a smaller median win. The <50 ms p50 / <300 ms p99 targets were missed. Gateway main-thread utilization remains 84–88%; run admission and idempotency/pre-admission still dominate, averaging 561 ms and 240 ms respectively after the change. Actor acquisition remains under 3 ms p99 and response serialization/send under 1.1 ms p99. This is synthetic comparative evidence, not a production latency claim.
Request attribution
A separate correlated trace of 40 ACKs per variant confirms 80 → 40
session.actor.acceptInputwrites before ACK. This trace ran on the final source after the timed ABBA campaign, with additional FIFO/worker instrumentation.A representative corrected request took 765 ms from RPC receipt to ACK, with 754 ms inside the ACK timer:
The request spent 673 ms waiting in the outer database FIFO, with 565 ms of main-thread active time during those waits. The actor read waited 61 ms and held admission for 3 ms; transcript acceptance waited 277 ms and held admission for 16 ms. Actual worker execution was 2.0 ms and 13.6 ms, with worker-broker queueing below 0.02 ms each. The idempotency read alone waited 245 ms in the outer FIFO.
This attributes the remaining delay to outer admission/main-thread contention, not slow SQL execution or response serialization. Phase spans can overlap; main-thread active time includes work for other requests and must not be summed as per-request CPU time. This trace is attribution evidence, separate from the 640-ACK latency comparison.
PR CI
Exact-head PR CI passed on
15bcdee97467655bc0e4dbd17cd4c17913935856: 613 s wall, 6,864 successful-job seconds; no failed jobs or retries. Typecheck, changed lanes, broad suites, and UI end-to-end checks ran in PR CI. The PR-context check initially rejected a renamed Evidence heading; restoring the required heading cleared that check without rerunning the CI suites.