Skip to content

fix: resume compacted turns after a Gateway restart - #160128

Merged
roboclaw-bot merged 8 commits into
mainfrom
openclaw/investigating-an-error
Sep 30, 2026
Merged

roboclaw-bot merged 8 commits into
mainfrom
openclaw/investigating-an-error

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: an unfinished conversation can fail with “Session transcript keyed user is outside the current turn” when a Gateway restart follows compaction.

User Impact

The built-in runtime can resume the accepted request without saving it twice, while still saving a distinct queued message. No configuration or database migration is required.

Why This Change Was Made

Compaction can summarize the current input out of model context without removing it from the transcript. Restart replay validates that durable input, but prompt submission reconstructs it when it is absent from model context. The reconstructed copy previously reached ordinary persistence and collided with the saved input.

Reuse the existing one-shot persistence suppression only after interrupted-turn replay preparation succeeds, and clear it when a differently keyed queued input arrives. The ordinary transcript turn guard and replay ownership revalidation remain unchanged. No new dispatcher, fallback, state, or replay key is introduced.

Evidence

  • A real SQLite cold-reopen regression reproduces the exact keyed-user error on unchanged production code after compaction removes the accepted input from model context. The repaired path preserves one durable original input, completed tool results, and the prior transcript prefix; a separate case verifies that queued steering is still saved.
  • Receiving verification after integrating the canonical CI repairs: 87/87 tests across the three replay/transcript-guard files pass (98.92 s command wall, Linux/Node 24.19.0). The five replay files are byte-identical to the previously reviewed head. These SQLite lifecycle tests exercise actual prompt submission and ownership changes, not only a predicate.
  • Independent P0–P2 autoreview is scoped-clean for the unchanged replay diff. Its selected changed-file gates pass, including core types, 27 core-test type graphs, formatting, lint, dead exports, runtime import cycles, and architecture guards.
  • The earlier Bun GC fixture failure was fixed on main in test: deflake Gateway waiter lifetime and Bun plugin retention fixtures #160200; the main version is preserved and that helper is no longer part of this PR. No CI planner or admission-limit changes are included.
  • Before the canonical CI repairs were integrated, the five-file replay candidate passed local manifest admission at 124 hybrid / 125 GitHub Node jobs, below the unchanged 130-job limit. That is retained planning evidence for the prior head, not current-head hosted completion; this PR changes neither the planner nor its limit.
  • The provider is mocked at the runtime boundary. No shared Gateway restart, live-model proof, configuration change, or database migration is claimed. Hosted CI and current-head bot review are checked before native landing.

Inherited CI failures and canonical repairs

The previous head's failed CI shard exposed two main-branch defects outside this replay change: an abort/reset fixture deadlock and a collector completion race that left scheduler capacity active. Both were independently reproduced on unmodified main.

Integrated the existing fixes rather than publishing a competing implementation: abort fixture commit 79f0e9bf127 and collector publication repair from #161019. On this combined source, the exact captured 25-file CI plan passes 376/376 cases (198.63 s), and the canonical publication owner's 21/21 cases pass (3.66 s). No skips, retry-to-green, weakened assertions, or CI-limit changes were used. These are local receiving results, not a hosted-CI success claim.

Qualification gap: during diagnosis, a discarded local collector candidate passed six full Stop-file runs, but its seventh stress run exited with native Node 24.19.0 heap corruption/SIGABRT. Core inspection located detection in V8 compilation during worker bootstrap; the corruption's cause remains unknown. That stress sequence stopped immediately and is not claimed green or fixed. The canonical upstream repair—not that candidate—is included here; normal current-head CI and review remain required.

Worked on by

Work sessions


View the OpenClaw team session

roboclaw-bot and others added 2 commits September 28, 2026 05:00
Reuse the validated persisted input when compaction has removed its model-context copy. Clear one-shot suppression for distinct queued inputs, preserving the transcript turn and ownership guards.

Co-authored-by: steipete <[email protected]>
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 9bb76237-cd52-47d4-8178-4be2a0fca461
@clawsweeper

clawsweeper Bot commented Sep 28, 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.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 28, 2026 05:03
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 7:35 PM ET / 23:35 UTC (Revision 4).

ClawSweeper review

What this changes

The branch repairs built-in agent replay after compaction and a Gateway restart, adds SQLite replay regression cases, and updates the compaction documentation.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main and the latest release still lack the replay repair, and review found no actionable defect in the proposed patch.

