Skip to content

fix(doctor): preserve legacy Claude conversations during migration - #143347

Merged
obviyus merged 2 commits into
mainfrom
fix/legacy-cli-session-bindings
Sep 9, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/legacy-cli-session-bindings

Conversation

@obviyus

@obviyus obviyus commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #136257.

What Problem This Solves

Doctor left legacy conversation IDs outside canonical bindings while runtime reads and saves still used the retired field. Repair could also restore a deliberately cleared stale conversation or disrupt a locked session.

Why This Change Was Made

Doctor copies safe legacy IDs before removing the old field, and runtime reads and saves change together. Canonical bindings and resume metadata retain precedence. Locked rows change only their binding representation. Stale-route cleanup also clears the legacy source so later migration cannot restore it; ambiguous records retain warnings.

User Impact

Run openclaw doctor --fix after upgrading and before resuming sessions that have only the old field. Configured and locked conversations retain their IDs and metadata. Stale conversations remain cleared, and normal saves no longer recreate the retired field.

Consumers: Doctor migration, runtime conversation lookup, normal saves, and stale-route repair now use canonical bindings consistently.

Evidence

The original regression missed the canonical binding after repair. Public Doctor repair, session listing, and repeated repair passed on ten synthetic sessions across two agents. Reopened databases preserved IDs, metadata, and locked ownership; stale state stayed cleared on repeat. Native checks passed; continuous integration covers migration, save, fork, and Doctor-to-history cases. No live conversation or credential operation was tested.

@obviyus obviyus self-assigned this Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 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 commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 9, 2026, 4:12 PM ET / 20:12 UTC (Revision 3).

ClawSweeper review

What this changes

Doctor migrates legacy Claude conversation IDs into provider-keyed session bindings, preserves locked conversations, prevents stale conversations from returning, and retires legacy runtime reads and writes.

Merge readiness

⛔ Blocked before merge - 4 items remain

The migration remains useful and the earlier locked-session defect is addressed. No new blocking code defect was established; the remaining blocker is confirming the accepted upgrade contract for retiring the shipped legacy reader.

Priority: P2
Reviewed head: 96e5877b0f15dffe7baa9fd934cbdea07ccb694e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused migration with meaningful persistence coverage and the prior locked-session correction; the remaining approval question does not lower patch quality.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. The updated body nevertheless reports compiled Doctor migration, database reopen, and repeat-repair observations for 10 sessions across two agents; live provider resume is not claimed, and history/resume coverage remains supplemental tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. The updated body nevertheless reports compiled Doctor migration, database reopen, and repeat-repair observations for 10 sessions across two agents; live provider resume is not claimed, and history/resume coverage remains supplemental tests.
Evidence reviewed 10 items Migration and locked-session correction: The migration preserves existing binding precedence, refuses to attach unbound metadata to a guessed conversation, and runs before the locked-session early return. Locked rows retain identity, routing, and recency.
Stale-state cleanup: Doctor clears the legacy migration source whenever its existing stale-route repair clears Claude bindings; locked records remain excluded from that destructive repair.
Current main still needs the migration: Fetched main retains legacy-field lookup and has no Claude-field migration in the route-repair owner. The requested migration is therefore not already implemented there.
Findings None None.
Security None None.

How this fits together

OpenClaw stores native Claude conversation bindings alongside local session state. Doctor repairs those persisted bindings, which agent execution, history import, and manual compaction then use to locate the existing conversation.

flowchart TD
  A[Stored session records] --> B[Doctor route cleanup]
  B --> C[Legacy binding migration]
  C --> D{Safe conversation identity?}
  D -->|Yes| E[Provider-keyed binding]
  D -->|Ambiguous| F[Preserved record and warning]
  E --> G[Resume and history lookup]
Loading

Decision needed

Question Recommendation
Is requiring Doctor before legacy-only Claude sessions resume an accepted upgrade contract for this retirement? Confirm the documented cutover: Link or record acceptance of the Doctor prerequisite and reconciliation behavior, retaining the current migration and coordinated reader/writer retirement.

Why: The implementation and documentation consistently make this intentional change, but the linked staging discussion does not establish the specific accepted persistent-contract decision.

