Skip to content

fix: preserve interrupted turns when new messages arrive - #170647

Merged
steipete merged 2 commits into
mainfrom
test/orphaned-recovery-shared-state-flake
Oct 13, 2026
Merged

steipete merged 2 commits into
mainfrom
test/orphaned-recovery-shared-state-flake

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes interrupted chat recovery being skipped when a new visible message arrives before background recovery starts.

User Impact

Interrupted work keeps its recovery claim until recovery resumes it, so a new message cannot silently consume the old request as ordinary conversation history. Ordinary failed sessions without recovery custody still recover in place. No configuration or schema change is required.

Why This Change Was Made

Orphan reconciliation intentionally retains a failed outcome while marking its delivery claim interrupted. Terminal-session reuse then cleared the interruption flag and delivery/source IDs before reply admission could resume that work. Background recovery could win the race and hide the defect.

Extend the existing terminal-reuse protection with the canonical recovery-claim predicate. Add a deterministic regression beside the existing four-case Gateway recovery test; its assertions and timing limits remain unchanged. Document the recovery ordering. Production is +6 lines: the existing owner needs this additional predicate, with no new state or recovery path.

Evidence

  • The existing recovery test failed at the provider-count assertion in scheduled main runs 38334375513 / job 115091148557 and 38339144048 / job 115106094655: expected two requests, received one containing both messages.

  • New regression: preserves interrupted recovery custody when reusing a failed session. It failed on unchanged production by clearing abortedLastRun and both delivery/source IDs. Command: CI=1 OPENCLAW_VITEST_WORKER_CACHE=1 node scripts/run-vitest.mjs src/gateway/server.chat.orphaned-recovery.test.ts --maxWorkers=1 -t 'preserves interrupted recovery custody'. Case: 43 ms; command: 235.02 s, mostly cold transformation/preparation.

  • The original 25-file replay was stopped during cold Gateway setup without a verdict; the isolated original case also hit a setup timeout. Neither is claimed as a reproduction or passing proof. The nearby database-admission diagnostic is not claimed fixed.

  • Changed-file Oxlint: zero diagnostics across both TypeScript files. Oxfmt and git diff --check: passed. Deslop: clean.

  • Prescribed Codex autoreview: scoped-clean through P2; no accepted/actionable findings. Hosted Codex review also completed without suggestions. ClawSweeper has acknowledged the PR but has posted no code findings as of closeout.

  • PR CI is the test gate. At head 798c78243a8e8995c3be46057e9dfaf4c68247ba, job 115133100497 passed the new custody regression (7 ms) and the unchanged four-case Gateway recovery test (21.539 s). Its agentic-control-plane-agent-chat-hosted-4 shard passed both tests in 34.01 s. Run 38347696342 completed: all PR test, lint, and production/test typecheck jobs passed. There were 36 successful jobs, 25 skips, and two failures: the inherited asset check below and the aggregate CI gate reporting that failure.

  • Live Gateway/Crabbox/Testbox proof, local typechecks, broad local suites, and production-reverted negative controls were intentionally skipped per maintainer policy. Only the lane's focused reproduction exception was used.

  • Inherited CI failure: PR build-artifacts job 115133099887 and latest scheduled main run 38347821426 / job 115133356342 both fail with the same generated extensions/workboard/openclaw.plugin.json mismatch. This PR does not change the Workboard source or manifest.

Keep durable recovery custody during terminal session reuse so reply admission resumes the interrupted source before a new visible input. Add a deterministic regression for the scheduled orphan recovery failure.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XS labels Oct 13, 2026
@steipete
steipete marked this pull request as ready for review October 13, 2026 04:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-10-13T04:44:52.140946Z 798c782 Draft marked ready
ℹ️ 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.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 13, 2026
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves an interrupted turn’s recovery claim when a new message reuses a failed, timed-out, or killed session.

Example: A failed session retains interrupted-run and accepted-input recovery IDs when the user sends “Then verify the new request.”

  • Before: Session reuse clears the interruption marker and source IDs, allowing the earlier request to become ordinary history without its own execution.
  • After: The earlier request retains custody and resumes before the new message takes foreground ownership.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch has no actionable findings and relevant Gateway harness coverage; supplied evidence does not include a standalone shipped-entry-point demonstration.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied validation covers a deterministic custody regression and the in-process Gateway recovery flow, while standalone live verification was explicitly skipped.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A new message can silently consume an interrupted request as history before recovery executes that request.
Reason: The narrow change restores documented recovery ordering, follows the prior recovery fixes’ intent, and has direction from the established feature owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still clears interrupted recovery custody during terminal-session reuse, and this focused patch fixes that path without an actionable correctness finding.

Priority: P1
Reviewed head: 798c78243a8e8995c3be46057e9dfaf4c68247ba

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session preparation normalizes reusable terminal sessions before reply admission; reply admission consumes retained recovery markers to resume interrupted work through the existing recovery owner.

flowchart TD
A[New visible message] --> B[Chat admission]
B --> C[Orphan reconciliation]
C --> D[Terminal session reuse]
D --> E[Reply admission]
E --> F[Existing recovery owner]
F --> G[Interrupted turn then new turn]
Loading

Technical review

Best possible solution:

Retain interrupted custody in the existing session-reuse owner and let existing reply admission resume it before accepting the next turn.

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

Source establishes the path from failed orphan reconciliation through destructive terminal reuse to missed recovery admission; the body also reports a deterministic pre-fix failure, but no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs the producer of lost custody using the canonical predicate, preserves ordinary terminal cleanup, and adds no competing recovery mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Terminal-session recovery custody keeps the original intent (78e6318: Preserve interrupted harness-completion claims while using canonical cleanup for ordinary terminal reuse.)
  • Gateway orphan recovery coverage keeps the original intent (9cf4837: Recover stranded conversations in place before a new message or retained retry can replace unfinished recovery custody.)
  • Restart-recovery documentation keeps the original intent (17c9b48: Document recovery preservation for automation turns interrupted by restart draining.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9cf4837 adds src/gateway/server.chat.orphaned-recovery.test.ts:17 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9cf4837995ff; files: src/gateway/server.chat.orphaned-recovery.test.ts)
  • Goutam Adwant: Raw commit 78e6318 adds src/config/sessions/terminal-status.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 78e6318772e0; files: src/config/sessions/terminal-status.ts)

PR surface

Source +6, Tests +16, Docs +3. Total +25 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 9 3 +6
Tests 1 16 0 +16
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 28 3 +25

Labels

Label changes:

  • add P1: Interrupted chat work can silently lose its independent recovery execution when a later message arrives, breaking conversation recovery.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Interrupted chat work can silently lose its independent recovery execution when a later message arrives, breaking conversation recovery.
  • 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.

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 October 13, 2026, 3:24 AM ET / 07:24 UTC.

@steipete
steipete merged commit c47a8be into main Oct 13, 2026
208 of 213 checks passed
@steipete
steipete deleted the test/orphaned-recovery-shared-state-flake branch October 13, 2026 10:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

RomneyDa pushed a commit that referenced this pull request Oct 14, 2026
Keep durable recovery custody during terminal session reuse so reply admission resumes the interrupted source before a new visible input. Add a deterministic regression for the scheduled orphan recovery failure.

(cherry picked from commit c47a8be)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…0647)

Keep durable recovery custody during terminal session reuse so reply admission resumes the interrupted source before a new visible input. Add a deterministic regression for the scheduled orphan recovery failure.
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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