Skip to content

fix: prevent restarts from reviving abandoned sessions - #190995

Merged
steipete merged 3 commits into
mainfrom
steipete/fix-2109-predecessor-resume
Nov 2, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/fix-2109-predecessor-resume

Conversation

@steipete

@steipete steipete commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #190964 reviving abandoned sessions from older Gateway lifetimes when their persisted runs were still unfinished.

User Impact

Crash recovery resumes only work from the immediately preceding Gateway lifetime. Any recorded shutdown completion uses its explicit markers; markers in any agent store also take precedence after a partially completed shutdown; older orphaned runs are recorded as stopped for restart and cannot be adopted again. No schema, configuration, or prompt/tool changes. The existing consume-before-admit crash window remains; recovery does not promise external tool effects exactly once.

Why This Change Was Made

An unfinished run identity does not identify its owning Gateway. Capture the predecessor's exact interval from the existing boot ledger before pruning, including safe-mode segments of the same incarnation, and compare the run's start time against that interval. A recent session edit is not evidence of live work. Missing boot history does not authorize unmarked recovery. Feed this fact into the existing startup decision and reuse the canonical cancellation projection to settle stale runs.

The change adds 113 production lines for the missing boot fact, its delivery to recovery, terminal settlement, and the Gateway-wide marker decision; it introduces no parallel recovery path, cache, or new persisted state. The CLI retains the boot owner's result instead of a separate copied decision. When no marker is known, crash adoption waits for existing database preparation to establish global marker absence; recorded preparation failures veto adoption. Known markers keep the immediate recovery path. Prepared stores reuse the snapshot already owned by database startup, removing a duplicate summary/orphan read; the existing input-recovery promise preserves FIFO admission before reconnecting sends.

Evidence

  • 143 focused tests pass across recovery, boot lifecycle, CLI startup, queued inputs, and deferred database preparation. The final runtime build passes. All three isolated-Gateway cases pass: both graceful siblings in the full run, and the crash/partial-shutdown case in its final focused replay (35.566 seconds). The investigated full-run timeout is recorded below.
  • The new SIGKILL regression fails on exact parent 71e516af03a11fb1e309ff4fd2a0b8dccee506da: the stale run receives a new continuation instead of terminal settlement. With the fix, the killed predecessor resumes once, the older row is settled without a restart input, and a subsequent deliberately interrupted shutdown resumes only its marked turn despite old and same-predecessor unmarked rows in another agent store. Existing graceful sibling tests retain their marked-session contract.
  • Separate actual-model proof, Node 26.12.1 / OpenAI gpt-4.1-mini: one automatic continuation completes 15.648 seconds after SIGKILL. The seeded stale session gets zero continuations and retains its original run identity as killed. All owned Gateway and checkpoint processes were verified gone.
  • The local real-Gateway UI sidebar-running-count test passes. A selected macOS browser test has an inherited Undo-key defect described below.
  • Codex P0–P2 autoreview is scoped-clean for the final repair and test diagnostics; a subsequent test-local binding rename only fixes lint shadowing. The prepared-snapshot regression fails before reuse with two reads instead of one and verifies startup remains closed until enqueue acceptance. Exact-head CI exposed a partial-shutdown fixture that revealed store-local marker precedence was insufficient. Auto-merge was cancelled before repair. A deterministic provider-finalizer barrier now proves this case: the old runtime fails by admitting an unmarked continuation after markers were persisted while boot completion remains absent. Review also caught a completed inspection failure disappearing from the pending map; recovery now checks the existing resident refusal fact, covered by a regression.

Synthetic measurement uses 35.13 GiB, 10,000 sessions, 1,000,000 transcript events, and 62,000 workspace files / 1.116 GB on macOS/APFS. Five counterbalanced pairs, ten calls per timing batch and three per allocation batch. The real recovery owner and native SQLite reads/writes run; only model admission is counted instead of executed. No production data.

