Skip to content

fix(sessions): preserve user input during restart recovery - #165502

Merged
steipete merged 1 commit into
mainfrom
steipete/restart-input-drop-20261005
Oct 5, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/restart-input-drop-20261005

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: an accepted chat instruction can fail during restart-related subagent registry activity and then be overlooked when a subagent announcement continues the conversation.

User Impact

Incoming replies re-read invalidated maintenance facts within the existing bounded initialization retry budget. If contention exhausts that budget, the visible error asks the user to retry. Saved, unanswered external user input stays actionable on the next run, including an announcement or requester-settle continuation.

Why This Change Was Made

Maintenance capture used an untyped error, bypassing reply initialization's optimistic-conflict handling. It now reports the existing maintenance-conflict type; reply initialization handles that known uncommitted conflict alongside its session-row conflict. Cancellation, admission identity, and uncertain-commit failures retain their existing behavior.

The orphan repair path previously detached the external user leaf and merged it into a synthetic continuation under a “context only” marker. Internal continuations now leave that user row in history with its original provenance. Ordinary user-turn repair identifies earlier unanswered input as actionable; routed inter-session data retains its existing treatment.

No schema, configuration, or durable format changes. Production LOC delta: +32 lines. Growth is required to distinguish external input from synthetic continuations and reuse the existing typed retry contract; no second retry owner or cache is added. The requested stat filter also includes six lines of test-routing inventory (+38 net); production itself is +32.

Evidence

Validation uses provider blacksmith-testbox, profile openclaw-check, lease tbx_01m45gbvwhk8qpwmwrr9stzqav (Testbox run). Base: e78e965a55e2d2b121c61d0a93e571c26f6f50f8. The original lease expired at its 65-minute job limit during the broad gate; replacement lease tbx_01m45mttvn8xp02xmmxyc876gd (gate run) checks the same candidate with per-file SHA-256 verification.

  • Negative control: both new orphan-input tests fail against the original production source: the saved user message disappears from provider history and the announcement receives one combined user prompt instead of two distinct inputs. Vitest: 21.54 s; test wrapper: 42.57 s (cold worker preparation included).
  • Preparation-conflict negative control: both cases fail on the original Subagent maintenance facts changed during preparation error (Vitest 33.78 s; wrapper 35.93 s). The initial attempt used the thread-hosted test family and failed before reaching the defect; the test now belongs to the existing database-worker family.
  • Candidate regressions and siblings: 194 tests passed. The two preparation cases prove two invalidations → three preparations → one dispatch with the original instruction, and continuous churn → ten preparations → zero dispatches plus retry guidance. Existing cancellation, source-admission and lifecycle rollback tests also pass.
  • Original orphan behavior: zero original user rows left in active history, one combined announcement prompt. Fixed behavior: the canonical external row survives two internal continuations and the provider receives separate external-user and announcement inputs.
  • Two oversized test files were split into coherent siblings, retaining all 63 cases and their CI routing. The split suite passed in 42.30 s (60.65 s wrapper); the final typed-fixture rerun passed 24 affected cases in 33.54 s (65.33 s wrapper).
  • node scripts/check-changed.mjs --base e78e965a55e2d2b121c61d0a93e571c26f6f50f8: all typechecks and preceding guards passed; the dead-export audit fails on untouched GoogleMeetJoinResult and MeetingRuntimeOwner. A clean detached checkout of the exact base, with its own frozen install, reproduces both findings (91.6 s command). All 11 remaining planned checks passed separately, including core/extension/script lint, runtime cycles, schema and authority guards (861.6 s command); the failed audit remains recorded, not waived.
  • Independent autoreview: scoped-clean through P2, including final test extraction and routing; no actionable findings.
  • Exact-head CI: passed, including openclaw/ci-gate, for 555d38897f1b3c8808b4ece7700bc6cad671e5ed (CI run, 876 s elapsed). A fresh head check found no pending or failed checks. The reviewed patch rebased cleanly onto 4f05baa4f524f436e10514831b80a35ec982d33f; git range-diff reports an identical patch. Testbox results above remain evidence for the original recorded base.

Focused commands use node scripts/run-vitest.mjs <files> --maxWorkers=1. Preparation dispatch coverage took 38.08 s wall / 7.106 s in tests with cold worker compilation; it exercises real reply initialization, SQLite preparation and registry publication, using synthetic final-runner responses, a disabled background maintenance kick, and injected backoff sleeps. Orphan/provider suites took 79.22 s wall across five files. This composition is needed to prove input reaches dispatch and preserves transcript identity; helper-only tests miss both failures.

Provider calls are mocked. No live Gateway was restarted or modified for this proof.

Retry invalidated subagent maintenance preparation through the existing
bounded reply initialization owner. Keep unanswered external user rows
separate from internal continuations and retain actionable input during
ordinary orphan repair.

Prove transient and exhausted registry churn through reply dispatch and
preserve the original user message across repeated continuation attempts.
@clawsweeper

clawsweeper Bot commented Oct 5, 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 scripts Repository scripts agents Agent runtime and tooling size: XL labels Oct 5, 2026
@steipete
steipete marked this pull request as ready for review October 5, 2026 10:06
@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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 6:31 AM ET / 10:31 UTC (Revision 2).

ClawSweeper review

What this changes

The PR retries invalidated session preparation, preserves unanswered user input during internal continuations, updates recovery documentation, and reorganizes regression coverage.

Merge readiness

✅ Ready for maintainer review

The PR remains useful and has no identified blocking defect. Source inspection resolves the earlier migration concern: existing transcript rows remain readable, and recovery preserves their original identity without introducing a new durable format.

Priority: P1
Reviewed head: 555d38897f1b3c8808b4ece7700bc6cad671e5ed

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful negative controls, successful exact-head CI, and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from external-contributor runtime proof. Supplied Testbox regressions exercise reply initialization, SQLite publication, persisted transcript reopening, and mocked provider inputs; they do not claim a live Gateway restart. Existing-state compatibility is sufficient: the original row shape and readers are unchanged, and seeded transcripts reopen with their original user entry preserved.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from external-contributor runtime proof. Supplied Testbox regressions exercise reply initialization, SQLite publication, persisted transcript reopening, and mocked provider inputs; they do not claim a live Gateway restart. Existing-state compatibility is sufficient: the original row shape and readers are unchanged, and seeded transcripts reopen with their original user entry preserved.
Evidence reviewed 9 items Verified introduced change: Reviewed the pinned merge-base-to-head production changes and test extraction. The actual checkout is the original PR head, not the synthetic test merge.
Bounded conflict recovery: Maintenance preservation conflicts return the existing stale-snapshot result. Reply initialization already refreshes preparation and bounds outer retries; cancellation and physical database identity checks remain intact. Maintenance capture rejects invalidated facts before lifecycle commit admission.
Existing-state compatibility: Internal continuations skip orphan detachment for external or legacy untagged user rows. Existing provenance, idempotency keys, row encoding, schema, and readers are unchanged. The persisted-boundary regression seeds an existing transcript, preserves the exact original entry across announcement and settle continuations, and reopens it through the existing reader. This resolves the prior review's migration question without requiring a migration.
Findings None None.
Security None None.

How this fits together

Reply initialization prepares session state before dispatching incoming instructions to an agent. Transcript recovery combines saved conversation history with new user input or internal subagent announcements before provider submission.

flowchart TD
  A[Incoming instruction] --> B[Reply initialization]
  C[Subagent maintenance facts] --> B
  B --> D{Preparation current?}
  D -->|No| E[Bounded refresh and retry]
  E --> B
  D -->|Yes| F[Transcript recovery]
  G[Saved unanswered user input] --> F
  F --> H[Agent provider input]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +32, Tests +300, Docs +7, Other +3. Total +342 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 8 53 21 +32
Tests 10 1183 883 +300
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 2 3 0 +3
Total 21 1246 904 +342

Review metrics

Metric Value Why it matters
Production versus regression growth production +32 lines; tests and test support +297 lines Production growth is justified by provenance-aware recovery and reuse of the typed conflict contract; test growth includes the suite extraction and boundary regressions.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-orphan-repair.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep one bounded initialization retry owner and preserve unanswered external input under its original transcript identity through internal continuations.

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

