Skip to content

fix: resume interrupted work when new messages arrive after restart - #147486

Merged
steipete merged 1 commit into
mainfrom
codex/restart-recovery-continuation
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/restart-recovery-continuation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes interrupted work becoming stuck with “restart recovery claim changed before agent adoption” when a new message arrives after a Gateway restart.

User Impact

The interrupted turn resumes from its saved context, and new messages use the existing follow-up queue while recovery owns the session. The agent is told that the restart did not cancel the task and to check current state, reconcile uncertain tool outcomes, and continue without asking the user to repeat the request.

Why This Change Was Made

Prompt preparation was clearing the durable interruption flag before the agent adopted its run. A subsequent claim conflict could then remove recovery state while leaving the old delivery claim behind. Prompt hints now leave durable state to the recovery owner, and foreground admission starts the existing recovery path before taking ownership of new work.

Existing delivery authority, permissions, reset behavior, and tombstone handling are preserved. No configuration or schema migration is required.

Evidence

  • Reproduced the lost-continuation regression against the original code using real isolated SQLite; it passes with the fix.
  • 461 focused tests passed across session hints, turn admission, recovery claims, reply context, and startup recovery. A final 57-test rerun also passed.
  • Full build, production and test type checks, targeted lint, formatting, and required repository guards passed.
  • Independent review found no actionable P0–P2 findings.
  • Recovery admission tests exercise real session leases and handoffs with a mocked recovery dispatch boundary. No new live restart or deployment was performed for validation.

Keep durable restart state with its recovery owner instead of consuming it during prompt preparation. Resume the interrupted turn through the existing Gateway recovery path before admitting new work, and direct the agent to reconcile current state and continue the original task.
@clawsweeper

clawsweeper Bot commented Sep 13, 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 agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 22:33
@steipete steipete self-assigned this Sep 13, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 6:41 PM ET / 22:41 UTC.

ClawSweeper review

What this changes

The PR preserves durable interruption state during prompt preparation, starts existing restart recovery before admitting new messages, and updates continuation instructions and regression coverage.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main retains the reported early interruption-flag clearing, and no verified merged replacement was established. No actionable correctness defect was found in the introduced changes.

Priority: P1
Reviewed head: 8de4c78490978d62403cdfb38047d1c891198fa2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies this as maintainer-authored, so the ordinary external-contributor proof gate does not apply. Reply admission and state preservation have reported SQLite and lease tests with mocked recovery dispatch; no after-fix live restart is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies this as maintainer-authored, so the ordinary external-contributor proof gate does not apply. Reply admission and state preservation have reported SQLite and lease tests with mocked recovery dispatch; no after-fix live restart is claimed.
Evidence reviewed 6 items Current main still contains the defect mechanism: At fetched main, applySessionHints clears abortedLastRun during prompt preparation. The later restart-recovery claim controller rejects an unrelated new run while the previous delivery claim remains active, and foreground-owner release can clear recovery state once the interruption flag is false.
Latest-release comparison: The supplied latest release, v2026.9.4, also clears the durable interruption flag in prompt preparation; this inspection does not establish an already-shipped fix.
Introduced admission behavior: The new branch releases its preliminary admission, invokes the existing recovery operation with the expected session and delivery-claim identities, checks database and Gateway lifecycle continuity, then reloads admission state. Heartbeat, reset, and tombstone handling remain separate.
Findings None None.
Security None None.

How this fits together

OpenClaw’s reply admission layer coordinates incoming messages with active and interrupted agent work. Restart recovery uses saved session state and transcripts to resume work while subsequent messages wait in the existing follow-up queue.

flowchart TD
  A[Incoming message] --> B[Reply admission]
  C[Saved interrupted session] --> B
  B --> D{Recovery pending?}
  D -->|Yes| E[Existing recovery owner]
  E --> F[Resume saved task]
  D -->|No| G[Normal reply processing]
  E --> H[Queue new messages]
  H --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -5, Tests +259, Docs +6. Total +260 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 80 85 -5
