Repository navigation
fix: keep chat sends working during concurrent session updates - #166027
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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 5:06 AM ET / 09:06 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR queues a raced session-metadata reread behind existing writes so concurrent chat sends can prepare successfully, with regression coverage and documentation. Merge readiness✅ Ready for maintainer review The fix remains necessary on current main. The pinned patch has no actionable correctness or security findings, and the reported production-path concurrency runs provide sufficient behavior proof. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway reads stored session metadata before preparing chat requests. Its session reader coordinates with SQLite writers and validates the selected session before handing facts to chat admission. flowchart TD
A[Chat send request] --> B[Discover session store]
B --> C[Read metadata snapshot]
C --> D{Snapshot still current}
D -->|Yes| F[Validate and consume facts]
D -->|Raced write| E[One reread in writer queue]
E --> F
F --> G[Chat admission]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +67, Docs +1. Total +68 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing writer FIFO for the single raced reread while retaining live freshness checks and synchronous, non-replayed consumption. Do we have a high-confidence way to reproduce the issue? Yes: current source permits two metadata publications to exhaust the speculative reread, and the supplied bench and disabled-fix regression report that exact failure. This read-only review did not execute it. Is this the best way to solve the issue? Yes: the patch reuses the existing ordering owner without increasing retries, adding a competing queue, or weakening freshness and consumer-effect guards. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2277f76df6a0. 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 (1 earlier review cycle)
|
|
Merged via squash.
|
…law#166027) Prevent concurrent session metadata updates from exhausting both chat.send preparation reads. The existing bounded reread now joins the canonical writer FIFO while preserving discovery, source validation, membership checks, and one-time consumer effects. Verified by a deterministic failing-before/passing-after regression, 60 focused cases on Node and Bun, and 73 successful sends through the maintained concurrent Gateway workload. Exact-head CI and ClawSweeper review passed. Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Fixes
chat.sendfailing withGatewaySessionFactsChangedDuringReadErrorwhen a preceding turn or the Control UI activity summary updates the same session during send preparation.User Impact
Concurrent chat clients can continue sending while session metadata settles. Existing membership, physical-source, and consumer-effect checks remain in force; no migration or configuration change is needed.
Why This Change Was Made
Initial chat preparation reads the complete session entry speculatively. Its single reread was also speculative, so two ordinary metadata publications could exhaust the retry bound. The reread now joins the existing writer FIFO and consumes a fresh snapshot before the next queued writer. The retry count stays unchanged, and a consumer that has begun effects is never replayed. Production LOC is neutral.
Evidence
A local Control UI protocol mode of the maintained Gateway bench reproduced two terminal failures among five measured sends on pinned Bun revision
667c4ab22at 4 connected / 2 active clients. Complete follow-up traces identified 16 same-session collisions: 9 activity-summary updates, 6 lifecycle completions, and 1 pending-delivery update, with no membership invalidations. Node 26 natural trials did not reproduce this specific error; the deterministic Node regression does.On the refreshed base, which includes the separate placement-inventory fix in #165984, Node 26 and pinned Bun passed all four 10-second trials at 4/2 and 32/16, with two drivers: 73 sends, 73 completed replies, zero errors, and clean acknowledged shutdowns. The macOS adaptation preserves signed clients and the maintained request workload but omits Linux resource accounting; these are correctness results, not performance measurements. Earlier baseline and fixed trials that hit the separate placement-inventory error were retained.
The regression injects real metadata writes after snapshot capture and waits for the owning FIFO to fully drain between attempts. Disabling this fix reproduces the exact error (1 failed, 6 passed); enabling it consumes fresh metadata once before the next queued write. All 60 focused tests pass on Node 24 and pinned Bun, including native-write exhaustion, membership revocation, physical aliases, and no replay of consumer effects.
session-utils-store-lookup.freshness.test.ts(7 tests)These command times include compiled-worker preparation; the new regression itself took 1.038 s on Node and 1.897 s on Bun. P2 independent review is scoped-clean; the runtime QA build and import-cycle check pass. The full changed-file check passed type, format, and safety validation, then stopped on two pre-existing unused exports:
OUTBOUND_GREETING_FALLBACK_MSin voice-call code andmodelCatalogRuntime.loadManifestModelCatalog. A clean detached current-main checkout atd3c121c23788c8b81d556b6455bc50e6c73e1631reproduces the identical findings; neither owner is touched by this PR. Every remaining planned lint/schema/storage/import/auth check was run separately and passed. No check was disabled. Exact-head CI passed atd16ef4f4f3e2b278e0b232427cade40190408c52; all seven freshness cases passed, with the new regression taking 1.057 s. ClawSweeper completed review of that same head with no findings or pre-merge blockers.