Before merge

  • Resolve merge risk (P1) - Upgraded legacy-only sessions lose native conversation lookup until Doctor runs; ambiguous records remain saved but cannot resume through the retired reader. The specific approval for accepting that operator requirement was not located.
  • Complete next step (P2) - Link the accepted migration and reader-retirement decision, or obtain explicit confirmation of the documented Doctor prerequisite.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +43, Tests +319, Docs +1. Total +363 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 5 71 28 +43
Tests 7 349 30 +319
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 422 59 +363

Review metrics

Metric Value Why it matters
Persistent contract 1 legacy field retired; 0 schema-version changes The compatibility boundary is session interpretation and upgrade sequencing rather than SQL schema migration.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-state-providers.ts, migration/backfill/repair: src/commands/doctor/shared/codex-route-session-repair.ts, unknown-data-model-change: src/commands/doctor/shared/codex-route-session-repair.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm Doctor-first upgrades (recommended)
    Accept the documented operator prerequisite and preserve the linked decision with the migration evidence.
  2. Retain lookup during migration rollout
    Defer reader removal if upgrades must continue resuming legacy-only sessions before Doctor runs.

Technical review

Best possible solution:

Keep Doctor as the canonical migration owner, with preserved conversation identity and an explicitly accepted upgrade prerequisite before retiring legacy lookup.

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

Yes, from source: current main leaves the Claude-only field outside canonical bindings, while the patch's migration tests provide concrete legacy-only and locked-row fixtures. No target code was executed during this read-only review.

Is this the best way to solve the issue?

Yes for the migration: it repairs the existing persistence owner and preserves binding precedence. Coordinated reader retirement is maintainable once its Doctor-first upgrade contract is explicitly accepted.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded migration and continuity repair for sessions retaining an older Claude binding representation.
  • merge-risk: 🚨 compatibility: The patch removes a shipped fallback and requires Doctor before legacy-only sessions can resume.
  • 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: Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. The updated body nevertheless reports compiled Doctor migration, database reopen, and repeat-repair observations for 10 sessions across two agents; live provider resume is not claimed, and history/resume coverage remains supplemental tests.

Evidence

What I checked:

  • Migration and locked-session correction: The migration preserves existing binding precedence, refuses to attach unbound metadata to a guessed conversation, and runs before the locked-session early return. Locked rows retain identity, routing, and recency. (src/commands/doctor/shared/codex-route-session-repair.ts:245, 96e5877b0f15)
  • Stale-state cleanup: Doctor clears the legacy migration source whenever its existing stale-route repair clears Claude bindings; locked records remain excluded from that destructive repair. (src/commands/doctor-session-state-providers.ts:470, 96e5877b0f15)
  • Current main still needs the migration: Fetched main retains legacy-field lookup and has no Claude-field migration in the route-repair owner. The requested migration is therefore not already implemented there. (src/commands/doctor/shared/codex-route-session-repair.ts:243, 43adb0b0084c)
  • Shipped compatibility boundary: The latest supplied release, v2026.9.3, accepts claudeCliSessionId when provider-keyed bindings are absent. Removing that fallback makes Doctor a prerequisite for those upgraded sessions. (src/config/sessions/cli-session-binding.ts, 1391f7cd2d40)
  • Persistence and consumer coverage: The new migration tests inspect reopened SQLite state, canonical metadata, provider-map precedence, ambiguous records, locked ownership, and repeat repair. The history test follows Doctor migration into actual history import for locked and unlocked records. These tests were inspected, not executed. (src/commands/doctor/shared/legacy-cli-session-binding.test.ts:28, 96e5877b0f15)
  • Updated runtime evidence and review continuity: The captured PR body reports compiled public Doctor and sessions commands over 10 synthetic sessions across two agents, database reopen checks, and stable repeated repair. It distinguishes artifact 41b019c889c4403b33993ee39d7eb04269b73316 from head 96e5877 and disclaims live provider execution. This addresses the earlier request for compiled migration observations; it does not establish a valid merge against the currently pinned base. (96e5877b0f15)

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • 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.

  • Link or record the accepted decision covering the Doctor prerequisite and legacy-reader retirement.

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 (2 earlier review cycles)
  • reviewed 2026-09-09T19:29:52.481Z sha 4ff4aa4 :: blocked before merge. :: [P1] [P1] Preserve resume bindings for locked sessions during migration
  • reviewed 2026-09-09T19:57:25.080Z sha 96e5877 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 9, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Sep 9, 2026