Priority: P2
Reviewed head: ab7203c4eee03a27022e8fba02e2fb7c0d4c744e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused repair has meaningful SQLite lifecycle proof and no identified patch defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The SQLite-backed production session manager is cold reopened after a compaction entry, then actual prompt submission completes without the keyed-user error, retains one durable original input, and saves a distinct queued steer. Provider streaming is mocked; the changed path does not alter a stored-data format.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The SQLite-backed production session manager is cold reopened after a compaction entry, then actual prompt submission completes without the keyed-user error, retains one durable original input, and saves a distinct queued steer. Provider streaming is mocked; the changed path does not alter a stored-data format.
Evidence reviewed 8 items Introduced replay repair: The pinned base-to-head patch arms one-shot user persistence suppression when an interrupted durable turn is prepared for replay.
Queued-input safeguard: The guard clears suppression when a queued user has a different replay key; the underlying guard consumes suppression on one user write.
Current-turn ownership: Replay preparation checks the live writer, transcript version, and original user anchor again before admission.
Findings None None.
Security None None.

How this fits together

The built-in agent runner restores a Gateway session from its SQLite transcript after a restart. Compaction can omit the accepted input from model context, so replay validation and the persistence guard must feed it to the model without saving it twice.

flowchart LR
A[Accepted user input] --> B[SQLite transcript]
B --> C[Compaction summary]
C --> D[Gateway restart]
D --> E{Current turn validated?}
E -->|Yes| F[Prompt persistence guard]
F --> G[Model continuation]
F --> H[Transcript without duplicate]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +12, Docs 0. Total +15 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 6 3 +3
Tests 2 73 61 +12
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 80 65 +15

Review metrics

Metric Value Why it matters
New replay scenarios 2 added The added cases cover compacted restart replay and persistence of queued steering afterward.

Technical review

Best possible solution:

Keep validated current-turn replay in the built-in agent runner so a compacted restart preserves one durable accepted input and writes later distinct inputs normally.

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

Yes, the checked-in SQLite cold-reopen fixture gives a concrete compaction-and-restart path to the keyed-user failure. This read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the existing one-shot persistence guard after validated replay, then clearing it for a distinct queued input, keeps the repair within the current transcript owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The SQLite-backed production session manager is cold reopened after a compaction entry, then actual prompt submission completes without the keyed-user error, retains one durable original input, and saves a distinct queued steer. Provider streaming is mocked; the changed path does not alter a stored-data format.

Label justifications:

  • P2: The repair addresses a specific interrupted-session failure after the less common compaction-and-restart sequence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The SQLite-backed production session manager is cold reopened after a compaction entry, then actual prompt submission completes without the keyed-user error, retains one durable original input, and saves a distinct queued steer. Provider streaming is mocked; the changed path does not alter a stored-data format.
  • proof: sufficient: Contributor real behavior proof is sufficient. The SQLite-backed production session manager is cold reopened after a compaction entry, then actual prompt submission completes without the keyed-user error, retains one durable original input, and saves a distinct queued steer. Provider streaming is mocked; the changed path does not alter a stored-data format.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Ayaan Zaidi: 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)

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 (3 earlier review cycles)
  • reviewed 2026-09-28T05:15:12.076Z sha 16ea974 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T06:15:06.400Z sha 0afdf46 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-30T22:05:09.586Z sha e1ad25a :: needs maintainer review before merge. :: none

@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) September 28, 2026 05:17
roboclaw-bot and others added 4 commits September 28, 2026 06:05
Keep the existing eight GC calls and all retention assertions, but invoke collection before resolving the immediate callback so Bun does not retain completed Promise frames during the collection.

Co-authored-by: steipete <[email protected]>
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 0dde0ca5-2371-4363-b454-6504a78a8052
Keep the original cold-restart replay repair and current main APIs. Preserve main’s already-landed Bun retention fixture repair, removing that helper from the PR delta.

Co-authored-by: steipete <[email protected]>
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 83686719-0a5c-4ba0-96b9-39e28eeb7125
@roboclaw-bot roboclaw-bot self-assigned this Sep 30, 2026
roboclaw-bot and others added 2 commits September 30, 2026 23:16
Use the canonical landed collector write-admission repair instead of publishing a competing local fix. The five-file replay repair remains byte-identical.

Co-authored-by: steipete <[email protected]>
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 30, 2026
@roboclaw-bot
roboclaw-bot merged commit 6dc7dbe into main Sep 30, 2026
247 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/investigating-an-error branch September 30, 2026 23:45
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
* fix: resume compacted turns after a Gateway restart

