Skip to content

fix: keep slow history reads from blocking transcript writes - #187989

Merged
RomneyDa merged 2 commits into
mainfrom
fix/history-read-writer-admission
Oct 30, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
fix/history-read-writer-admission

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: a slow history read can stall transcript writes behind it for the entire history-worker timeout.

User Impact

Bounded hydration and prepared model-context reads no longer reserve the database writer while awaiting a worker response. Existing source, authority, mutation and synchronous-consumer checks remain enforced. No configuration change or data migration is required.

Why This Change Was Made

An incident trace showed a history hydration read holding the writer for 59,999 ms while a transcript append queued behind it for 59,975 ms. This establishes head-of-line blocking, not a circular deadlock or the underlying cause of the worker timeout.

The two affected paths now share one small read/accept operation: capture the existing mutation witnesses under writer admission, perform the read outside that reservation, then reacquire admission and validate before synchronous consumption. An intervening mutation retries the read once; continued mutation rejects it without invoking the consumer. Already-owned writer execution keeps its existing custody.

Scope is deliberately limited: this does not repair filesystem fragmentation, change SQLite durability, remove whole-file snapshots, or change other ordered-read paths. It has not been deployed to the incident server.

Evidence

  • Regression reproduced on the base: both hydration cases failed the writer-progress assertion while the real worker reply was held.
  • Real SQLite/worker regressions cover writer progress, rejection of an obsolete hydration result followed by a fresh read, and the separate prepared model-context path. Existing sibling suites cover physical replacement, closed readers, fenced appends/removes and retained actor context.
  • Core and agent/session test TypeScript graphs pass; focused lint passes; changed-page MDX check and staged whitespace check pass. The test-line ratchet passes.
  • Final focused run: 36 tests passed across 3 files (2 actor-context reuse tests plus 34 hydration/model-context worker tests); compiler-generation verification passed. Command: node scripts/run-vitest.mjs src/config/sessions/session-transcript-anchor-read.worker.test.ts src/config/sessions/session-transcript-context-read.worker.test.ts src/config/sessions/session-actor-transcript-reuse.test.ts --maxWorkers=1.
  • Author simplification pass: removes duplicated async writer reservations and shares only the read/accept protocol; no new state owner, queue, schema or configuration. The necessary growth is concurrency validation and three regression cases (148 net test lines, with a scoped allocation). Against the base: production +92/−48, tests +150/−2, documentation +7, allocation +2.

Review and qualification limits

Independent review of the production patch and the subsequent consumer-test repair found no actionable blocking findings. Reviews were diff/evidence-based; the author separately inspected the ownership contracts and verified test results. Real-provider/Gateway end-to-end validation is not claimed; current-head PR CI remains pending.

Earlier checks exposed and corrected a required-environment type mismatch and test lint issues. An intermediate run passed all 36 assertions but was invalidated because source changed before the worker-generation verification; it is not counted as the final passing run.

CI repair: run 40983725167 exposed three stale model-context consumer expectations. The tests now require refreshed contents after the bounded retry rather than a rejection or stale snapshot. All 32 tests in that consumer suite passed, as did its targeted TypeScript graph, lint, format, and the test-line ratchet. The failed CI receipt is retained; it is not relabeled green.

Release writer admission while bounded history workers run, then validate
existing source and mutation witnesses before synchronous consumption.
Retry one intervening mutation without repeating the consumer.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
@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: M labels Oct 30, 2026
@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. labels Oct 30, 2026
@RomneyDa
RomneyDa marked this pull request as ready for review October 30, 2026 01:05
Update three consumer expectations for the bounded retry contract; assert refreshed content and two reads. CI failure retained from run 40983725167; the repaired 32-test consumer suite, focused lint, format and test types pass.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 30, 2026
@RomneyDa
RomneyDa enabled auto-merge (squash) October 30, 2026 01:19
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR releases writer admission while bounded transcript hydration and prepared model-context reads await workers, then validates results before consumption.

Example: A history hydration read takes 59,999 ms while a transcript append queues behind it.

  • Before: The incident trace reported the append waiting 59,975 ms for writer admission.
  • After: The append can proceed during the read; an intervening mutation causes one fresh read before consumption.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation appears correct, but supplied tests do not meet the requested real-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Transcript appends can stall for the duration of a slow history read.
Reason: A source-confirmed scheduling defect affects normal transcript progress, and the maintainer-authored direction preserves the existing storage and authority owners.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses writer blocking still present on main, and inspection found no concrete introduced correctness defect.