@obviyus
obviyus merged commit 227e2f4 into main Sep 9, 2026
195 of 197 checks passed
@obviyus
obviyus deleted the fix/legacy-cli-session-bindings branch September 9, 2026 20:28
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 227e2f4.

Proof: The compiled public Doctor flow repaired 10 synthetic sessions across two agents, listed them, reopened both databases, and repeated repair without changing the resulting binding state. Independent acceptance passed all six stored-state clauses. Exact-head local review passed with proof A, overall B, no findings, and no security concerns. Required CI passed, including ordinary/locked Doctor-to-history, binding save/fork, and stale-cleanup cases.

Before After
Old Claude IDs depended on a single-provider fallback. Doctor migrates safe IDs; runtime lookup and normal saves use provider-keyed bindings.
Locked rows could retain bytes but lose resume/history lookup. Their bindings migrate while identity, ownership, route, and recency stay intact.
Stale cleanup could be followed by obsolete-ID resurrection. Cleanup removes the old migration source too; stale conversations stay cleared.

Run openclaw doctor --fix after upgrading before resuming legacy-only sessions. Ambiguous records remain saved with reconciliation warnings. No live provider conversation or credential operation is claimed. The earlier failed proof and CI results remain retained; all 13 landed file blobs match the reviewed head.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 10, 2026
…penclaw#143347)

Related: openclaw#136257

## What Problem This Solves

Fixes an issue where Doctor leaves old Claude conversation IDs outside the canonical binding, while runtime lookup and normal saves still depend on the retired field. The upgrade must preserve locked-session continuity and prevent deliberately cleared stale conversations from returning.

## Why This Change Was Made

This follows the approved Doctor migration and reader-retirement scope from openclaw#136257. Doctor copies safe legacy IDs before removing the old field, and runtime lookup and normal saves change together. Existing canonical bindings, provider-keyed IDs, and resume metadata take precedence. Locked rows change only their binding representation; identity, ownership, route, and recency remain intact. Ambiguous records stay saved with reconciliation warnings.

The existing stale-route repair also clears the old migration source when it clears a Claude binding. A later migration step therefore cannot restore an obsolete conversation. Historical-field cleanup and protected plugin-slot handling remain available for unresolved old records.

## User Impact

Run `openclaw doctor --fix` after upgrading and before resuming sessions that only have the old field. Configured and locked conversations keep their IDs and resume metadata. Stale conversations stay cleared. Normal saves no longer recreate the retired field.

## Evidence

The initial main regression failed because the canonical binding was missing after Doctor repair. The first candidate passed 74 focused tests. Public Doctor proof and the first source review then exposed two connected gaps: stale-state resurrection and locked-session continuity. Both are repaired in this revision, with the earlier failures retained.

The compiled runtime built from this head passes public `doctor --fix --non-interactive`, `sessions --all-agents --json`, and repeated Doctor repair on 10 synthetic sessions across two agents. Saved state was checked after reopening both databases. Configured legacy IDs, canonical metadata, provider-keyed IDs, and locked ownership are preserved; ambiguous and empty records retain warnings; stale Claude state stays cleared. Every checked record is stable on repeat.