Warm recovery, median / p95 batch mean Before After
Wall, ms 120.204 / 132.679 110.827 / 123.994
Process CPU including workers, ms 157.238 / 189.870 150.516 / 158.882
Main-thread CPU, ms 30.334 / 35.833 25.332 / 26.335
Sampled host allocation, B 12,119,133 / 12,303,261 10,500,957 / 10,678,176
Admission attempts / stale rows settled 12 / 0 4 / 8
History-worker tasks 14 14

A/A median variation: wall -22.70%, process CPU -10.06%, main CPU -15.48%, allocation +1.38%. The shared host remained loaded (one-minute load 28.47–30.33 during timing controls), despite pausing lane-owned heavy jobs. Timing and CPU differences are not separable from that control variation; no speedup or neutral-CPU claim is made. Sampled host allocation decreased 13.35%, with a much smaller allocation control difference. Counts are stable in every run. Sampling excludes worker/native allocations, model execution, cold integrity checks, and btrfs. Boot-ledger lookup and waits for deferred database preparation were not separately timed. The committed measurement script reproduces the owner comparison.

The final full Gateway replay had one 120-second whole-test timeout waiting for the third boot’s marked continuation; both graceful siblings passed. Its log shows over 90 seconds elapsed before the partial-kill checkpoint. The unchanged runtime passed the focused replay in 26.877 seconds. The fixture now uses the existing siblings’ 180-second budget and retains phase timings plus bounded failure logs. The original exact admission delay was not captured; this is not classified as an inherited main failure or a proven product deadlock. The final focused replay passes in 35.566 seconds: first boot at 6.977s, crash continuation at 22.671s, partial kill at 24.247s, and marked continuation at 35.228s.

Inherited main regressions

pnpm check:changed ran completely. After correcting and rerunning this patch's lint failures, its remaining failure is three unused plugin-hook exports. Exact-parent production Knip reproduces the same three symbols; #190906 (71e516af03a11fb1e309ff4fd2a0b8dccee506da) introduced them. These are an unresolved main regression, not passing checks or noise.

The macOS browser test view.invalidation.browser.test.tsx fails identically on the exact parent because #173115 (19ac02afebec06357762f80db0749e058bfa5e64) hardcodes Control+Z for native Undo. A one-line ControlOrMeta causal control gives 3/3 passing without weakening assertions. This lane leaves UI source unchanged; the actual Gateway UI E2E passes.

@clawsweeper

clawsweeper Bot commented Nov 2, 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 cli CLI command changes scripts Repository scripts size: L labels Nov 2, 2026
@steipete
steipete marked this pull request as ready for review November 2, 2026 09:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T10:51:40.168844Z 06669bf New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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 Nov 2, 2026
@steipete
steipete enabled auto-merge (squash) November 2, 2026 09:34
@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. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR limits automatic crash recovery to the preceding Gateway lifetime and settles older unfinished runs without resuming them.

Example: A Gateway starts at 200 with a crashed predecessor that started at 100, while an abandoned session started at 1.

  • Before: Both unfinished sessions can receive restart continuations.
  • After: Only the predecessor's session resumes; the abandoned session is recorded as killed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with no established discrete code defect, but conflicting exact-head regression evidence and incomplete upgrade validation prevent a merge-ready assessment.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor-proof gate does not apply to this maintainer-authored PR; its body records actual-model SIGKILL recovery and stale-session rejection, but the required latest-stable upgrade compatibility scenario is not supplied.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Restarting a Gateway can revive abandoned conversations whose old runs were never terminally settled.
Reason: The maintainer-authored direction repairs a concrete recovery boundary using existing owners and adds no production configuration or schema.

Regression provenance

Regression provenance — verified: source commit b1b6a4659639 by Peter Steinberger; canonical PR #190964 (blame-to-merge-commit).

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR addresses a current-main recovery defect, but its exact-head clean-restart regression is failing and needs attribution before merge.

Priority: P2
Reviewed head: 113bd3f5f2254bf3a07599a0ff62a47b94a9250a

