Skip to content

fix: prevent completed conversations from resuming after restart - #166340

Closed
roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/fix-166300-legacy-recovery
Closed

roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/fix-166300-legacy-recovery

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #166300

What Problem This Solves

Fixes an issue where users updating or restarting a Gateway could have a completed historical conversation resume, run tools, and send an unsolicited reply. A legacy failed-recovery row could retain an unmatched runtime fence after its execution and delivery owners had been cleared.

Why This Change Was Made

Recovery now distinguishes retained evidence from permission to execute again. A terminal row with only an unowned runtime fence is preserved behind a quiet, zero-attempt recovery tombstone instead of becoming a fresh executable cycle. Startup marking and foreground admission use the same owner-level classification.

This does not guess completion from an assistant final or session age, discard unmatched fences, or change the transcript resume policy. Existing recovery cycles, runtime/writer identities, harness-completion ownership, pending finals, and delivery claims retain their recovery behavior. No schema or configuration changes.

The refactor consolidates the two recovery inspectors and duplicated foreground-claim guards, removes the redundant rollover-eligibility layer, and keeps outcome policy in the existing state owner rather than introducing another production module.

User Impact

Completed legacy conversations no longer restart themselves from ambiguous leftover state. The original transcript, timestamps, and recovery evidence stay intact, without a new message or notice. If continuation is needed, the existing Resume in new session, /new, or /reset paths remain available.

The intentional tradeoff is that this narrowly identified ambiguous legacy state requires explicit recovery instead of ordinary in-place input. Genuine interrupted work and owed replies remain automatically recoverable.

Reported by @hannesrudolph.

Work sessions

The net-negative follow-up was implemented and verified in the original discussion session linked above.

Evidence

  • Before the original fix, ordinary and Codex-mirrored completed-final startup cases each dispatched a new turn. The regression cases now verify zero dispatch, zero recovery notices, unchanged transcript/timestamps, retained evidence, and stable repeated scans.
  • 216,000 generated before/after transition comparisons matched the previously published fix, including returned results and state mutations for inspection, observation, adoption, and foreground binding/validation/release across current and stale generations.
  • 116 fresh tests passed after the refactor: 113 recovery/state/startup/claim-lifecycle tests across seven files, plus three public sessions.recover cases. The public cases passed both before and after removal of the redundant helper: absent tombstones are rejected, and repeated recovery reuses its existing successor.
  • One helper-only rollover test was replaced with public-boundary coverage; the actual legacy replay regressions and legitimate-work controls remain. The initial candidate's 12 additional selected runtime controls passed previously; they were not rerun in this refactor pass.
  • Measured wall times: the seven-file recovery run took 105.63 s; the public recovery selection took 58.12 s before (cold compilation) and 25.19 s after (warm). These are test-cost observations, not a performance comparison. The public selection includes three passing cases and 21 intentionally filtered cases.
  • The complete affected-path changed-check run passed against pinned base 51f772a: production typechecking, all 27 core-test type graphs, targeted lint, formatting, dead-export scans, and the applicable ownership/schema/import-cycle guards.
  • Fresh independent pre-commit review of the entire candidate and unchanged owner contracts completed with no P0–P2 findings. The reviewer inspected tests rather than running them.
  • The legacy fixture was generated from the source-extracted July fail_recovery transition and cleanup at d111bef, with source blob identities checked. The precise original July production interruption is not claimed as proven.
  • Direct Codex dependency inspection: completion handling and completed versus interrupted turns. The fix remains provider-independent.

Production delta: +118/−145, net −27 lines relative to the original base 51f772a (previous candidate: net +61). Tests/fixtures: +269/−45, net +224; docs: +9. The complete PR remains net positive because it retains regression coverage.

Proof uses isolated SQLite/startup and public-handler execution with mocked dispatch, not live provider/channel traffic or an installed-updater run. The full repository test suite was not run. Before merge, recovery-owner acceptance of the documented foreground restriction and published-driver-to-candidate upgrade evidence remain outstanding; this PR stays draft.