Priority: P1
Reviewed head: 8ae9328389bfadcc44069a1417dcf9ffa8bb9389

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied isolated Gateway run demonstrates transcript appends progressing while an affected history read is delayed.
Agent review details

How this fits together

SessionManager requests transcript snapshots from SQLite history workers; writer admission orders mutation checks and synchronous publication of accepted snapshots.

flowchart TD
  A[SessionManager request] --> B[Capture mutation witnesses]
  B --> C[History worker read]
  C --> D[Reacquire writer admission]
  D --> E[Validate source and witnesses]
  E --> F[Synchronous consumer]
  E -->|First mutation| B
Loading

Technical review

Best possible solution:

Keep the shared read-and-accept operation using the existing writer, receipt, reader, and mutation owners.

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

Current main visibly holds writer admission across the worker await; the author reports base-failing regressions, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch removes the blocking reservation while retaining synchronous acceptance and existing freshness checks; the shared helper serves both affected callers without introducing another state owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1ae91fa20263.

Provenance checked

  • Bounded hydration admission changes intended behavior with a stated reason (1b19614: Combine fresh transcript bytes and replay metadata under FIFO custody with synchronous consumption and native mutation validation.)
  • Prepared model-context admission changes intended behavior with a stated reason (ab5fd51: Carry the selected execution owner into bounded context preparation and preserve source, mutation, and live-authority checks.)
  • Resident transcript reuse keeps the original intent (55de901: Reuse the current replica without creating another retained transcript owner, while preserving fences and detached results.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +44, Tests +152, Docs +7, Other +2. Total +205 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 92 48 +44
Tests 3 161 9 +152
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 8 262 57 +205

Review metrics

Metric Value Why it matters
Production versus test LOC Production +92/-48; tests +161/-9 Growth implements one shared acceptance protocol and regressions for writer progress, stale hydration, and the distinct model-context consumer.

Labels

Label changes:

  • add P1: The reported incident and current source establish transcript writes waiting behind a history read for almost a minute.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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: The reported incident and current source establish transcript writes waiting behind a history read for almost a minute.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Provide sanitized output from an isolated Gateway exercising the changed scheduling behavior.

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, 9:29 PM ET / October 30, 2026, 01:29 UTC.

@RomneyDa
RomneyDa merged commit 8bc6317 into main Oct 30, 2026
126 of 127 checks passed
@RomneyDa
RomneyDa deleted the fix/history-read-writer-admission branch October 30, 2026 01:37
steipete added a commit that referenced this pull request Oct 30, 2026
…failing (#188073)

#187989 (8bc6317, "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 9344233 (good) to main (bad) found 8bc6317 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.
@steipete

Copy link
Copy Markdown
Contributor

Heads-up: this change made the bounded history-read owner rethrow on a second mutation conflict, so concurrent session starts failed with SessionEntryChangedDuringReadError. Bisecting from 9344233 found 8bc6317 as the first bad commit, and its parent passes. It broke test/gateway-restart-resume.e2e.test.ts and test/gateway-restart-handoff.e2e.test.ts on main.

The fix is #188073 (f0586d2). It keeps two optimistic reads, then does one fresh bounded read under the existing writer admission and rechecks authority before consuming. Under repeated contention the writer queue is held briefly during that final read. The intent of this PR, keeping slow history reads from blocking transcript writes, is otherwise preserved.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
…w#187989)

* fix: keep slow history reads from blocking transcript writes

Release writer admission while bounded history workers run, then validate
existing source and mutation witnesses before synchronous consumption.
Retry one intervening mutation without repeating the consumer.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>

* test: verify refreshed model context after admitted read retry

Update three consumer expectations for the bounded retry contract; assert refreshed content and two reads. CI failure retained from run 40983725167; the repaired 32-test consumer suite, focused lint, format and test types pass.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>

---------

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
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 17, 2026
* fix: keep slow history reads from blocking transcript writes

Release writer admission while bounded history workers run, then validate
existing source and mutation witnesses before synchronous consumption.
Retry one intervening mutation without repeating the consumer.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>

* test: verify refreshed model context after admitted read retry

Update three consumer expectations for the bounded retry contract; assert refreshed content and two reads. CI failure retained from run 40983725167; the repaired 32-test consumer suite, focused lint, format and test types pass.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>

---------

Co-authored-by: jalehman <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>

(cherry picked from commit 8bc6317)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants