Skip to content

fix: keep concurrent session starts from failing history reads - #188073

Merged
steipete merged 1 commit into
mainfrom
codex/restart-acceptance-regression
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/restart-acceptance-regression

Conversation

@steipete

@steipete steipete commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes agent turns failing with Session entry changed during read when several sessions start concurrently in a shared session store, before restart acceptance can reach its restart checks.

Related: #187989.

User Impact

Concurrent starts can finish loading history and produce replies. Ordinary slow history reads continue to let transcript writers progress. When both optimistic reads lose to writes, one final bounded read holds the existing writer admission; queued writes can wait for that read. No configuration, schema, stored-data, dependency, or upgrade changes.

Why This Change Was Made

Bisect identifies 8bc631709922a7f994253aef52cddf74e627745f (#187989) as the first bad commit; its direct parent 9abf96a0ac1e53ceb5a1bdbf302452b5b50ac8b5 passes the unchanged restart acceptance test. In session-transcript-read-cohort.ts, the second database-wide mutation conflict was rethrown at line 54, turning normal concurrent activity into a terminal turn failure.

Keep the two optimistic attempts, then reread under the existing FIFO admission when both were overtaken. Recheck the live owner, current authority, and freshly captured mutation witness after the awaited read and before consuming. Consume only once. Physical replacement, revocation, cancellation, or a native write that bypasses admission still refuses unsafe consumption.

The existing model-context writer-progress test now performs two real transcript writes and verifies that the consumer receives the newest content once. Production: +12 lines; tests: -2 lines; docs: +2 lines. The simplify pass retained one read owner and no new state.

Evidence

  • Unchanged main 264adfe194c1 and first bad 8bc631709922: the original restart acceptance fails during initial setup with Session entry changed during read; direct parent 9abf96a0ac1e passes. All nine bisect probes completed; no setup/build failures were treated as product verdicts.
  • Focused repeated-contention regression: red on unchanged main with SessionEntryChangedDuringReadError; green with this fix.
  • Exact head: 66 tests pass across session-transcript-context-read.worker.test.ts, session-transcript-anchor-read.worker.test.ts, and session-manager-model-context-snapshot.test.ts (two shards, 51.83 seconds including orchestration).
  • Targeted session-owner TypeScript check, targeted lint, formatting, line-cap/max-lines/test-lines/assertion-safety ratchets, and git diff --check: pass. No budget or baseline changes.
  • Local Codex autoreview, base 264adfe194c1 to the local snapshot committed as de60b653589e062be2c68a8b4833f8729c8dfe05: scoped-clean at P0 only; no accepted/actionable P0 findings. Maintainer review remains pending.
  • Exact head de60b653589e062be2c68a8b4833f8729c8dfe05: the unchanged restart acceptance passes (1 test, 61.39 seconds including transformation; test execution 36.92 seconds), including both graceful replacement cycles, FIFO queued inputs, and lossy SIGKILL behavior.
  • Exact-head PR CI: run 40998119782 completed successfully. Both reported required openclaw/ci-gate checks are SUCCESS. The PR is ready and mergeable; not merged.

All Gateway tests use isolated state and ports with the synthetic Responses provider. No live Gateway, deployment, or release changes.

After two optimistic history reads lose to writes, perform one fresh read under the existing writer admission. Preserve live authority and mutation checks and consume only once. This restores concurrent starts in shared session stores without blocking writers on ordinary slow reads.
@clawsweeper

clawsweeper Bot commented Oct 30, 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 size: S labels Oct 30, 2026
@steipete
steipete marked this pull request as ready for review October 30, 2026 03:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T03:36:07.443265Z de60b65 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

After two history reads conflict with writes, this PR performs one fresh read under the existing writer admission.

Example: Transcript writes containing later-0 and later-1 overtake the first two model-context reads.

  • Before: The second conflict throws SessionEntryChangedDuringReadError before the consumer runs.
  • After: A final serialized read includes later-1 and invokes the consumer once.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and appears correct; confidence rests on inspected production-path regression coverage and reported acceptance results rather than independently inspectable runtime output.
Proof confidence 🦐 gold shrimp (3/6) The host identifies this PR as maintainer-authored, so the ordinary contributor proof gate does not apply; supplied evidence reports real-worker contention coverage and isolated Gateway acceptance with a synthetic provider, without a separate runtime artifact.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Agent turns can fail while loading history when other sessions write to their shared store.
Reason: The source confirms a normal-concurrency failure, and the maintainer-authored direction explicitly accepts the bounded writer wait needed to restore progress without changing configuration or storage contracts.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a source-confirmed concurrent-start regression still present on current main, and review found no actionable introduced defect.

Priority: P1
Reviewed head: de60b653589e062be2c68a8b4833f8729c8dfe05

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session hydration and prepared model-context loading share a read-and-accept operation between SQLite history workers and synchronous consumers, using the existing writer FIFO and mutation witnesses.

flowchart TD
  A[Session history request] --> B[Capture mutation witnesses]
  B --> C[Read outside writer admission]
  C --> D[Validate under writer admission]
  D -->|First conflict| B
  D -->|Second conflict| E[Fresh read under writer admission]
  E --> F[Recheck owner and witnesses]
  D -->|Unchanged| G[Consume once]
  F --> G
Loading

Technical review

Best possible solution:

Keep the two optimistic reads and use the existing writer owner for one final fresh read while preserving all acceptance checks.

Do we have a high-confidence way to reproduce the issue?

Two writes overtaking the two optimistic reads reach the terminal throw on current main; the revised regression exercises that sequence, and the author reports red-on-base/green-on-head results, but this read-only review executed no target code.

Is this the best way to solve the issue?

This is a focused repair in the existing shared owner: the fallback obtains a fresh snapshot under admission rather than accepting stale data or replaying the consumer, and every changed hunk serves that invariant.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 315380c47895.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Raw commit 8bc6317 adds src/config/sessions/session-transcript-read-cohort.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8bc631709922; files: src/config/sessions/session-transcript-read-cohort.ts)

