Skip to content

Fork from the saved session after a restart - #191

Merged
khalilgharbaoui merged 1 commit into
masterfrom
fix/fork-after-restart
Nov 15, 2026
Merged

khalilgharbaoui merged 1 commit into
masterfrom
fix/fork-after-restart

Conversation

@khalilgharbaoui

Copy link
Copy Markdown
Owner

A fork of a whole conversation that an earlier opencode process served now starts from the parent's saved Claude session instead of replaying the thread as text (h #g319).

What happened

On 2026-11-15 the maintainer forked the director session through its last message. opencode had restarted three times since the parent's last turn, and the fork checkpoints (h #g305) live in memory, so the fork's first turn replayed 2,888 messages bounded to 180,000 characters and lost almost all of its context. The parent's resume record and transcript were on disk.

Change

  • findForkResumePoint (src/session-resume-store.ts) looks for a sibling key's record (forkSiblingSignature: only the affinity may differ), the same binary, not being written to, its transcript on disk, and a strict chain this history continues with nothing but the reply past it. Longest match wins.
  • The prologue runs it after the in-memory fork lookup, only where the turn was about to replay, gated on forkFromCheckpoint, resumeAfterRestart and the --fork-session probe, and starts the fork as forkSessions does: --resume <id> --fork-session headless, forkOf on the interactive transport. The parent keeps its record and its conversation.
  • It is given the raw prompt, as the record is written, not the note-filtered thread: found live, where a reply carrying the plugin's usage note made every fork miss.
  • A refused candidate logs one INFO line with its reason.

Checked

  • Live on opencode 2.2.6 (private serve, scratch XDG dirs, Haiku 5.5): two turns, a server restart, POST /api/session/{id}/fork with {} (boundary through, like the maintainer's). The fork spawned with --resume <parent> --fork-session, wrote 29 tokens to the prompt cache against 21,163 for the replayed fork, and answered with both codewords from before the restart.
  • test/fork-from-checkpoint.test.ts: the fork after a simulated restart (with a noted reply), the parent continuing its own session, and the refusals (earlier message, gone transcript, forkFromCheckpoint: false, resumeAfterRestart: false). Controls with the branch off and with the filtered prompt both fail.
  • npm run typecheck, npm test (2,325 pass), npm run build.

Not covered

A fork from an earlier message after a restart still replays: the record keeps no checkpoint to cut at. Same snapshot caveat as forkFromCheckpoint: the fork answers under the system prompt the parent first ran with.

A fork of a whole conversation served before an opencode restart replayed it as text, because the fork checkpoints are kept in memory. The parent's resume record is on disk, so the fork now starts from it with --resume <id> --fork-session. A fork from an earlier message still replays (h #g319).
@khalilgharbaoui
khalilgharbaoui merged commit 1684624 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