Preserve unowned terminal recovery fences behind the existing explicit recovery boundary instead of authorizing a new turn. Retain genuine interruption and delivery custody. Fixes #166300.

Co-authored-by: hannesrudolph <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 6, 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: M labels Oct 6, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 6, 2026, 7:37 PM ET / 23:37 UTC (Revision 2).

ClawSweeper review

What this changes

The PR quarantines ambiguous legacy recovery records to prevent unsolicited conversation restarts, consolidates recovery checks, and adds regression coverage and documentation.

Merge readiness

⛔ Blocked before merge - 4 items remain

The fix remains necessary on current main, and the consolidation introduces no concrete blocking code finding. Both previously identified merge blockers remain unresolved.

Priority: P1
Reviewed head: d2a49b409f771a4564bc7d7e9098bdd5a7181b89
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation and meaningful regressions provide useful confidence, but required existing-state upgrade proof remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The bot-authored PR is exempt from the ordinary external-contributor proof gate; its reported SQLite startup and public-handler tests use mocked dispatch. The new persisted quarantine semantics still lack the independently required published-updater-to-candidate upgrade validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The bot-authored PR is exempt from the ordinary external-contributor proof gate; its reported SQLite startup and public-handler tests use mocked dispatch. The new persisted quarantine semantics still lack the independently required published-updater-to-candidate upgrade validation.
Evidence reviewed 12 items Pinned introduced changes: Reviewed the merge-base-to-head changes using the host-provided identities. The checkout matches the original PR head; no pinned test merge is available, so base-only refactors were not attributed to this PR.
Current main still permits legacy adoption: Current main creates a recovery cycle from a surviving claim and abortedLastRun without the new unowned-terminal-fence classification. An unmatched runtime fence prevents terminal settlement, leaving the reported fixture recoverable.
Narrow quarantine and foreground restriction: The predicate excludes existing cycles, runtime/writer identities, delivery claims, harness completion, and pending finals. Observation preserves an unmatched terminal fence behind a zero-attempt tombstone; foreground adoption rejects the same state.
Findings None None.
Security None None.

How this fits together

Gateway restart recovery reads persisted session obligations and decides whether to resume agent work or preserve the session for explicit recovery. Its decisions control fresh tool execution and subsequent replies.

flowchart TD
  A[Persisted session state] --> B[Startup recovery scan]
  B --> C[Recovery ownership classification]
  D[New foreground input] --> C
  C -->|Unowned terminal residue| E[Preserved recovery tombstone]
  C -->|Unfinished owned work| F[Agent continuation]
  E --> G[Explicit Resume action]
  F --> H[Tools and reply delivery]
Loading

Decision needed

Question Recommendation
Should unowned terminal legacy fences block ordinary in-place input and require explicit recovery into a replacement session? Accept explicit recovery: Approve the narrow quarantine contract, contingent on published-updater validation preserving evidence and legitimate unfinished work.

Why: The restriction prevents unsafe historical replay but changes continuation behavior for existing sessions; the contributor explicitly leaves recovery-owner acceptance outstanding.

Before merge

  • Resolve merge risk (P1) - Affected legacy sessions will reject ordinary in-place input and require explicit Resume, /new, or /reset; recovery-owner acceptance of this intentional restriction remains outstanding.
  • Resolve merge risk (P1) - The required published-updater-to-candidate validation has not demonstrated preservation of existing legacy state, suppression of replay, and continued recovery of legitimate obligations.
  • Complete next step (P2) - Obtain recovery-owner acceptance, record published-updater-to-candidate upgrade validation, and resolve the reported merge conflicts before requesting landing.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source -27, Tests +224, Docs +9. Total +206 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 4 118 145 -27
Tests 6 269 45 +224
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 396 190 +206

Review metrics

Metric Value Why it matters
Production versus regression coverage production −27 LOC; tests/fixtures +224 LOC Consolidating inspection and claim guards reduces production code while retaining startup and public-recovery regressions.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166300
Summary: This PR is the explicit candidate repair for the reported legacy completed-conversation replay.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Approve and verify the quarantine contract (recommended)
    Record recovery-owner acceptance and the published-updater upgrade result before landing the intentional foreground restriction.
  2. Revise foreground continuation
    Keep the PR paused while designing a safe fresh-input continuation path if replacement-session recovery is unacceptable.

