Skip to content

fix: keep chat sends working during concurrent session updates - #166027

Merged
steipete merged 2 commits into
mainfrom
steipete/w193-session-facts-race
Oct 6, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/w193-session-facts-race

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes chat.send failing with GatewaySessionFactsChangedDuringReadError when 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 667c4ab22 at 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.

Changed test file Node 24 wall time Pinned Bun wall time Hosted CI wall time
session-utils-store-lookup.freshness.test.ts (7 tests) 39.310 s 28.721 s 35.89 s

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_MS in voice-call code and modelCatalogRuntime.loadManifestModelCatalog. A clean detached current-main checkout at d3c121c23788c8b81d556b6455bc50e6c73e1631 reproduces 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 at d16ef4f4f3e2b278e0b232427cade40190408c52; 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.

@clawsweeper

clawsweeper Bot commented Oct 6, 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 docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 6, 2026
@steipete
steipete marked this pull request as ready for review October 6, 2026 08:49
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 5:06 AM ET / 09:06 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: d16ef4f4f3e2b278e0b232427cade40190408c52

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful concurrency proof and no actionable introduced defects.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured body connects the changed session-read owner to signed Control UI protocol clients exercising concurrent chat.send preparation on Node and pinned Bun, reporting 73 completed replies and zero errors after the fix. The disabled-fix regression is supplemental. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body connects the changed session-read owner to signed Control UI protocol clients exercising concurrent chat.send preparation on Node and pinned Bun, reporting 73 completed replies and zero errors after the fix. The disabled-fix regression is supplemental. No stored-data contract changes require migration proof.
Evidence reviewed 9 items Pinned introduced change: The merge-base-to-head patch changes only the bounded reread ordering, its regression, and documentation; it does not introduce configuration, schema, dependency, or permission changes.
Current main still needs the fix: Fetched main computes ordering before the retry loop, leaving an ordinary metadata reread speculative. Its existing retry bound can therefore be exhausted by a second publication.
Existing ordering and freshness owner: The ordered reader acquires the existing writer queues, retains physical reader owners, checks native mutations and publications around awaited reads, and requires synchronous consumption. The patch preserves discovery checks, one retry, and rejection after consumption begins.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +67, Docs +1. Total +68 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 69 2 +67
Docs 1 4 3 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 76 8 +68

Review metrics

Metric Value Why it matters
Regression runtime New case 1.057 s; changed suite 35.89 s in hosted CI The reported suite cost includes compiled-worker preparation and protects a real writer-ordering race.

Technical review

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Ordinary concurrent session updates can terminate chat-send preparation, with failures observed through the real Gateway protocol.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body connects the changed session-read owner to signed Control UI protocol clients exercising concurrent chat.send preparation on Node and pinned Bun, reporting 73 completed replies and zero errors after the fix. The disabled-fix regression is supplemental. No stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body connects the changed session-read owner to signed Control UI protocol clients exercising concurrent chat.send preparation on Node and pinned Bun, reporting 73 completed replies and zero errors after the fix. The disabled-fix regression is supplemental. No stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head patch changes only the bounded reread ordering, its regression, and documentation; it does not introduce configuration, schema, dependency, or permission changes. (src/gateway/session-utils-store-lookup.ts:427, d16ef4f4f3e2)
  • Current main still needs the fix: Fetched main computes ordering before the retry loop, leaving an ordinary metadata reread speculative. Its existing retry bound can therefore be exhausted by a second publication. (src/gateway/session-utils-store-lookup.ts:323, 2277f76df6a0)
  • Existing ordering and freshness owner: The ordered reader acquires the existing writer queues, retains physical reader owners, checks native mutations and publications around awaited reads, and requires synchronous consumption. The patch preserves discovery checks, one retry, and rejection after consumption begins. (src/config/sessions/session-entry-read-ordered.ts:28, d16ef4f4f3e2)
  • Real chat entrypoint: Ordinary chat-send preparation invokes the shared Gateway session reader without membership ordering, establishing the affected speculative-read path. Later admission remains responsible for current caller and session authority. (src/gateway/server-methods/chat-send-session.ts:230, d16ef4f4f3e2)
  • Meaningful race regression: The added test injects real metadata writes through the production admission owner after snapshot capture, awaits queue drainage, and asserts that fresh metadata is consumed before the next queued write. Existing cases retain native-write exhaustion and no-replay coverage. (src/gateway/session-utils-store-lookup.freshness.test.ts:123, d16ef4f4f3e2)
  • Captured runtime proof and test cost: The captured PR body reports two baseline failures in five measured Bun sends, followed by Node 26 and pinned Bun trials using signed Control UI protocol clients: 73 sends, 73 completed replies, zero errors, and acknowledged shutdowns. It also reports the intended regression failing with the fix disabled and 60 focused tests passing. The changed suite's hosted wall time was 35.89 seconds, including compiled-worker preparation; the new regression took 1.057 seconds. These are contributor-reported observations, not reviewer executions. (d16ef4f4f3e2)

Likely related people:

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

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 (1 earlier review cycle)
  • reviewed 2026-10-06T08:55:22.936Z sha d16ef4f :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 74a5b14 into main Oct 6, 2026
203 of 205 checks passed
@steipete
steipete deleted the steipete/w193-session-facts-race branch October 6, 2026 09:08
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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