PR surface

Source +12, Tests -2, Docs +2. Total +12 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 31 19 +12
Tests 1 29 31 -2
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 64 52 +12

Labels

Label changes:

  • add P1: Normal concurrent session starts can terminate agent turns before replies, and the responsible second-conflict failure remains on current main.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Normal concurrent session starts can terminate agent turns before replies, and the responsible second-conflict failure remains on current main.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 29, 2026, 11:57 PM ET / October 30, 2026, 03:57 UTC.

@steipete
steipete merged commit f0586d2 into main Oct 30, 2026
225 of 227 checks passed
@steipete
steipete deleted the codex/restart-acceptance-regression branch October 30, 2026 04:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
…failing (openclaw#188073)

openclaw#187989 (570a3bf, "keep slow history reads from blocking transcript writes") made the bounded history-read owner rethrow on a second mutation conflict (session-transcript-read-cohort). Concurrent session starts then failed with SessionEntryChangedDuringReadError. That broke the restart acceptance e2e (test/gateway-restart-resume.e2e.test.ts) and test/gateway-restart-handoff.e2e.test.ts on main, and any production path that starts sessions concurrently.

The read now makes two optimistic attempts, then one fresh bounded read under the existing writer admission, rechecking authority before consuming once. Accepted tradeoff: under repeated contention, the final bounded read briefly holds the writer queue.

Proof at exact head de60b65: bisect from 4e2e6c6 (good) to main (bad) found 570a3bf as first bad, and its parent passes. The unchanged acceptance e2e is red on main and on the culprit, green here (1 passed). The owner regression ("repeated contention") is red with SessionEntryChangedDuringReadError before the fix and green after. Owner and consumer suites pass (66 tests); targeted typecheck, lint, format and ratchets pass. Exact-head CI succeeded, both ci-gate checks SUCCESS. Production +12 LOC.
roboclaw-bot added a commit that referenced this pull request Oct 31, 2026
…188947)