Before merge

  • Resolve merge risk - Before merge, the PR owner must attribute the exact-head clean-restart settlement failure and either repair its cause or provide evidence establishing an outside cause.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a latest-stable v2026.10.9 upgrade run demonstrating retained settings, transcripts, and eligible legacy recovery alongside stale-run settlement.
Agent review details

How this fits together

CLI startup obtains predecessor facts from the shared-state boot ledger, passes them into session recovery, and uses existing session writers and ordinary input admission to settle or resume persisted runs.

flowchart TD
  A[CLI startup] --> B[Boot ledger worker]
  B --> C[Predecessor interval]
  C --> D[Session recovery owner]
  E[Persisted session entries] --> D
  D --> F[Canonical terminal settlement]
  D --> G[Ordinary resume admission]
Loading

Technical review

Best possible solution:

Use the existing boot ledger for predecessor selection and the existing lifecycle projection for terminal settlement, preserving graceful markers and ordinary admission.

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

Current-main source admits ownerless unfinished runs without a predecessor bound, and the body records a red-on-parent Gateway regression; this review executed no target code.

Is this the best way to solve the issue?

The patch follows the smallest complete owner-based repair: derive one boot fact, carry it through startup, and reuse canonical lifecycle settlement without another recovery subsystem.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Repair the failing settlement scenario (recommended)
    Trace the unmarked session's state changes through restart and shutdown, correct the responsible owner or fixture, and pass the existing regression without weakening its identity assertions.
  2. Establish an outside cause
    Provide a controlled comparison demonstrating that the same failure occurs independently of this change before treating the check as inherited.

Provenance checked

  • Unmarked crash recovery changes intended behavior with a stated reason (b1b6a46: Resume a persisted interrupted root turn after SIGKILL through the existing ordinary admission path.)
  • Boot-ledger worker ownership keeps the original intent (1b9731a: Keep boot-history inspection, pruning, and append off the Gateway main thread while preserving breaker decisions.)
  • Deferred session recovery keeps the original intent (9bf3231: Recover retained inputs after their physical databases become ready without blocking unrelated agents.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b1b6a46 adds src/gateway/session-restart-resume.ts:495 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b1b6a4659639; files: src/gateway/session-restart-resume.ts)
  • Shakker: Raw commit 9bf3231 adds src/gateway/session-restart-resume.ts:285 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9bf3231d2535; files: src/gateway/session-restart-resume.ts)

PR surface

Source +69, Tests +194, Docs +7, Other +132. Total +402 across 13 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 85 16 +69
Tests 3 283 89 +194
Docs 2 27 20 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 160 28 +132
Total 13 555 153 +402

Review metrics

Metric Value Why it matters
Production versus regression code Production +85/-16; tests +283/-89 Production growth supplies the missing boot fact, its delivery, and canonical settlement; regression growth covers lifetime selection and process restart behavior.
Benchmark options 2 benchmark-only flags --resume and --markers extend the measurement script; no Gateway configuration option is added.

Labels

Label changes:

  • add P2: The fix addresses unintended continuation of abandoned sessions after restart, with a limited recovery-specific scope.
  • add merge-risk: 🚨 session-state: The exact-head regression observes an unmarked session ending under a different run identity and terminal status; attribution remains unresolved.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.

Label justifications:

  • P2: The fix addresses unintended continuation of abandoned sessions after restart, with a limited recovery-specific scope.
  • merge-risk: 🚨 session-state: The exact-head regression observes an unmarked session ending under a different run identity and terminal status; attribution remains unresolved.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.

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 November 2, 2026, 4:40 AM ET / 09:40 UTC.

@steipete
steipete disabled auto-merge November 2, 2026 09:43
@steipete
steipete merged commit f8d028a into main Nov 2, 2026
132 of 133 checks passed
@steipete
steipete deleted the steipete/fix-2109-predecessor-resume branch November 2, 2026 11:25
@steipete

steipete commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
* fix: prevent restarts from reviving abandoned sessions

* style: satisfy restart recovery lint checks

* fix(gateway): honor restart markers across prepared stores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant