Repository navigation
fix: forked claude-cli conversation starts with an empty model context - #155591
Patrick-Erichsen merged 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:49 PM ET / 22:49 UTC (Revision 8). ClawSweeper reviewWhat this changesPreserve checkpointed native CLI conversation context when creating whole-session forks, and share guarded child-session claiming, recovery, and persistence across command and live replies. Merge readiness✅ Ready for maintainer review Keep open: the fix remains necessary on current main, the earlier account-validation and checkpoint concerns are resolved, and the published native-runtime evidence supports the repaired behavior. No blocking patch defect was found. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores the visible conversation separately from the native CLI session that holds the model’s context. Fork creation must carry both histories forward, while the execution owner validates the binding and saves the child’s distinct native session. flowchart TD
A[Parent conversation] --> B[Whole-session fork]
B --> C[Copy visible transcript]
B --> D[Check native fork capability and checkpoint]
D --> E[Validate account and execution owner]
E --> F[Branch native CLI session]
F --> G[Save distinct child binding]
C --> H[Child conversation]
G --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +97, Tests +447, Docs +1. Total +545 across 16 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Use the existing session owner to create checkpoint-pinned native children with independent IDs and normal account/environment validation. Do we have a high-confidence way to reproduce the issue? Yes: create a whole-session fork of a Claude CLI conversation and ask the child about a parent-only codeword. Current-main source lacks the native-binding handoff, and published before/after Gateway traces demonstrate the failure; this read-only review did not execute it. Is this the best way to solve the issue? Yes: extending the existing binding and execution owners repairs both creation paths and the live caller without a parallel store or new configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ac85f6dc13ab. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
c899871 to
b6d75d6
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
c3f3dfd to
5868ee4
Compare
Carry checkpointed native context through whole-session forks and share owner-bound claim, restore, and successor publication across CLI callers. Co-authored-by: Marvinthebored <[email protected]>
5868ee4 to
989056f
Compare
|
Integrated the checkpointed native fork with current main's shared session owner, preserving @Marvinthebored's contribution. The repair also moves plugin preparation outside the SQLite transaction and fences cancelled or released claims/successor writes. Paired regressions reproduce missing child bindings, unsupported checkpoint capability, plugin work inside BEGIN, and cancelled publication before the fix. Final validation: 317 focused/sibling tests, 95 final caller retests, the full changed-file gate (all 27 test type graphs, production types, Knip, lint/format, storage guards), and canonical P0 autoreview pass. Fresh candidate proof uses the actual fork builder, admission/executor, SQLite callbacks, and installed Claude CLI 2.1.219 with a local deterministic API: fresh child forgets the codeword; pinned fork remembers the recorded parent checkpoint, receives a distinct native ID, resumes that ID next turn, and leaves the advanced parent unchanged. Both missing-capability controls reject before spawning and preserve the marker. Six native processes exit0. This is reviewer native-runtime proof, not authenticated cloud inference; the contributor's separate authenticated Gateway trace is preserved in the body. The body includes per-file test time and available historical CI cost, addressing the latest Rank-up move. Production net+97 absorbs existing callback duplication and supplies the missing creation/live lifecycle boundaries; no schema/config/protocol additions. Root also directly inspected sibling Codex thread/fork source and the installed Claude flag contract. Public candidate989056f18ab145cc6a4769647104b4516d700671; final-head hosted build/CI and native landing checks remain required. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Required full build verification for
Build log SHA-256: |
|
Merged via squash.
|
Carry checkpointed native context through whole-session forks and share owner-bound claim, restore, and successor publication across CLI callers. Co-authored-by: Patrick Erichsen <[email protected]> Co-authored-by: Marvinthebored <[email protected]>
Closes #155590
Forking a native CLI conversation copied the visible transcript but dropped the native context. The child could therefore forget the parent conversation; the live-reply path also lacked the callbacks needed to branch the native session safely.
This keeps the contributor's checkpointed fork handoff and integrates it with current main's shared CLI session owner. Whole-session Gateway and automatic parent forks copy only checkpointed bindings whose backend supports both fork and checkpoint resume. The child drops the parent's force-reuse flag and reseed receipt, retains account/environment validation, claims its one-shot fork, and persists the new native session ID for later turns. Per-message forks remain fresh because they use a different transcript cutoff.
The maintainer repair also:
No schema, configuration option, protocol, migration, or stored-field shape changes.
Reviewer verification
Integration base:
8ae1e870c1ad684b32be61bd3d460e06deb083e5. Candidate commit:989056f18ab145cc6a4769647104b4516d700671.Paired regressions fail on current-main production for the Gateway fork builder, public
sessions.create, and automatic parent-fork owner. Additional incoming-candidate controls fail for missing checkpoint-resume capability, plugin normalization insideBEGIN, and cancelled live claim/successor writes; all pass after the owner repair.317 targeted and sibling tests passed. After the final caller simplification, the affected live and command suites passed again (95 tests). Coverage includes real SQLite publication, released/replaced owners, retry restoration, auth profile/epoch invalidation, legacy IDs, catalog force reuse, unsupported backends, and native runner spawn/recovery behavior.
Fresh native proof uses candidate fork construction, the actual admission/execution and SQLite callback owners, installed Claude CLI 2.1.219, and an isolated deterministic local Anthropic API fixture. It uses no cloud credentials or production profile:
PELICAN-42; native ID75f9928d-…; checkpoint recordedNO-CODEWORDTURTLE-99, same parent native IDPELICAN-42, distinct IDc7bb4368-…PELICAN-42, same child IDTURTLE-99, same parent ID and unchanged parent bindingAll six native processes exited 0; the proof test passed in 4.681s. A separate seven-process native dependency probe also showed that an unpinned fork sees the later
TURTLE-99, proving the saved checkpoint matters. These are reviewer-run native proofs with a local model fixture. The contributor's authenticated throwaway-Gateway trace is retained below and is separate evidence.Canonical autoreview (Codex, default P0 scope) exited 0,
scoped-clean, with no findings. The full changed-file gate passed: production types, all 27 test type graphs, all Knip scans, lint/format, storage guards, and zero runtime import cycles. Required full build verification for989056f18ab145cc6a4769647104b4516d700671:pnpm buildpassed, exit 0, 446.515 seconds; Node 24.19.0 and pnpm 12.5.1 with frozen dependencies in an isolated source workspace and synthetic HOME.8ae1e870c1ad684b32be61bd3d460e06deb083e5, with unchanged UI/build configuration. Named UI follow-up: consolidate mixed static/dynamic imports for session roster caching, snapshot invalidation, and composer draft persistence.Build log SHA-256:
f0ebacafa6eb061e18cd2e6c234976a3292c79cabdd6d3f9716c2fe9badefacc. This completes the build gate alongside the published paired native CLI and Gateway proof.Test cost and scope
Per-file Vitest wall time includes hooks; wrapper compilation/import overhead is separate. These measured times address the latest ClawSweeper
Rank-up movesrequest.src/agents/cli-session.test.tssrc/gateway/session-create-fork-entry.test.tssrc/gateway/server.sessions.create.forks.test.tssrc/config/sessions/session-accessor.parent-fork.test.tssrc/auto-reply/reply/agent-runner-execution-cli-admission.test.tssrc/agents/cli-session-store.test.tssrc/agents/command/attempt-execution.cli.test.tsAvailable prior-head CI run: 151 jobs, 51,380 summed job-seconds. This is total job time, not marginal PR cost. Selected jobs: build-artifacts 304s; test-types-core-4 160s; test-types-core-2 244s; dependencies 79s. The three latter failures were the fixture types/unused exports repaired here; final exact-head CI is the landing gate.
Production: +144/-47, net +97 lines. Tests: +491/-44, net +447. Docs: +1. Sharing callbacks and removing caller backend discovery absorbs existing duplication; the remaining growth implements the missing checkpointed native handoff at both creation owners and the live caller's lifecycle-safe publication. No parallel state store or provider-specific core policy is added.
Original implementation and authenticated Gateway proof by @Marvinthebored; maintainer integration and additional verification are AI-assisted through Codex.
Contributor's original report and earlier revision proof
Closes #155590
AI-assisted (Claude Code, run by @Marvinthebored); reviewed and tested by a human.
What Problem This Solves
Fixes an issue where users who fork a conversation running on a native CLI backend (
claude-cli) would get a child session that starts with an empty model context. The Control UI shows the parent's transcript in the child, but the agent's first reply behaves like a brand-new session because the nativeclaudeprocess is started fresh instead of resuming the parent's session. This affects Control UI Fork conversation,sessions.createwithfork: true, andsessions_spawnwithcontext: "fork".Why This Change Was Made
Forked session entries now carry the parent's CLI session bindings, marked for a one-shot fork resume, so the child's first turn resumes the parent's native session with the backend's fork flag (
--fork-sessionforclaude-cli) and then keeps its own new native id, as the existingforkNextResumemachinery already supports. The copied binding does not setforceReuse: the child's first turn runs the same auth profile, auth epoch, cwd, and MCP checks as any other stored session, so an account or environment change starts the child fresh instead of resuming under the wrong credential. Only bindings with a recordedresumeCheckpointIdare copied, because the runner pins the fork resume to that checkpoint (--resume-session-at); without one the branch point would follow whatever the parent did next. Only backends that expose a fork flag are copied; any other backend starts a fresh native session as before, since resuming without a fork flag would share the parent's native thread. Legacy per-session ids on a reused target and the parent's reseed receipt are dropped, because both name a session that is not the child's. Per-message "Fork from here" is intentionally unchanged: it cuts the transcript at an earlier point, so a fresh native session is correct there.Live testing surfaced a second gap: the live chat turn runs through
src/auto-reply/reply/agent-runner-cli-candidate.ts, which never passedforkCliSessionOnResumeor the fork-store claim/restore/persist callbacks to the CLI runner. Onlysrc/agents/command/attempt-execution.tsdid. With the marker set but ignored, the child resumed the parent's native session without--fork-sessionand shared the parent's thread. The callback wiring now lives in one shared helper,buildCliSessionForkRunParamsinsrc/agents/command/session-store.ts, used by both callers, so the two paths cannot drift apart again.A third gap was in the shared successor writer,
persistCliSessionForkSuccessorInStoreinsrc/agents/command/session-store.ts. When the child's first turn claims the fork and the backend reports the new native id, that writer rebinds the child before the rest of the turn can fail, so a retry does not re-fork the parent. It used to writeforceReuse: trueon that rebinding, whichresolveCliSessionReusetreats as an unconditional reuse. Between successor persistence and the next completed turn, a change of auth profile, auth epoch, cwd, or MCP config would then have been ignored. The writer now spreads the source binding and replaces onlysessionId, so the parent's fingerprints carry over and a later turn validates the successor like any other stored session. A source binding that already carriesforceReuse(catalog adoption of an external session, which has no fingerprints) keeps it, so that path is unchanged.User Impact
Forking a
claude-cliconversation now produces a child that remembers the parent conversation, matching what the copied transcript and the "forked session" sidebar label already promise. The parent's binding is untouched, so the parent continues unaffected. Backends without a fork flag see no behavior change. Documentation indocs/gateway/cli-backends.mddescribes the fork behavior.Evidence
Three regression tests were added, one per fork path (
buildForkedGatewaySessionEntry,forkSessionEntryFromParentTargetvia the SQLite parent-fork accessor, and thesessions.creategateway method). Stock vs patched, with only the five source files swapped and the tests left in place:The unit test also asserts the negative cases: a parent binding for a backend without a fork flag is not copied, a parent binding without a recorded checkpoint is not copied (the child starts fresh), the parent's
reseedReceiptis dropped, stalecliSessionIds/claudeCliSessionIdon a reused target are cleared, and the parent entry is not mutated.Neighboring suites (
src/config/sessions,src/gateway/session-create*,src/agents/cli-session*,src/agents/command/session-store*,src/agents/cli-backends*): 2038 passed, 2 failed. The 2 failures are insession-transcript-reconcile.lease.test.tsand fail identically on the base commit with this change reverted, so they are unrelated.tsgo -p tsconfig.core.json --noEmitreports no errors in the changed files.oxlint,oxfmt --check, and the import-cycle check pass on the changed files.A fourth regression test covers the live chat path (
src/auto-reply/reply/agent-runner-execution-cli-admission.test.ts, "honors a forked child's one-shot fork marker on its first native resume"). Stock vs patched, with onlyagent-runner-cli-candidate.tsswapped and the test left in place:Account validation on the copied binding is covered in
src/agents/cli-session.test.ts("validates a forked binding against the child's account before resuming it"): the forked binding carries the parent's fingerprints and noforceReuse, andresolveCliSessionReusereturnsinvalidatewithauth-profile/auth-epochwhen the child's current profile or epoch differs, andreusewhen they match. Fork suites after this change: 5 files, 241 tests passed.Live proof against a running
claudebinary, on a throwaway gateway built from this branch (state dir and config isolated,claude-cli/claude-haiku-4-5,OPENCLAW_CLI_BACKEND_LOG_OUTPUT=1to log the spawned argv). Procedure: send "The codeword is PELICAN-42" to a fresh parent session, fork it withsessions.create { parentSessionKey, fork: true }, then ask the child "What is the codeword?".Successor persistence (fourth commit). New test in
src/agents/command/session-store.test.ts, "keeps account checks on the fork successor when the source was not force-reused": a source binding withauthProfileId: "claude:work",authEpoch: "epoch-1",authEpochVersion: 3and a checkpoint is claimed and the successor persisted; the stored binding is the source binding with onlysessionIdreplaced and noforceReuse, in memory and after a freshloadPersistedSessionEntry. Feeding that persisted binding toresolveCliSessionReusewithauthProfileId: "claude:personal",authEpoch: "epoch-2"returns{ mode: "invalidate", invalidatedReason: "auth-profile" }, so a credential change after successor persistence starts the child fresh instead of resuming the retained native context. With the previous writer the persisted binding carriedforceReuse: true, whichresolveCliSessionReusehonors before any fingerprint check. The existing successor assertions inattempt-execution.cli.test.tsandagent-runner-execution-cli-admission.test.tsnow assert thatforceReuseis absent on the persisted successor. Fork suites after this commit: 6 files, 345 tests passed.Data model: no stored fields are added, removed, or renamed.
forceReuseis still read and written where it was; the only change is that new fork-successor writes no longer add it. Existing store entries need no migration.Live proof of the same build (throwaway gateway, same procedure as above):
Typecheck boundary:
tsc -p tsconfig.core.json --noEmiton this branch reports no errors in the changed files; the remaining output is declaration-portability noise (TS4094/TS2883) in unrelated test-support and package files (the checked-intsgorunner was not usable in this symlinked checkout, so this was run with the bundledtsc).An earlier revision of this branch (before the third commit) produced the same child reply with
--resume <parent> --fork-sessionand no checkpoint pin, and the revision before that (entry construction fixed, live path not yet wired) spawned the child with--resume <parent>and no--fork-session, which is what motivated the shared helper.Rebased onto current
main(no conflicts remain).