Related: #187989

## What Problem This Solves

Fixes a model-context CI test failing intermittently when transcript projection writes overlap its second read.

## User Impact

The fixture reliably checks the intended two-read contract. There is no user-visible runtime change.

## Why This Change Was Made

#187989 moved slow history reads outside writer admission and updated this test to expect refreshed messages after one retry. The native rewrite also schedules background projection reconciliation; those later writes can legitimately trigger the serialized fallback added by #188073. The fixture now joins that reconciliation before returning its first stale read. The exact two-call assertion and both refreshed-message checks remain unchanged.

## Evidence

- Directed scheduling reproduces the original expected-2/received-3 failure; the same qualifier passes with exactly two reads after the fix.
- 66 real-worker tests pass across the changed file and its two sibling suites on Node 24.22.1 and repository-pinned Bun.
- Scoped typecheck, lint, format, four ratchets and whitespace checks pass. Test count and test-line ceiling are unchanged.
- Fresh independent canonical P0–P2 autoreview: scoped-clean, no findings.
- Test-only change; production retries, timeouts and assertions are preserved. The historical CI scheduler interleave is unobserved; the controlled projection-write cause is proven.

Requested by @steipete

## Work sessions

[Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/b5679712-7777-4ff7-a05a-81c1efab2069)

Co-authored-by: steipete <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…penclaw#188947)

Related: openclaw#187989

## What Problem This Solves

Fixes a model-context CI test failing intermittently when transcript projection writes overlap its second read.

## User Impact

The fixture reliably checks the intended two-read contract. There is no user-visible runtime change.

## Why This Change Was Made

openclaw#187989 moved slow history reads outside writer admission and updated this test to expect refreshed messages after one retry. The native rewrite also schedules background projection reconciliation; those later writes can legitimately trigger the serialized fallback added by openclaw#188073. The fixture now joins that reconciliation before returning its first stale read. The exact two-call assertion and both refreshed-message checks remain unchanged.

## Evidence

- Directed scheduling reproduces the original expected-2/received-3 failure; the same qualifier passes with exactly two reads after the fix.
- 66 real-worker tests pass across the changed file and its two sibling suites on Node 24.22.1 and repository-pinned Bun.
- Scoped typecheck, lint, format, four ratchets and whitespace checks pass. Test count and test-line ceiling are unchanged.
- Fresh independent canonical P0–P2 autoreview: scoped-clean, no findings.
- Test-only change; production retries, timeouts and assertions are preserved. The historical CI scheduler interleave is unobserved; the controlled projection-write cause is proven.

Requested by @steipete

## Work sessions

[Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/b5679712-7777-4ff7-a05a-81c1efab2069)

Co-authored-by: steipete <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Backport #188073 from main, source commit
f0586d2. Repeated transcript
mutations currently exhaust both optimistic reads and abort restart
recovery with SessionEntryChangedDuringReadError before replying.

After two contended attempts, make one fresh bounded read under the
existing writer admission. Recheck owner authority and the snapshot
before consuming once. The accepted tradeoff is briefly holding the
writer queue after repeated contention.

Release adaptation: preserve the release's session-scoped write receipts
and target interface rather than restoring the source's database-wide
receipt. Update the existing same-session mutation test to expect the
third read while retaining rejection and zero consumption. No schema,
configuration, grant, or permission changes.

The unchanged signed-in-person restart E2E is red on 8142a61 and green
with this patch (22.359s). The deterministic owner regression is red
without the fallback. Both owner suites pass (18 tests), including on
base 50fde57. Targeted typecheck,
lint, formatting and diff checks pass for the patch.

(cherry picked from commit f0586d2)

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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