Technical review

Best possible solution:

Preserve ambiguous legacy obligations without replay, retain legitimate recovery, and expose the existing Resume action under an approved and verified upgrade contract.

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

Yes, from source: the reported failed/aborted row with an unmatched runtime fence becomes recoverable on current main. This review did not execute a reproduction; the linked report independently records production dispatch and delivery.

Is this the best way to solve the issue?

Yes at the owner boundary: preserving ambiguous evidence without minting a new execution obligation is narrower than age cutoffs or arbitrary assistant-final checks. The foreground restriction still needs owner acceptance and upgrade validation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: The linked production incident reactivated historical work and sent an unsolicited reply after a routine update.
  • merge-risk: 🚨 compatibility: The new durable quarantine rejects ordinary input in affected existing sessions, with acceptance and upgrade validation still outstanding.
  • 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. Not applicable: The bot-authored PR is exempt from the ordinary external-contributor proof gate; its reported SQLite startup and public-handler tests use mocked dispatch. The new persisted quarantine semantics still lack the independently required published-updater-to-candidate upgrade validation.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head changes using the host-provided identities. The checkout matches the original PR head; no pinned test merge is available, so base-only refactors were not attributed to this PR. (d2a49b409f77)
  • Current main still permits legacy adoption: Current main creates a recovery cycle from a surviving claim and abortedLastRun without the new unowned-terminal-fence classification. An unmatched runtime fence prevents terminal settlement, leaving the reported fixture recoverable. (src/agents/main-session-recovery/main-session-recovery-state.ts:348, 45228e1aeed6)
  • Narrow quarantine and foreground restriction: The predicate excludes existing cycles, runtime/writer identities, delivery claims, harness completion, and pending finals. Observation preserves an unmatched terminal fence behind a zero-attempt tombstone; foreground adoption rejects the same state. (src/agents/main-session-recovery/main-session-recovery-state.ts:149, d2a49b409f77)
  • Startup boundary regression coverage: The new canonical-final and Codex-mirrored-final cases exercise persisted state through startup marking and recovery observation, asserting no dispatch or notice and stable repeated scans. Positive controls retain interrupted work and pending-final recovery. Dispatch is mocked; these tests were inspected, not executed during this review. (src/agents/main-session-recovery/main-session-startup-recovery.test.ts:303, d2a49b409f77)
  • Public recovery contract retained: Removing the redundant eligibility helper retains the tombstone requirement and existing successor-reuse path. Public-handler coverage checks rejection without a tombstone and repeated recovery returning the same successor. (src/gateway/session-recovery-service.ts:320, d2a49b409f77)
  • Prior blockers remain explicitly outstanding: The captured PR body still states that recovery-owner acceptance of rejecting ordinary in-place input and published-driver-to-candidate upgrade evidence are outstanding. These are the same two rank-up items retained from the previous completed review; current REST review/comment reads supplied no human acceptance. (d2a49b409f77)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Record recovery-owner acceptance of requiring explicit recovery for ordinary in-place input.
  • Record the published-updater-to-candidate result using isolated legacy state and legitimate-work controls.

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 (1 earlier review cycle)
  • reviewed 2026-10-06T23:15:16.488Z sha 63aec21 :: blocked before merge. :: none

Keep the legacy replay fix while sharing inspection and foreground-claim validation. Remove redundant rollover eligibility and replace helper-only coverage with public recovery checks. Production code is net negative against the original PR base.

Co-authored-by: hannesrudolph <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Closing as obsolete.

Obsolete after #185730 replaced the reconstruction/fence/tombstone recovery architecture this PR changes. Current recovery uses graceful-stop markers and ordinary resume inputs; this closure is not a claim that every restart-related defect is resolved.

This closes the PR without deleting its branch.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

[Bug] Restart recovery resumes a completed 70-day-old conversation after the run-outcome refactor

1 participant