Skip to content

Carry a moved session into its new directory - #189

Merged
khalilgharbaoui merged 2 commits into
masterfrom
fix/session-move
Nov 15, 2026
Merged

khalilgharbaoui merged 2 commits into
masterfrom
fix/session-move

Conversation

@khalilgharbaoui

Copy link
Copy Markdown
Owner

A session opencode moved to another working directory replayed its whole thread as text on the next turn (h #g317).

What happened

On 2026-11-14 a lane's Code Mode execute moved its session into a fresh worktree (session_move). The session's directory is the spawn's cwd and the first segment of the session key, so the next step landed on a key nothing had answered and replayed the history into a new Claude session. agent-guard refused that replay by size ("the prompt exceeds the assignment-probe scan cap"), which v0.73.4 now reports as prompt blocked (h #g314). This PR removes the replay itself.

Measured (Claude Code 2.1.322, Haiku 5.5, two scratch repos)

  • --resume <id> from another directory continues the conversation, and the model reports the NEW directory: the environment block is not snapshotted.
  • With no copy, the CLI keeps appending under the OLD directory's project folder, where the restart lookup and the interactive transport's tail never look.
  • Cache: a same-directory resume wrote 25 tokens, the first resume from the new directory 3,630, a later one 0.

Change

  • modelSiblingSignature lets the cwd differ, like the model, effort, spawn settings and account. The shared default affinity keeps its directory.
  • findSiblingResumePoint checks the transcript under the sibling's own cwd and returns siblingCwd. The caller copies it with carryTranscriptToAccount's new sourceCwds (same never-overwrite and longest-copy rules), stops the old key's child, and transfers the session.
  • conversationIdentity ignores the cwd, so the step answering the call that moved the session finishes on the child parked in it, in the old directory (h #g271's routing). The next turn carries.
  • It reads the resume store, so resumeAfterRestart: false still replays a move, as it does a model change.

Live check (opencode 2.2.6, scratch serve, this build)

Session in repo A answered a codeword, POST /api/session/{id}/move to repo B, next turn: spawned in repo B with --resume of the same Claude session, answered with the codeword and repo B as its directory, transcript copied (original untouched). Cache on that turn: 38,958 read, 18,292 written, because opencode's forwarded system prompt carries the directory too.

Checks

  • npm run typecheck, npm test (2322 pass), npm run build
  • test/session-move.test.ts: real doStream turns in two directories of one opencode session, with a fake CLI that resumes only a transcript under its own directory (so the copy is proven). Carried in process and after a restart, another session never carried, resumeAfterRestart: false replays. The two carry tests fail with the signature change switched off.
  • test/effort-sessions.test.ts: a step answering a call parked in the old directory finishes on that child (without the routing it never reaches it).
  • test/account-transcript.test.ts: sourceCwds, including moving back.

Not measured live: the mid-turn move through Code Mode, and the interactive transport.

opencode 2 moves a session between directories (session_move into a lane's worktree), and the cwd is the first segment of the session key, so the next turn replayed the whole thread, where a guard hook could refuse it by size. Measured on Claude Code 2.1.322: --resume from another directory keeps the conversation and the model sees the new directory, but without a copy the CLI keeps appending under the old directory's name. The sibling lookup now lets the cwd differ, the transcript is copied under the new directory before the resume, and a step answering the call that moved the session finishes on the old directory's child (h #g317).
@khalilgharbaoui
khalilgharbaoui merged commit 51bc536 into master Nov 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant