Skip to content

fix: prevent internal recovery errors after queued turns - #164656

Merged
RomneyDa merged 5 commits into
mainfrom
openclaw/fix-restart-recovery-claim-error-exposure
Oct 5, 2026
Merged

RomneyDa merged 5 commits into
mainfrom
openclaw/fix-restart-recovery-claim-error-exposure

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: a queued Control UI turn could expose an internal restart-recovery ownership error after the preceding run was interrupted.

User Impact

An interrupted run no longer strands its queued successor. If recovery ownership changes in a way that cannot be transferred safely, the user sees conversation-change guidance instead of an internal claim diagnostic or an inaccurate claim that the Gateway is restarting.

Why This Change Was Made

OpenClaw records durable recovery ownership for admitted turns so work and delivery can be reconciled if the Gateway later restarts. The incident itself was not caused by openclaw update or a Gateway restart: the process stayed on the same PID while the active model/run was aborted and another Control UI turn was already queued.

The queued successor had been admitted in memory while the earlier run still owned the durable recovery record. When the successor began, admission treated that retained ownership as an impossible claim change and threw a generic error that was persisted verbatim as a failed-before-reply message.

This change transfers only an aborted, delivery-free Control UI recovery record to its queued successor in one guarded session-row update. Admission now distinguishes a committed handoff from a refused expected-state patch before adopting the returned row. A channel successor keeps the distinct recovery ID persisted for its ingress, so hook checkpoints, readiness checks, and cleanup all service the same claim. Other ownership changes use a typed lifecycle error handled at the reply boundary, keeping internal diagnostics in logs while telling the user that the conversation changed.

Evidence

  • Recovered the affected session and confirmed the sequence: active Control UI run, queued successor, active-run abort, then successor admission against the aborted predecessor's recovery record.
  • Both accepted ClawSweeper findings have failing-path regressions: mixed-ingress channel tracking, and an ownership replacement before successor transfer persistence.
  • pnpm test src/auto-reply/reply/restart-recovery-claim.successor.test.ts src/auto-reply/reply/restart-recovery-claim.test.ts src/auto-reply/reply/restart-recovery-claim.lifecycle.test.ts src/auto-reply/reply/agent-runner-core.test.ts --maxWorkers=1 — 59 tests passed in 76.61s.
  • pnpm test src/gateway/server.chat.acp-completion.test.ts --maxWorkers=1 — 12 tests passed in 61.15s after rebasing onto the upstream sharing-fence fix.
  • pnpm test src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts --maxWorkers=1 — 222 tests passed; two active-steering queue assertions outside this PR's changed paths failed on the earlier base. The recovery-admission regression in this file passed.
  • pnpm check:changed — passed on the final source, including line-cap ratchets, production/test typechecks, lint, dead exports, import cycles, and database guards.
  • AutoReview (Codex, P1) — scoped clean on the exact final diff.
  • ClawSweeper — platinum hermit on exact head fba69b0f817; no actionable findings.

@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 5, 2026, 2:15 PM ET / 18:15 UTC (Revision 5).

ClawSweeper review

What this changes

The PR lets queued turns inherit an interrupted Control UI recovery record, preserves channel recovery tracking, and replaces internal ownership errors with conversation-change guidance.

Merge readiness

⛔ Blocked before merge - 1 item remains

The prior handoff-refusal and channel-tracking findings are resolved. No remaining introduced correctness defect was found, and current main still lacks this repair. The Teams discussion identifies broader channel contention that this PR does not fully address.

Priority: P2
Reviewed head: fba69b0f817e895493033669b1804d9287615df7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful ownership regressions and both prior blockers addressed.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository MEMBER, so ordinary contributor runtime proof is exempt. The body records incident analysis and regression results rather than an after-fix live trace; source inspection confirms the refusal guard and adoption ordering. No schema or serialized data-model contract changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository MEMBER, so ordinary contributor runtime proof is exempt. The body records incident analysis and regression results rather than an after-fix live trace; source inspection confirms the refusal guard and adoption ordering. No schema or serialized data-model contract changes are introduced.
Evidence reviewed 8 items Pinned introduced change: Inspected the merge-base-to-head production hunks. The transfer is limited to an aborted running Control UI claim without pending delivery, hook state, or receipt state; channel successors retain their separately generated recovery ID.
Previous blocker repaired: The latest commit adds didCommit and rejects a refused admission patch even when the accessor returns the existing row. Its new regression replaces ownership before patch preparation, checks rejection, and verifies the replacement claim remains intact. GitHub's exact previous-head comparison confirms this repair.
Writer and execution contracts: A null prepared patch returns the existing session row, explaining why the explicit committed-patch check is necessary. The writer independently validates its prepared row before commit, and agent execution awaits recovery admission before invoking adoption or reply hooks.
Findings None None.
Security None None.

How this fits together

Reply admission connects incoming chat turns to durable session recovery records before agent execution. Those records subsequently govern reply-hook checkpoints, restart recovery, and cleanup.

flowchart TD
  A[Incoming or queued turn] --> B[Read session recovery record]
  B --> C[Check predecessor and ownership]
  C --> D[Guarded session write]
  D --> E[Agent execution and reply checkpoints]
  C --> F[Conversation-change guidance]
  D --> F
  E --> G[Recovery settlement and cleanup]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +76, Tests +229. Total +305 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 89 13 +76
Tests 4 230 1 +229
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 319 14 +305

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +76 lines; tests net +228 lines Production growth has a stated purpose: guarded ownership transfer and typed reply handling within the existing owner.

Stored data model

Persistent data-model change detected: serialized state: src/auto-reply/reply/restart-recovery-claim.ts, unknown-data-model-change: src/auto-reply/reply/restart-recovery-claim.ts. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

A Control UI queued-turn transcript would usefully corroborate the repaired user flow. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis verify the Control UI flow where a second chat turn is queued before the active turn is aborted; capture redacted transcript and diagnostic evidence that the successor replies without exposing an internal recovery-claim error.

Technical review

Best possible solution:

Keep recovery transfer in the existing guarded admission owner, while preserving broader active-channel contention as separate work.

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

Yes, from source: a distinct queued turn encountering an aborted running Control UI claim reaches the generic rejection on current main. Runtime execution was not performed during this read-only review.

Is this the best way to solve the issue?

Yes. The patch repairs the existing admission owner and distinguishes a refused write from a committed handoff; expanding it to active channel predecessors would require a separate, evidenced repair.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • 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 author is a repository MEMBER, so ordinary contributor runtime proof is exempt. The body records incident analysis and regression results rather than an after-fix live trace; source inspection confirms the refusal guard and adoption ordering. No schema or serialized data-model contract changes are introduced.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded queued-turn recovery failure without evidence of a wider urgent regression introduced by the patch.
  • 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 author is a repository MEMBER, so ordinary contributor runtime proof is exempt. The body records incident analysis and regression results rather than an after-fix live trace; source inspection confirms the refusal guard and adoption ordering. No schema or serialized data-model contract changes are introduced.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The shared reply boundary changes the warning Telegram users can receive during recovery contention, which is observable on the Test Server.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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 (4 earlier review cycles)
  • reviewed 2026-10-04T01:20:45.872Z sha 3b4ddae :: blocked before merge. :: [P1] Keep channel successors bound to their persisted recovery run ID
  • reviewed 2026-10-04T04:36:21.594Z sha de6052b :: blocked before merge. :: [P1] Keep channel successors bound to their persisted recovery run ID
  • reviewed 2026-10-05T17:44:05.156Z sha eb9985808767074d6600ebcc269053f9e987e9e4 :: blocked before merge. :: none
  • reviewed 2026-10-05T17:54:08.627Z sha 0e9a383 :: blocked before merge. :: [P1] [P1] Reject a successor when its recovery transfer was refused

@lucascmg-vx

Copy link
Copy Markdown
Contributor

We hit this exact queued-successor race in production on the Microsoft Teams channel, and as far as I can tell this PR's hand-off would not cover it, because it only applies to Control UI turns.

Environment: 2026.9.6 (eb377ac), Docker, @openclaw/msteams, direct messages (DMs).

What happens: a user sends a second message in a DM while the previous turn in that session is still running. Admission throws instead of queueing, the msteams debounce flush gives up, and the message is silently lost. There was no gateway restart: it was the same process throughout.

04:55:50 [diagnostic] liveness heartbeat delayed: overdue=14061ms elapsed=44061ms; deferring recovery decisions
04:55:52 [diagnostic] message dispatch completed: channel=msteams sessionId=unknown sessionKey=agent:main:msteams:direct:<id> source=replyResolver outcome=error error="Error: restart recovery claim changed before agent adoption"
04:55:52 [msteams] dispatch failed: restart recovery claim changed before agent adoption
04:55:52 [msteams] debounce flush failed: restart recovery claim changed before agent adoption
04:55:53 (same message retried once, same error)
04:58:12 [diagnostic] lane wait exceeded: lane=session:agent:main:msteams:direct:<id> waitedMs=135869 queueAhead=0 activeAhead=1 activeNow=0 queueBehind=0
07:25:03 (a second DM, same error, no heartbeat delay beforehand)
07:25:12 [diagnostic] lane wait exceeded: lane=session:agent:main:msteams:direct:<id> waitedMs=6916 queueAhead=0 activeAhead=1

In both cases activeAhead=1 shows a turn was still running in the lane. Afterwards both sessions settled to status: done with no leftover claim, so this is the transient variant, not the permanent jam in #118839. The throw that fires is the activeClaimRunId && (abortedLastRun || status === "running" || ...) branch in restart-recovery-claim.ts. That branch is unchanged in v2026.9.8 and on main.

Request: could the successor hand-off (or simply waiting on the active claim's lane) apply to channel turns too, not only Control UI? For channels, a typed error plus a "conversation changed" notice still drops the user's message, and most users don't resend.

@RomneyDa
RomneyDa force-pushed the openclaw/fix-restart-recovery-claim-error-exposure branch from de6052b to eb99858 Compare October 5, 2026 17:36
@RomneyDa

RomneyDa commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa
RomneyDa marked this pull request as ready for review October 5, 2026 17:39
@clawsweeper clawsweeper Bot added proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@RomneyDa
RomneyDa force-pushed the openclaw/fix-restart-recovery-claim-error-exposure branch from eb99858 to 0e9a383 Compare October 5, 2026 17:47
@RomneyDa

RomneyDa commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Oct 5, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@RomneyDa
RomneyDa enabled auto-merge (squash) October 5, 2026 18:31
@RomneyDa
RomneyDa disabled auto-merge October 5, 2026 18:31
@RomneyDa
RomneyDa merged commit a33accd into main Oct 5, 2026
155 checks passed
@RomneyDa
RomneyDa deleted the openclaw/fix-restart-recovery-claim-error-exposure branch October 5, 2026 18:32
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…4656)

* fix: keep restart recovery races out of user replies

* fix: describe recovery contention accurately

* fix: preserve channel recovery claim tracking

* test: split recovery successor coverage

* fix: reject refused recovery handoffs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

2 participants