Reuse the validated persisted input when compaction has removed its model-context copy. Clear one-shot suppression for distinct queued inputs, preserving the transcript turn and ownership guards.

Co-authored-by: steipete <[email protected]>

* fix: resume compacted turns after a Gateway restart

Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 9bb76237-cd52-47d4-8178-4be2a0fca461

* test: collect plugin retention fixtures in native tasks

Keep the existing eight GC calls and all retention assertions, but invoke collection before resolving the immediate callback so Bun does not retain completed Promise frames during the collection.

Co-authored-by: steipete <[email protected]>

* fix: resume compacted turns after a Gateway restart

Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 0dde0ca5-2371-4363-b454-6504a78a8052

* fix: resume compacted turns after a Gateway restart

Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 83686719-0a5c-4ba0-96b9-39e28eeb7125

---------

Co-authored-by: steipete <[email protected]>
steipete added a commit that referenced this pull request Oct 1, 2026
Channel ingress saves the user's message before the run starts, so the
first attempt prepares a durable-turn replay and suppresses the runtime
re-append (#160128). The suppressed append never reported the message as
persisted, leaving the run's active-prompt fact stale. After timeout
compaction moved the saved message out of the current turn, the retry
re-sent the original keyed prompt, the transcript adopted the old row by
idempotency key, and the current-turn guard failed the reply. Fallback
candidates and worker re-placement read the same stale fact.

Report the replayed durable user through the existing persisted callback
when its append is suppressed, matching the adopted append it replaces.
The recorder already holds the turn, so no transcript write is added.
steipete added a commit that referenced this pull request Oct 1, 2026
… was already saved (#162260)

* fix(test): hold timeout recovery until the child handoff is leasable

The Gateway timeout-recovery subagent E2E released the held compaction as
soon as the child's execution row was terminal. On 2-core Linux runners
compaction then finished before the child's announce resolved, so the
announce found the recovered retry already active and steered the
completion into it as an internal event. The fixture provider only
recognizes the steering-queue form that a retry leases from a deferred
handoff, answered PARENT-OK, and the 90 s composite deadline expired.

Hold compaction until the child row is terminal/ok and its delivery is a
pending payload without an in-flight announce reservation, the predicate
the requester steering lease consumes. Assert that the first recovered
parent reply carries the child result, and name the stalled phase with
provider and handoff evidence when the composite budget expires.

* fix(agents): report replayed durable users as persisted

Channel ingress saves the user's message before the run starts, so the
first attempt prepares a durable-turn replay and suppresses the runtime
re-append (#160128). The suppressed append never reported the message as
persisted, leaving the run's active-prompt fact stale. After timeout
compaction moved the saved message out of the current turn, the retry
re-sent the original keyed prompt, the transcript adopted the old row by
idempotency key, and the current-turn guard failed the reply. Fallback
candidates and worker re-placement read the same stale fact.

Report the replayed durable user through the existing persisted callback
when its append is suppressed, matching the adopted append it replaces.
The recorder already holds the turn, so no transcript write is added.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
… was already saved (openclaw#162260)

* fix(test): hold timeout recovery until the child handoff is leasable

The Gateway timeout-recovery subagent E2E released the held compaction as
soon as the child's execution row was terminal. On 2-core Linux runners
compaction then finished before the child's announce resolved, so the
announce found the recovered retry already active and steered the
completion into it as an internal event. The fixture provider only
recognizes the steering-queue form that a retry leases from a deferred
handoff, answered PARENT-OK, and the 90 s composite deadline expired.

Hold compaction until the child row is terminal/ok and its delivery is a
pending payload without an in-flight announce reservation, the predicate
the requester steering lease consumes. Assert that the first recovered
parent reply carries the child result, and name the stalled phase with
provider and handoff evidence when the composite budget expires.

* fix(agents): report replayed durable users as persisted

Channel ingress saves the user's message before the run starts, so the
first attempt prepares a durable-turn replay and suppresses the runtime
re-append (openclaw#160128). The suppressed append never reported the message as
persisted, leaving the run's active-prompt fact stale. After timeout
compaction moved the saved message out of the current turn, the retry
re-sent the original keyed prompt, the transcript adopted the old row by
idempotency key, and the current-turn guard failed the reply. Fallback
candidates and worker re-placement read the same stale fact.

Report the replayed durable user through the existing persisted callback
when its append is suppressed, matching the adopted append it replaces.
The recorder already holds the turn, so no transcript write is added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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