Skip to content

fix: recover conversations stranded after gateway restarts - #153433

Merged
steipete merged 1 commit into
mainfrom
codex/fix-stranded-session-recovery
Sep 20, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-stranded-session-recovery

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes conversations repeatedly rejecting messages with “conversation changed” after a Gateway restart leaves unfinished recovery state behind a failed or statusless run. Refreshing the conversation could not repair that state.

User Impact

Users can continue the same conversation through a new message or a retry of the retained request. Explicit sessions.recover can also resume the stranded work in place, preserving the session key and transcript.

Why This Change Was Made

Normal chat admission and explicit recovery now share the existing guarded orphan-reconciliation owner. Reconciliation runs before durable retry resolution or a new delivery claim can replace the old one. Live runs, cloud workers, stale session/branch/settings requests, completed runs, and tombstones retain their existing protections. No schema, configuration, retention, or permission change is required; existing stored recovery markers are the input to repair after an update.

Evidence

  • Reproduced the exact dispatch-refresh failure through a real Gateway WebSocket connection identifying as Control UI before the fix. Failed and statusless explicit-recovery cases also failed before the repair.
  • Real Gateway coverage verifies failed/statusless records with both new messages and matching retained request IDs, predecessor-before-new ordering, exactly-once execution, preserved history, and rejection of conflicting or stale requests without mutation.
  • Focused recovery, admission, startup queue/cancellation, live-owner, cloud-worker, authority, and tombstone tests passed.
  • pnpm build, core and test typechecks, formatting, lint, dead-export scans, and the remaining changed-code guards passed. The changed-check run stopped on a test cleanup lint issue; that mechanical correction and every remaining guard were then verified directly.
  • Independent review found a same-ID retry acknowledgement bug; its new regression failed before the ordering correction and passes afterward.
Review disposition

A subsequent device-retention finding was reviewed against the authenticated request dispatcher, the recovery admission owner, and the Gateway instance runtime. The requesting client capture already spans the awaited handler. Guarded reconciliation restores an existing durable obligation; automatic recovery then uses its named session admission and instance-owned system principal, with session/claim/generation revalidation. It does not admit the retry's new input under a detached browser credential. The current request rechecks authority after resolution. No additional caller-retention policy was added to previously accepted recovery work.

@clawsweeper

clawsweeper Bot commented Sep 20, 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 maintainer Maintainer-authored PR labels Sep 20, 2026
@steipete
steipete marked this pull request as ready for review September 20, 2026 04:36
@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 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 12:43 AM ET / 04:43 UTC.

ClawSweeper review

What this changes

The PR lets new chat messages, retained retries, and explicit recovery resume stranded conversations in place, with regression coverage and updated recovery documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful recovery fix: current main and the latest release still exclude failed and statusless sessions from orphan reconciliation. No blocking defect was found in the introduced changes.

Priority: P1
Reviewed head: d313585c94b30fe5bf8dcd5212cc5a121e758c5a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with shared ownership, meaningful regression coverage, and no blocking correctness findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository context identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports before/after Gateway WebSocket recovery, and inspected coverage exercises the changed admission owner against persisted stranded state; execution was not independently repeated.
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 context identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports before/after Gateway WebSocket recovery, and inspected coverage exercises the changed admission owner against persisted stranded state; execution was not independently repeated.
Evidence reviewed 9 items Introduced change boundary: Reviewed the pinned merge-base-to-head changes and complete affected production modules. The host-verified test merge contains the same seven changed paths; unrelated endpoint drift was excluded from ownership claims.
Current main still needs the repair: Current main requires status running for explicit orphan reconciliation. Failed and statusless rows with an unfinished non-tombstoned cycle therefore remain outside this recovery path.
Latest-release comparison: The source at the supplied v2026.9.5 release commit also restricts orphan reconciliation to running sessions; the requested expansion is not already present there.
Findings None None.
Security None None.

How this fits together

Gateway admission checks incoming chat requests against persisted session state. Restart recovery reconciles interrupted work before admitting another turn, preserving the conversation and preventing duplicate execution.

flowchart TD
  A[Chat message or explicit recovery] --> B[Validate request and session]
  B --> C[Inspect unfinished recovery]
  C --> D{Live run or cloud worker?}
  D -->|Yes| E[Preserve active ownership]
  D -->|No| F[Reconcile interrupted session]
  F --> G[Resume retained work]
  G --> H[Admit new work without duplication]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +111, Tests +256, Docs +2. Total +369 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 166 55 +111
Tests 2 264 8 +256
Docs 1 7 5 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 437 68 +369

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +111 net lines; tests +256 net lines Production growth adds guarded pre-admission reconciliation while reusing existing recovery transitions; most growth provides boundary regression coverage.

Technical review

Best possible solution:

Keep recovery centralized in the existing guarded owner so stranded conversations resume in place before new input can replace their retained delivery claim.

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

Yes: current source excludes failed and statusless sessions carrying unfinished recovery state, and the PR supplies concrete Gateway request scenarios for both. This review did not execute the reproduction.

Is this the best way to solve the issue?

Yes: extending the existing orphan-reconciliation owner and invoking it before durable retry resolution addresses the admission wedge without adding a competing recovery mechanism or changing stored formats.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The reported restart failure blocks further messages in an existing conversation despite refreshing it.
  • 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 context identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports before/after Gateway WebSocket recovery, and inspected coverage exercises the changed admission owner against persisted stranded state; execution was not independently repeated.

Label justifications:

  • P1: The reported restart failure blocks further messages in an existing conversation despite refreshing it.
  • 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 context identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports before/after Gateway WebSocket recovery, and inspected coverage exercises the changed admission owner against persisted stranded state; execution was not independently repeated.

Evidence

What I checked:

  • Introduced change boundary: Reviewed the pinned merge-base-to-head changes and complete affected production modules. The host-verified test merge contains the same seven changed paths; unrelated endpoint drift was excluded from ownership claims. (d313585c94b3)
  • Current main still needs the repair: Current main requires status running for explicit orphan reconciliation. Failed and statusless rows with an unfinished non-tombstoned cycle therefore remain outside this recovery path. (src/gateway/session-recovery-service.ts:110, 4891bc477fa7)
  • Latest-release comparison: The source at the supplied v2026.9.5 release commit also restricts orphan reconciliation to running sessions; the requested expansion is not already present there. (src/gateway/session-recovery-service.ts, ec9c1a13db89)
  • Reconciliation precedes retry resolution: Chat pre-admission reconciles eligible state before resolving the durable claim. Its commit guard rechecks caller authority, routing, request identity, session identity, active branch, permissions, and tool settings. (src/gateway/server-methods/chat-send-pre-admission.ts:539, d313585c94b3)
  • Live ownership and final-write guards: The shared reconciliation service checks plugin ownership, worker placement, session identity, lifecycle revision, and recovery revision. The marking owner rechecks live runs and lifecycle generation, and the SQLite replacement owner invokes assertCommitAllowed inside the write transaction before writing rows. (src/config/sessions/session-accessor.sqlite-replacement-projection.ts:268, d313585c94b3)
  • Recovery authority disposition: The captured PR body explains that reconciliation restores previously accepted work. Source inspection supports that distinction: normal request authority spans pre-admission, while automatic recovery uses the existing session admission owner and Gateway recovery runtime with session, claim, and generation checks. No new caller-retention policy or permission contract is introduced. (src/agents/main-session-recovery/main-session-restart-recovery-runtime.ts:142, d313585c94b3)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 9cf4837 into main Sep 20, 2026
281 checks passed
@steipete
steipete deleted the codex/fix-stranded-session-recovery branch September 20, 2026 05:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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: 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.

1 participant