Tests 4 304 45 +259
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 390 130 +260

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net −5 lines; tests net +259 lines The repair removes a competing state writer while adding coverage for recovery ownership and admission ordering.

Technical review

Best possible solution:

Keep interruption state under the existing recovery owner until adoption or settlement, with new messages using the established follow-up queue.

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

Yes, from source: prepare a new message against an interrupted session with an existing delivery claim, then fail adoption and release its foreground owner. Current main clears the interruption marker too early; this review did not execute that sequence.

Is this the best way to solve the issue?

Yes. Removing prompt preparation’s durable write and invoking the existing recovery owner addresses the lifecycle conflict without introducing another recovery mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The reported defect strands interrupted agent work when a new message arrives after restart.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies this as maintainer-authored, so the ordinary external-contributor proof gate does not apply. Reply admission and state preservation have reported SQLite and lease tests with mocked recovery dispatch; no after-fix live restart is claimed.

Label justifications:

  • P1: The reported defect strands interrupted agent work when a new message arrives after restart.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies this as maintainer-authored, so the ordinary external-contributor proof gate does not apply. Reply admission and state preservation have reported SQLite and lease tests with mocked recovery dispatch; no after-fix live restart is claimed.

Evidence

What I checked:

  • Current main still contains the defect mechanism: At fetched main, applySessionHints clears abortedLastRun during prompt preparation. The later restart-recovery claim controller rejects an unrelated new run while the previous delivery claim remains active, and foreground-owner release can clear recovery state once the interruption flag is false. (src/auto-reply/reply/body.ts:32, c92ce0278f4a)
  • Latest-release comparison: The supplied latest release, v2026.9.4, also clears the durable interruption flag in prompt preparation; this inspection does not establish an already-shipped fix. (src/auto-reply/reply/body.ts:32, 3a9d69db306c)
  • Introduced admission behavior: The new branch releases its preliminary admission, invokes the existing recovery operation with the expected session and delivery-claim identities, checks database and Gateway lifecycle continuity, then reloads admission state. Heartbeat, reset, and tombstone handling remain separate. (src/auto-reply/reply/reply-turn-admission.ts:438, 8de4c7849097)
  • Existing owner and queue contracts: Recovery revalidates the exact saved target before acquiring its named admission and hands that admission to execution. Existing reply queue selection recognizes that owner and queues follow-ups instead of steering the recovered run. The patch adds no schema, configuration, plugin API, or dependency contract. (src/agents/main-session-recovery/main-session-restart-recovery-runtime.ts:176, 8de4c7849097)
  • Regression coverage and proof limits: The added cases exercise preserved SQLite recovery state, successful or concurrent recovery ownership, follow-up waiting, and bounded behavior when recovery does not start. The captured PR body reports 461 focused tests and a final 57-test rerun, with recovery dispatch mocked and no live restart performed. Captured context identity: 186de1c0fe0a866f713034fabdc83e9b340f95c371f4d9ff9176c83b8ef791f7. This read-only review did not execute tests. (src/auto-reply/reply/reply-turn-admission.test.ts:163, 8de4c7849097)
  • Area-history routing: Current-main path history identifies repeated reply-admission and recovery work by Peter Steinberger, alongside related work by Jesse Merhi and Shakker. Exact source-line introduction was not established; these are routing signals. (src/auto-reply/reply/reply-turn-admission.ts, c92ce0278f4a)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jesse Merhi: 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.

@steipete
steipete merged commit 5dc800b into main Sep 13, 2026
261 checks passed
@steipete
steipete deleted the codex/restart-recovery-continuation branch September 13, 2026 22:49
@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 14, 2026
Keep durable restart state with its recovery owner instead of consuming it during prompt preparation. Resume the interrupted turn through the existing Gateway recovery path before admitting new work, and direct the agent to reconcile current state and continue the original task.
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 gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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