The normal native pre-commit hook passed on the revised source. [Required CI](https://github.com/openclaw/openclaw/actions/runs/34397549548) covers type checks and the updated migration, save, fork, and Doctor-to-history cases. Runtime artifact build `41b019c889c4403b33993ee39d7eb04269b73316` is the CI test merge containing head `96e5877b0f15dffe7baa9fd934cbdea07ccb694e`; those identities are kept separate in the proof.

No live provider conversation, credential operation, or schema change is claimed.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Sep 13, 2026
Related: #144392

Supersedes #145788 by @Marvinthebored. Thanks to @EnotionZ for the issue report. The original commit and authorship are preserved.

## What Problem This Solves

Canceling a reply makes the next turn forget the conversation, even though earlier messages still appear in history.

## User Impact

Stopping a reply keeps the established conversation available for the next turn. Invalid sessions and account boundaries still receive their existing checks.

## Why This Change Was Made

Retain established native bindings on cancellation. Clear unfinished replacements on both thrown errors and returned partial-output interruptions. An incomplete fork claim is restored by current-owner cleanup even when the signal is aborted. New claims, successor publication, and recovery arming retain their abort guards; all writes retain session, lifecycle, writer, and source-binding checks.

This preserves partial-output reporting from #126883 while removing cancellation-only binding invalidation. No schema, migration, configuration, protocol, or dependency change.

## Final-head evidence

Head `b068bf05618ddcd3e1b28894c68ad734e0eac997` includes a one-line test-type correction that passes the existing defined session entry; the command still reloads persisted state before choosing the next native binding. All 157 tests in that file, targeted lint, and formatting pass. Production source is unchanged from `2c163fd9eb57100ae3a2eec38cb6038e5f752851`.

The complete affected owner suites passed on fresh merge `4b66a1a18209c21b5e92986452b2b98b95ae6fa1`, with parents `2c163fd9eb57100ae3a2eec38cb6038e5f752851` and main `9542320aa5cdcc4af53e3b05ad75160992a34407`. All **28 complete canonical groups exited 0**: 46,971 labeled passes and 88 skips. Three cases are unlabelled in the native support summary; no status is inferred. This includes both fork-restoration cases and all four abort/timeout × established/replacement command cases. Complete current group membership, exact commands, numeric exits, and raw logs are retained.

```sh
env -u NO_COLOR -u FORCE_COLOR node --import tsx scripts/ci-run-node-test-shard.mts
```

Hosted [CI run 34774482283, attempt 1](https://github.com/openclaw/openclaw/actions/runs/34774482283) passed except `checks-node-compact-small-32` and its aggregate gate. Its QA-profile routing assertion is **base-red**: the same test fails on plain main `28887b564210326174413d0d8ade72b38268d5f3` and fresh candidate/main merge `7ea7374fcf62570c9b3fa631cf17072ef5eda2d6`, both exit 1. #143968 (`07b96d9b4122e1afdd0efbb662b2335eb716dfec`) added `qa-profile-run-status.test.ts` as a sixth workflow reader without updating the five-target expectation. This PR changes none of those routing inputs.

```sh
OPENCLAW_E2E_USE_PREBUILT_DIST=1 node scripts/run-vitest.mjs run \
  test/scripts/test-projects.test.ts -t 'routes QA Profile Evidence'
```

## Fork-claim correction

Candidate `2c163fd9eb57100ae3a2eec38cb6038e5f752851` restores a committed fork claim after cancellation before a successor appears. Previously, restoration rejected the aborted signal, lost the fork marker, and let the next command resume the source directly. Cleanup now uses the existing current-owner settlement assertion. Stale session, lifecycle, writer, placement, and source-binding checks remain enforced.

The regression fails on `e2ca5b29bfa09810aaa20eca8a1d0e85ced913c8`: the marker is absent and the next command receives `forkCliSessionOnResume=false`. After correction, both the recovery-error control and actual-signal cancellation pass; stored/cache markers and the source checkpoint remain, and the next command receives `forkCliSessionOnResume=true`.

```sh
env -u NO_COLOR -u FORCE_COLOR node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.agents.config.ts \
  src/agents/command/attempt-execution.cli.test.ts --maxWorkers=1 \
  -t 'preserves a restored fork marker before a successor'
```

Fresh merge `54a5c90a8b4585f72842e380365b95263b05983d` has first parent candidate `2c163fd9eb57100ae3a2eec38cb6038e5f752851` and second parent main `adb6e518a44218650883f3daec4bd319165e0017`. All **436 tests in seven complete focused files passed**, including command successor/flag cleanup, aborted pre-successor restoration, stale-store guards, returned interruption, thrown cancellation, auto-reply, and fork-runner siblings. This bounded rerun supplements the earlier complete suites.

Both real Gateway cancellation shapes also passed on that merge: before output (zero assistant events) and after first output. Both next turns resumed the same native binding, logged `historyPrompt=none`, and recalled `PEBBLE-7429`. Both drivers exited 0. The new catalog regression uses the real command/store entry point with a mocked native runner; it proves next-turn fork routing, not a new live source-transcript isolation capture.

Targeted lint passed, including max-lines:

```sh
pnpm exec oxlint --config .oxlintrc.json \
  src/agents/command/attempt-execution.ts \
  src/agents/command/attempt-execution.cli.test.ts
```

Original red evidence remains intact. Exact commands, merge identities, numeric exits, and complete captures are retained. The complete affected-suite rerun and final-head CI classification are recorded above.

## Earlier evidence

Validated corrected candidate `4fd555e5957f86289cf981ce4cf4b0bb1122c679` on temporary merge `d5f41d1cd6c9b603db32deec1d60c1ba93e7e04d`. Its parents are that candidate and main `a0cce74d389d737d6dcf21de7344af10cf862f72`.

All 28 complete canonical CI groups for the affected agent, reply, scheduled-run, and fast test suites exited 0 on that merge. Reporters label **46,859 tests passed and 88 skipped**. The full command persistence matrix passed, including unfinished-successor and temporary-flag cleanup for abort and timeout, plus established-binding resume.

Each complete group ran through the CI command, with its canonical configuration, include list and environment preserved:

```sh
node --import tsx scripts/ci-run-node-test-shard.mts
```

These are the complete affected test suites on the recorded merge. Final-head CI and its reproduced base-red exception are recorded above. Initial host setup failures were retained, then resolved by removing conflicting color settings and making GNU timeout available without replacing existing command resolution. No source assertions or timeouts were relaxed. One native summary leaves three cases unlabeled; the raw count line is retained without assigning them a status.

The real Gateway was also rerun from the merge with isolated state, workspace and port:

```sh
OPENCLAW_CONFIG_PATH="$PROOF/openclaw.json" OPENCLAW_STATE_DIR="$PROOF/state" \
  pnpm openclaw gateway --port 21978 --bind loopback
```

`chat.send` remembered a synthetic code, a second request started a long reply, `chat.abort` canceled it, and the next `chat.send` requested the code without repeating it.

| Cancellation | Recorded main | Corrected merge |
| --- | --- | --- |
| Before output | Fresh native session; `UNKNOWN` | Same native binding; `PEBBLE-7429` |
| After first output | Fresh native session; `UNKNOWN` | Same native binding; `PEBBLE-7429` |

Both drivers exited 0. Both continuations logged `useResume=true` with the same native fingerprint and `historyPrompt=none`. The pre-output run had zero assistant events before cancellation. Original red captures, merge parents, selection, exact commands, numeric exits and complete logs are preserved. Final-head CI and its reproduced base-red exception are recorded above.

## Compatibility and prior behavior

This deliberately changes the cancellation-only binding invalidation retained by #126883 and #128131. Partial output remains visible, interrupted turns remain unsuccessful, and successful authentication settlement remains suppressed. Expired-session recovery from #115513 and the retired-field migration from #143347 remain unchanged. There is no schema, migration, configuration, protocol, dependency, or permission change.

## Consumers

Command attempts, auto-reply turns, and scheduled turns consume the binding result. History import, session freshness, catalog continuation, export, runtime selection, and detached-media continuation read the retained binding or its explicit absence.

Catalog adoption seeds a binding with `forceReuse` and a one-shot fork marker. The command path claims that marker before execution and can persist a successor before final settlement. These writes require the current session, lifecycle, writer, and expected source binding. Successful settlement removes the temporary reuse flag; interrupted replacement cleanup removes the successor and flag together. An established binding remains available after cancellation. Cancellation before a fork successor appears restores the one-shot marker, so the next command must still fork from the source. Cache updates occur at the successful commit, and scheduled continuation publication follows base-session persistence.

## Evidence limits

The real Gateway sequences cover cancellation before output and after the first output. Both failed on main `fe3b2891fdeaa1a891d54cb2b306e975fc5408cf` and passed at `f9c5b148cf4d92de5211315a4e8c374bef279d9d`. The next turn resumed the same native binding without replaying local history and recalled the seeded code.

The initial 272 focused tests include command persistence and next-turn routing, auto-reply retention, failed-flush cleanup, and scheduled-run settlement. They ran on the branch based on `f85a9945daaebc61d041db27b4d3175d17082e37`. The later fresh merge `d5f41d1cd6c9b603db32deec1d60c1ba93e7e04d`, recorded above, passed all 28 complete affected test groups and both real Gateway cancellation shapes. No browser-click or platform-specific UI claim is made.

The two test suites that failed on the contributor head pass when applied to the refreshed main base and after correction. The original hosted failures were not reproduced in their original shard order, so their cause remains unclassified. No assertion or timeout was relaxed for this repair.

## Test ledger clarification

- The ordinary-abort policy and command assertions now require retention instead of unconditional deletion. Command coverage also checks the subsequent resume.
- The contributor-only interrupted-flush helper matrix was removed before the final diff because command persistence coverage supersedes it.
- The retained interrupted-partial-output fixture now names an established reusable session. Its unchanged clear assertion independently protects failed transcript flush; its partial-output, unsuccessful-hook, timeout, and authentication assertions remain.
- The new composition cases invoke `runAgentAttempt`, claim a fork, persist its successor, abort the actual signal, consume the production settlement result, reopen stored state, and check the next attempt. The channel regression invokes `executeAgentTurn`; the failed-flush regression invokes `runPreparedCliAgent`. Direct policy-unit assertions supplement these entry-point checks.

The earlier head `e2ca5b29bfa09810aaa20eca8a1d0e85ced913c8` only replaces a retained unflushed ID with the equivalent condition at its two consumers. Review accepted that behavior-preserving delta. CI run [34769866871](https://github.com/openclaw/openclaw/actions/runs/34769866871) passed at attempt 2 on this exact head. Attempt 1 had one test failure in an unrelated QA binary-admission case; it passed on the retry without a code or timeout change and is recorded as a flake.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
Related: openclaw#144392

Supersedes openclaw#145788 by @Marvinthebored. Thanks to @EnotionZ for the issue report. The original commit and authorship are preserved.

## What Problem This Solves

Canceling a reply makes the next turn forget the conversation, even though earlier messages still appear in history.

## User Impact

Stopping a reply keeps the established conversation available for the next turn. Invalid sessions and account boundaries still receive their existing checks.

## Why This Change Was Made

Retain established native bindings on cancellation. Clear unfinished replacements on both thrown errors and returned partial-output interruptions. An incomplete fork claim is restored by current-owner cleanup even when the signal is aborted. New claims, successor publication, and recovery arming retain their abort guards; all writes retain session, lifecycle, writer, and source-binding checks.

This preserves partial-output reporting from openclaw#126883 while removing cancellation-only binding invalidation. No schema, migration, configuration, protocol, or dependency change.

## Final-head evidence

Head `b068bf05618ddcd3e1b28894c68ad734e0eac997` includes a one-line test-type correction that passes the existing defined session entry; the command still reloads persisted state before choosing the next native binding. All 157 tests in that file, targeted lint, and formatting pass. Production source is unchanged from `2c163fd9eb57100ae3a2eec38cb6038e5f752851`.

The complete affected owner suites passed on fresh merge `4b66a1a18209c21b5e92986452b2b98b95ae6fa1`, with parents `2c163fd9eb57100ae3a2eec38cb6038e5f752851` and main `a9a9a16114bea90d6eac90486356697df2462cb9`. All **28 complete canonical groups exited 0**: 46,971 labeled passes and 88 skips. Three cases are unlabelled in the native support summary; no status is inferred. This includes both fork-restoration cases and all four abort/timeout × established/replacement command cases. Complete current group membership, exact commands, numeric exits, and raw logs are retained.

```sh
env -u NO_COLOR -u FORCE_COLOR node --import tsx scripts/ci-run-node-test-shard.mts
```

Hosted [CI run 34774482283, attempt 1](https://github.com/openclaw/openclaw/actions/runs/34774482283) passed except `checks-node-compact-small-32` and its aggregate gate. Its QA-profile routing assertion is **base-red**: the same test fails on plain main `a1105f105a093f768914a29c24b70d6ba406cad8` and fresh candidate/main merge `7ea7374fcf62570c9b3fa631cf17072ef5eda2d6`, both exit 1. openclaw#143968 (`41aebf15de48524e80c95f05e0c1212f2dfd29c6`) added `qa-profile-run-status.test.ts` as a sixth workflow reader without updating the five-target expectation. This PR changes none of those routing inputs.

```sh
OPENCLAW_E2E_USE_PREBUILT_DIST=1 node scripts/run-vitest.mjs run \
  test/scripts/test-projects.test.ts -t 'routes QA Profile Evidence'
```

## Fork-claim correction

Candidate `2c163fd9eb57100ae3a2eec38cb6038e5f752851` restores a committed fork claim after cancellation before a successor appears. Previously, restoration rejected the aborted signal, lost the fork marker, and let the next command resume the source directly. Cleanup now uses the existing current-owner settlement assertion. Stale session, lifecycle, writer, placement, and source-binding checks remain enforced.

The regression fails on `e2ca5b29bfa09810aaa20eca8a1d0e85ced913c8`: the marker is absent and the next command receives `forkCliSessionOnResume=false`. After correction, both the recovery-error control and actual-signal cancellation pass; stored/cache markers and the source checkpoint remain, and the next command receives `forkCliSessionOnResume=true`.

```sh
env -u NO_COLOR -u FORCE_COLOR node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.agents.config.ts \
  src/agents/command/attempt-execution.cli.test.ts --maxWorkers=1 \
  -t 'preserves a restored fork marker before a successor'
```

Fresh merge `54a5c90a8b4585f72842e380365b95263b05983d` has first parent candidate `2c163fd9eb57100ae3a2eec38cb6038e5f752851` and second parent main `e08263bdd3341031c219bb147638f23a1f4c3c03`. All **436 tests in seven complete focused files passed**, including command successor/flag cleanup, aborted pre-successor restoration, stale-store guards, returned interruption, thrown cancellation, auto-reply, and fork-runner siblings. This bounded rerun supplements the earlier complete suites.

Both real Gateway cancellation shapes also passed on that merge: before output (zero assistant events) and after first output. Both next turns resumed the same native binding, logged `historyPrompt=none`, and recalled `PEBBLE-7429`. Both drivers exited 0. The new catalog regression uses the real command/store entry point with a mocked native runner; it proves next-turn fork routing, not a new live source-transcript isolation capture.

Targeted lint passed, including max-lines:

```sh
pnpm exec oxlint --config .oxlintrc.json \
  src/agents/command/attempt-execution.ts \
  src/agents/command/attempt-execution.cli.test.ts
```

Original red evidence remains intact. Exact commands, merge identities, numeric exits, and complete captures are retained. The complete affected-suite rerun and final-head CI classification are recorded above.

## Earlier evidence

Validated corrected candidate `4fd555e5957f86289cf981ce4cf4b0bb1122c679` on temporary merge `d5f41d1cd6c9b603db32deec1d60c1ba93e7e04d`. Its parents are that candidate and main `e0ad90d2bc2effce521cbde79cec2be56cece725`.

All 28 complete canonical CI groups for the affected agent, reply, scheduled-run, and fast test suites exited 0 on that merge. Reporters label **46,859 tests passed and 88 skipped**. The full command persistence matrix passed, including unfinished-successor and temporary-flag cleanup for abort and timeout, plus established-binding resume.

Each complete group ran through the CI command, with its canonical configuration, include list and environment preserved:

```sh
node --import tsx scripts/ci-run-node-test-shard.mts
```

These are the complete affected test suites on the recorded merge. Final-head CI and its reproduced base-red exception are recorded above. Initial host setup failures were retained, then resolved by removing conflicting color settings and making GNU timeout available without replacing existing command resolution. No source assertions or timeouts were relaxed. One native summary leaves three cases unlabeled; the raw count line is retained without assigning them a status.

The real Gateway was also rerun from the merge with isolated state, workspace and port:

```sh
OPENCLAW_CONFIG_PATH="$PROOF/openclaw.json" OPENCLAW_STATE_DIR="$PROOF/state" \
  pnpm openclaw gateway --port 21978 --bind loopback
```

`chat.send` remembered a synthetic code, a second request started a long reply, `chat.abort` canceled it, and the next `chat.send` requested the code without repeating it.

| Cancellation | Recorded main | Corrected merge |
| --- | --- | --- |
| Before output | Fresh native session; `UNKNOWN` | Same native binding; `PEBBLE-7429` |
| After first output | Fresh native session; `UNKNOWN` | Same native binding; `PEBBLE-7429` |

Both drivers exited 0. Both continuations logged `useResume=true` with the same native fingerprint and `historyPrompt=none`. The pre-output run had zero assistant events before cancellation. Original red captures, merge parents, selection, exact commands, numeric exits and complete logs are preserved. Final-head CI and its reproduced base-red exception are recorded above.

## Compatibility and prior behavior

This deliberately changes the cancellation-only binding invalidation retained by openclaw#126883 and openclaw#128131. Partial output remains visible, interrupted turns remain unsuccessful, and successful authentication settlement remains suppressed. Expired-session recovery from openclaw#115513 and the retired-field migration from openclaw#143347 remain unchanged. There is no schema, migration, configuration, protocol, dependency, or permission change.

## Consumers

Command attempts, auto-reply turns, and scheduled turns consume the binding result. History import, session freshness, catalog continuation, export, runtime selection, and detached-media continuation read the retained binding or its explicit absence.

Catalog adoption seeds a binding with `forceReuse` and a one-shot fork marker. The command path claims that marker before execution and can persist a successor before final settlement. These writes require the current session, lifecycle, writer, and expected source binding. Successful settlement removes the temporary reuse flag; interrupted replacement cleanup removes the successor and flag together. An established binding remains available after cancellation. Cancellation before a fork successor appears restores the one-shot marker, so the next command must still fork from the source. Cache updates occur at the successful commit, and scheduled continuation publication follows base-session persistence.

## Evidence limits

The real Gateway sequences cover cancellation before output and after the first output. Both failed on main `0c664785f82d3af6c2101efb53d7269d30261f4c` and passed at `f9c5b148cf4d92de5211315a4e8c374bef279d9d`. The next turn resumed the same native binding without replaying local history and recalled the seeded code.

The initial 272 focused tests include command persistence and next-turn routing, auto-reply retention, failed-flush cleanup, and scheduled-run settlement. They ran on the branch based on `329bc5bf9694af38477f9fd45ebe47ad86b538a9`. The later fresh merge `d5f41d1cd6c9b603db32deec1d60c1ba93e7e04d`, recorded above, passed all 28 complete affected test groups and both real Gateway cancellation shapes. No browser-click or platform-specific UI claim is made.

The two test suites that failed on the contributor head pass when applied to the refreshed main base and after correction. The original hosted failures were not reproduced in their original shard order, so their cause remains unclassified. No assertion or timeout was relaxed for this repair.

## Test ledger clarification

- The ordinary-abort policy and command assertions now require retention instead of unconditional deletion. Command coverage also checks the subsequent resume.
- The contributor-only interrupted-flush helper matrix was removed before the final diff because command persistence coverage supersedes it.
- The retained interrupted-partial-output fixture now names an established reusable session. Its unchanged clear assertion independently protects failed transcript flush; its partial-output, unsuccessful-hook, timeout, and authentication assertions remain.
- The new composition cases invoke `runAgentAttempt`, claim a fork, persist its successor, abort the actual signal, consume the production settlement result, reopen stored state, and check the next attempt. The channel regression invokes `executeAgentTurn`; the failed-flush regression invokes `runPreparedCliAgent`. Direct policy-unit assertions supplement these entry-point checks.

The earlier head `e2ca5b29bfa09810aaa20eca8a1d0e85ced913c8` only replaces a retained unflushed ID with the equivalent condition at its two consumers. Review accepted that behavior-preserving delta. CI run [34769866871](https://github.com/openclaw/openclaw/actions/runs/34769866871) passed at attempt 2 on this exact head. Attempt 1 had one test failure in an unrelated QA binary-admission case; it passed on the retry without a code or timeout change and is recorded as a flake.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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