Yes, from source: invalidate subagent maintenance facts during reply preparation, then continue a transcript ending in unanswered external input with a subagent announcement. The supplied negative controls cover both failures; this review did not execute them.

Is this the best way to solve the issue?

Yes. The patch repairs the existing retry and transcript owners without adding competing mechanisms, and existing-state inspection resolves the earlier migration concern.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The repair addresses accepted instructions being overlooked during restart-related session recovery.
  • 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 verified repository-admin author is exempt from external-contributor runtime proof. Supplied Testbox regressions exercise reply initialization, SQLite publication, persisted transcript reopening, and mocked provider inputs; they do not claim a live Gateway restart. Existing-state compatibility is sufficient: the original row shape and readers are unchanged, and seeded transcripts reopen with their original user entry preserved.

Evidence

What I checked:

  • Verified introduced change: Reviewed the pinned merge-base-to-head production changes and test extraction. The actual checkout is the original PR head, not the synthetic test merge. (555d38897f1b)
  • Bounded conflict recovery: Maintenance preservation conflicts return the existing stale-snapshot result. Reply initialization already refreshes preparation and bounds outer retries; cancellation and physical database identity checks remain intact. Maintenance capture rejects invalidated facts before lifecycle commit admission. (src/config/sessions/session-accessor.reset.ts:324, 555d38897f1b)
  • Existing-state compatibility: Internal continuations skip orphan detachment for external or legacy untagged user rows. Existing provenance, idempotency keys, row encoding, schema, and readers are unchanged. The persisted-boundary regression seeds an existing transcript, preserves the exact original entry across announcement and settle continuations, and reopens it through the existing reader. This resolves the prior review's migration question without requiring a migration. (src/agents/embedded-agent-runner/run/attempt-session-boundary.orphan.test.ts:487, 555d38897f1b)
  • Input provenance remains distinct: Ordinary orphan repair marks external input as actionable while retaining the existing context-only treatment for routed inter-session input. The new preservation branch does not create or transfer execution authority, change principals, or bypass the existing transcript admission owners. (src/agents/embedded-agent-runner/run/attempt-prompt-helpers.ts:406, 555d38897f1b)
  • Regression evidence and its limits: The captured PR body reports original-code negative controls and 194 passing candidate tests. Inspected tests exercise real reply initialization and SQLite maintenance publication, plus persisted transcript reopening; final runner responses and provider transport are mocked. No live Gateway restart was claimed, and this read-only review ran no tests. (src/auto-reply/reply/get-reply.maintenance-conflict.test.ts:41, 555d38897f1b)
  • Current main still needs the repair: Fetched main retains the untyped maintenance invalidation error and the previous orphan-repair selection. Live GitHub metadata reports this PR open and unmerged. Release-source inspection failed with HTTP 403 during historical blob retrieval, so no shipped-release claim is made. (src/agents/embedded-agent-runner/run/attempt-session-prepare.ts:352, 583abe2eba27)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • oabdelmaksoud: 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 (1 earlier review cycle)
  • reviewed 2026-10-05T10:12:41.171Z sha 555d388 :: blocked before merge. :: none

@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer note on the "Add data-model compatibility proof" item: the flagged file, src/agents/embedded-agent-runner/run/attempt-orphan-repair.ts, only narrows a TypeScript type (UserMessage to PersistedUserTurnMessage) on an in-memory repair plan. The PR adds no stored row, column, JSON shape, migration, or backfill. Its only persistence effect is narrower: during state-preserving internal continuations, an unanswered external user row is no longer detached from the transcript, so it stays in user history instead of being demoted to context-only text. Existing transcripts are read the same before and after this PR, so no upgrade proof applies. Declining that item; there are no other findings.

@steipete
steipete merged commit 3cda99d into main Oct 5, 2026
273 of 275 checks passed
@steipete
steipete deleted the steipete/restart-input-drop-20261005 branch October 5, 2026 10:47
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…165502)

Retry invalidated subagent maintenance preparation through the existing
bounded reply initialization owner. Keep unanswered external user rows
separate from internal continuations and retain actionable input during
ordinary orphan repair.

Prove transient and exhausted registry churn through reply dispatch and
preserve the original user message across repeated continuation attempts.
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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