Skip to content

fix(gateway): sessions.describe stalls while the session list refreshes the same row - #156791

Merged
steipete merged 2 commits into
mainfrom
fix/recap-describe-flake
Sep 24, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/recap-describe-flake

Conversation

@steipete

@steipete steipete commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: sessions.describe can 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 the session-activity-summaries recap flake (keeps describe non-current while the newer first-turn recap is queued or held, ~40-50% locally, and checks-node-compact-large-12 in CI).

This change makes the refresh owner keep one in-flight worker read per row, with no row-count special case:

  • Bulk refresh skips rows an exact read already owns, and records the rows it is reading.
  • Exact preparation joins a bulk read that already holds its row instead of queuing a second read, then rechecks once that read settles (covering rejected facts, cold archived rows, and materialization left over the 12 ms slice).
  • Rows that already hold accepted facts stay selectable by bulk, since finishing them needs no worker read.
  • When every dirty row is owned by an exact read, the drain waits for those reads instead of spinning, then yields once so foreground callers install their held placement snapshots before the drain prepares placements again.

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 synchronous refreshPending fast 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 main got 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 touches session-row-placement-projection.ts and 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.ts hold 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 on main (the held row is read twice) and pass with this change.

  • Recap test on the flaking macOS host: 10/10 sequential passes with the final code (reported ~40-50% failures on main). Linux Testbox did not reproduce the recap flake on either side (10/10 baseline), so the new regression cases are the deterministic proof.
  • Linux Testbox, final code: session-row-projection*.test.ts 21 files, 159/159; prepared-read.test.ts 15/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:core and the Gateway tsgo project pass; oxfmt and git diff --check are clean.
  • node scripts/check-changed.mjs passed 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.
  • Test cost: the three new cases measured 1.36 s, 1.22 s, and 1.20 s on the Linux Testbox (about 3.8 s total, mostly per-case state setup shared with the file's existing cases); they sequence with held deferreds, not timers or polling.

Known unrelated flakes seen on unmodified main during 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.ts failed twice on this PR's CI (2-CPU runner): two startup-interrupt cleanup cases timed out waiting for thread/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 before thread/fork (the sibling side-question.test.ts already 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.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 23, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 8:17 AM ET / 12:17 UTC (Revision 3).

ClawSweeper review

What this changes

The 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 provenance

Possible 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
Reviewed head: 107640e15767a8e998b61a799e6f3c69c32ac08e

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Real worker-boundary evidence supports the same-store fix, but the unresolved cross-store stall limits patch readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The added regression drives the production session-row projection through its real SQLite worker reader with a held response; after release, the foreground description returns the updated row with one read per key. The contributor also reports 10/10 recap passes on the flaking macOS host. This proves the same-store path, while the separate two-store correctness finding remains; no stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The added regression drives the production session-row projection through its real SQLite worker reader with a held response; after release, the foreground description returns the updated row with one read per key. The contributor also reports 10/10 recap passes on the flaking macOS host. This proves the same-store path, while the separate two-store correctness finding remains; no stored-data contract changes.
Evidence reviewed 9 items Introduced cross-store join: The PR maps every selected dirty row to one bulk completion promise, and exact preparation joins that promise for its requested row.
Sequential physical-store reads: The facts reader awaits each physical-store group in sequence before accepting the selected rows. A held first store therefore delays completion for a later store in the same bulk batch.
Regression coverage boundary: The new held-worker cases create their rows under the same main-agent store; they establish same-store deduplication but do not exercise an independently ready second physical store.
Findings 1 actionable finding [P2] Keep exact reads independent of unrelated stores
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Keep exact reads independent of unrelated stores (P2) - Every selected row receives this one bulk completion promise. The facts reader awaits physical-store groups sequentially, so holding the first store also stalls sessions.describe for a ready row in a later store. This is the prior review’s still-unfixed finding; scope the join to the target read and cover two stores.
  • Resolve merge risk (P1) - A bulk batch spanning two physical stores can make a description for the later, ready store wait behind a held read in the first store. The added cases do not cover that ordering.
  • Complete next step (P2) - Repair cross-store read joining and add a held-first-store case that proves an unrelated second-store description completes before release.

Findings

  • [P2] Keep exact reads independent of unrelated stores — src/gateway/session-row-projection-refresh.ts:216-218
Agent review details

Security

None.

PR surface

Source +40, Tests +96. Total +136 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 48 8 +40
Tests 2 176 80 +96
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 224 88 +136

Review metrics

Metric Value Why it matters
Added regression runtime 3 cases; about 3.8 s combined The reported cost is relevant to the repository’s per-PR test budget.

Merge-risk options

Maintainer options:

  1. Separate cross-store completion (recommended)
    Scope joined completion to the row’s active physical-store read and prove that a second store’s description finishes while the first store remains held.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Scope bulk completion to each target row or physical-store read while retaining same-row deduplication, and add a two-store held-first-worker regression that proves the second store’s description finishes before the first is released.

Technical review

Best 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:

  • [P2] Keep exact reads independent of unrelated stores — src/gateway/session-row-projection-refresh.ts:216-218
    Every selected row receives this one bulk completion promise. The facts reader awaits physical-store groups sequentially, so holding the first store also stalls sessions.describe for a ready row in a later store. This is the prior review’s still-unfixed finding; scope the join to the target read and cover two stores.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5b384871ea62.

Labels

Label changes:

  • add merge-risk: 🚨 availability: Merging the shared bulk promise can stall a ready store’s description behind an unrelated held worker read.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The remaining defect is a bounded cross-store description stall in an otherwise useful Gateway repair.
  • merge-risk: 🚨 availability: Merging the shared bulk promise can stall a ready store’s description behind an unrelated held worker read.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The added regression drives the production session-row projection through its real SQLite worker reader with a held response; after release, the foreground description returns the updated row with one read per key. The contributor also reports 10/10 recap passes on the flaking macOS host. This proves the same-store path, while the separate two-store correctness finding remains; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The added regression drives the production session-row projection through its real SQLite worker reader with a held response; after release, the foreground description returns the updated row with one read per key. The contributor also reports 10/10 recap passes on the flaking macOS host. This proves the same-store path, while the separate two-store correctness finding remains; no stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/session-row-projection.worker-read.test.ts.
  • [P1] node scripts/run-vitest.mjs src/gateway/session-row-projection.prepared-read.test.ts.
  • [P1] pnpm tsgo:core.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof that a description for a later physical store completes while an unrelated earlier store’s worker response is held.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-23T21:58:00.916Z sha f13f6fe :: needs maintainer review before merge. :: none
  • reviewed 2026-09-24T08:41:06.805Z sha 67f520b :: blocked before merge. :: [P2] Keep exact reads independent of unrelated stores

…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.
@steipete
steipete force-pushed the fix/recap-describe-flake branch from f13f6fe to 67f520b Compare September 24, 2026 08:32
@steipete

steipete commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

CI run 35975857019 failed checks-node-changed-extensions-bundle-13 in extensions/codex/src/app-server/side-question.execution.test.ts:

  • scopes side-turn abort cleanup when its startup interrupt fails with a retained peer
  • scopes side-turn abort cleanup when its startup interrupt and client retirement fail

Both exhausted the 5s wait at line 160: Codex side harness did not write thread/fork. Classified unrelated to this change: the harness uses a mocked shared Codex app-server client, and the side-question path does not import the Gateway session-row projection. The only other failed job was the aggregate CI gate.

On a fresh Linux Blacksmith Testbox at 67f520b1c42a748ebc17ea29e3dfce5bde8de705, five sequential full-file runs passed: 1 PASS, 2 PASS, 3 PASS, 4 PASS, 5 PASS (10 tests each). The failure did not reproduce; no code changed. The lease was stopped.

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 thread/fork wait; the hosted shard reported 309 passed / 2 failed. Landing is stopped. No second rerun, code change, or merge was attempted.

…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.
@steipete
steipete merged commit 1384db1 into main Sep 24, 2026
206 of 209 checks passed
@steipete
steipete deleted the fix/recap-describe-flake branch September 24, 2026 13:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant