Repository navigation
fix(gateway): sessions.describe stalls while the session list refreshes the same row - #156791
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: blocked before merge. Reviewed September 24, 2026, 8:17 AM ET / 12:17 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch shares in-flight Gateway session-row reads between list refresh and descriptions, adds overlap regression cases, and adjusts a Codex side-question test fixture and cleanup. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 3 items remain Keep open. The previously identified cross-store stall remains in this head: a description for one store can wait for an unrelated store’s bulk read. Current main also lacks the proposed same-row coalescing, so the core fix remains useful. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway keeps session rows ready for list and description requests. Session changes mark rows dirty; background refresh and foreground descriptions read their updated facts through SQLite workers. flowchart LR
A[Session change] --> B[Dirty session rows]
B --> C[Background list refresh]
D[Describe request] --> E[Exact row preparation]
C --> F[SQLite read workers]
E --> F
F --> G[Updated row facts]
G --> H[List or description]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +40, Tests +96. Total +136 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Give each target row or physical-store read its own completion boundary, preserving same-row sharing while a description in another store can finish independently. Do we have a high-confidence way to reproduce the issue? Yes, from source: start a bulk refresh with dirty rows in two physical stores, hold the first store’s worker response, and describe the second. This read-only review did not execute that missing case. Is this the best way to solve the issue? No, the current sharing scope is too broad. Keeping completion tied to the target row or store is the narrower repair, with a two-store regression protecting foreground independence. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5b384871ea62. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What 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 |
…escribe Bulk refresh and exact row preparation could read the same dirty session row concurrently, starting a cold second shared-state reader and stalling sessions.describe past its window. Keep one in-flight worker read per row: bulk skips exact-owned rows, exact preparation joins an in-flight bulk read and rechecks, and the drain waits for exact reads (then yields) instead of spinning.
f13f6fe to
67f520b
Compare
|
CI run 35975857019 failed
Both exhausted the 5s wait at line 160: On a fresh Linux Blacksmith Testbox at The failed jobs were rerun once (run attempt 2) on this same head. No further reruns are authorized. Attempt 2 failed again on the same two cases and the same |
…untime Two startup-interrupt cleanup cases timed out on 2-CPU CI runners waiting for thread/fork: each case paid 1.2-2.6 s of real provider-schema normalization, and a failed wait skipped abort/close, leaking the binding lease into the next case. Reuse the sibling prepared schema runtime fixture and make cleanup unconditional.
|
Merged via squash.
|
…es the same row (openclaw#156791) * fix(gateway): share in-flight session row reads between refresh and describe Bulk refresh and exact row preparation could read the same dirty session row concurrently, starting a cold second shared-state reader and stalling sessions.describe past its window. Keep one in-flight worker read per row: bulk skips exact-owned rows, exact preparation joins an in-flight bulk read and rechecks, and the drain waits for exact reads (then yields) instead of spinning. * test(codex): contain side-question abort cleanup and prepare schema runtime Two startup-interrupt cleanup cases timed out on 2-CPU CI runners waiting for thread/fork: each case paid 1.2-2.6 s of real provider-schema normalization, and a failed wait skipped abort/close, leaking the binding lease into the next case. Reuse the sibling prepared schema runtime fixture and make cleanup unconditional.
What Problem This Solves
Fixes:
sessions.describecan stall for over a second right after a session changes, because a background session-list refresh and the describe request read the same session row at the same time.User Impact
Session describe reads that land while the resident session list is refreshing no longer issue a duplicate worker read or cold-start a second shared-state reader, so they return as fast as the warm path. Internal-facing otherwise; no config or API change.
Why This Change Was Made
The resident session-row projection has two readers for dirty rows: the background bulk refresh (up to 64 dirty rows per batch) and exact preparation for foreground reads like
sessions.describe. Neither knew about the other, so a row could be read twice concurrently. The duplicate request often started a second, cold shared-state read worker that needed more than a second, while the warm worker answered in milliseconds. That is the root cause of thesession-activity-summariesrecap flake (keeps describe non-current while the newer first-turn recap is queued or held, ~40-50% locally, andchecks-node-compact-large-12in CI).This change makes the refresh owner keep one in-flight worker read per row, with no row-count special case:
That last yield comes from instrumentation. Without it, the drain woke in the same microtask burst as the describes and re-read placements that materialization had just registered (duplicate placement reads in
session-row-projection.prepared-read.test.ts, 3/15 runs). A synchronousrefreshPendingfast path in exact preparation also fixed that, but it bypassed the archive test's preparation barrier, so it was dropped.Reviewer note: the post-wait yield restores the ordering that
maingot incidentally from its duplicate worker round trip. It is a scheduling guarantee by convention (the drain already yields between batches), not a structural handoff between the placement owner and the drain. If you would rather have the placement owner skip resident preparation for ids with an installed-pending exact snapshot, that is the stricter follow-up, but it touchessession-row-placement-projection.tsand I kept this change inside the refresh owner.The shared-state read-worker pool itself is unchanged. Its second worker is ordinary pool capacity for distinct concurrent reads; the pool cannot tell a duplicate from a distinct request, so deduplication belongs to the row owner.
Evidence
New regression cases in
session-row-projection.worker-read.test.tshold a worker read open and assert each dirty row is read exactly once, with bulk-first and exact-first ordering, for one and two rows. All three fail onmain(the held row is read twice) and pass with this change.main). Linux Testbox did not reproduce the recap flake on either side (10/10 baseline), so the new regression cases are the deterministic proof.session-row-projection*.test.ts21 files, 159/159;prepared-read.test.ts15/15 runs (the intermediate candidate failed 3/15 while baseline passed 15/15); accepted-facts and worker-read 41/41, including the pinned-pages cold-archive case; keyed-marks benchmark passes (median 259.8 ms thread CPU for 10k publications, about 25 s wall versus 36 s baseline);pnpm tsgo:coreand the Gateway tsgo project pass;oxfmtandgit diff --checkare clean.node scripts/check-changed.mjspassed on the Testbox for the diff before the final three-line yield; the yield adds no new types or imports beyond an existing helper, and typechecks were rerun on the final code.Known unrelated flakes seen on unmodified
mainduring this work: three preview-deadline tests (~1 in 3) and a 100 ms latency assertion observed at ~128 ms.Bundled flaky-test fix (separate commit)
extensions/codex/src/app-server/side-question.execution.test.tsfailed twice on this PR's CI (2-CPU runner): two startup-interrupt cleanup cases timed out waiting forthread/fork. The shard never loads the changed gateway module (instrumented: zero loads across all 11 forks), so it is unrelated to the projection change, but it would block any PR that pulls this shard. Measured causes on a CPU-constrained Testbox: each case paid 1.2-2.6 s of real provider-schema normalization beforethread/fork(the siblingside-question.test.tsalready uses the prepared schema runtime fixture), and a failed wait skipped abort/close, leaking the binding lease so the next case also timed out (injected-failure probe: next case failed at 5.0 s before, passed in 1.46 s after). The commit adds the sibling fixture and makes cleanup unconditional; assertions and the 5 s deadline are unchanged. Proof: constrained 11-file shard 3/3 (311/311), side-question files 102/102 locally at load ~75 with the affected cases at ~1.35 s, extensions test typecheck, autoreview clean.