← Back to Pull requests

fix(claudecode): adopt the parent's Claude Code session on a fork child #284

Closed
unknown closed this pull request without merging on Nov 18, 2026 04:47 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 06:41 UTC
Author

A memory-tier fork clones the parent's compute, so the child's harness memory holds the parent's Claude Code session under the parent's UID and nothing under the child's. Every child turn then failed with errStateLost. This fixes that inside the harness, with no proto, capability or spec change. Fixes #255.

  • On a fork child's first turn the harness continues the parent's session under the child's own id: claude --resume <parent id> --fork-session --session-id <child id>. Later child turns resume the child's id. The parent's entry is only read.

  • Adoption needs a fork marker in the child's history with no turn after it, a fork point (the last execution before the marker, an INPUT-only one included) that this harness started, and exactly one idle session whose last execution is the fork point. An unknown fork point is never skipped for an older one, so a fork of a child whose turn never reached the harness, or of a parent turn the harness refused before starting, fails closed. Zero or ambiguous matches, and non-fork sessions with no state, also fail closed with errStateLost.

  • Until Claude Code confirms the child's own id, every child attempt rechecks that the parent is still idle at the fork point, so a retry after a cancelled or failed attempt never copies turns the parent ran later.

  • While such an attempt runs it reserves the parent, and any unconfirmed fork in between, until the attempt ends: their turns fail with a fork-in-progress error, so the parent's transcript can't move on before Claude Code copies it. A parent turn refused this way counts as never started, so a fork taken at it fails closed.

  • ForkSafe stays false; it still means a fork by replay is not supported. The package doc, docs/harness-authoring.md and a changelog fragment describe the new behavior.
  • Tested:

  • go vet, gofmt and go test -race in integrations/claudecode, including new fake-claude tests for adoption, the fail-closed cases, a new fork adopting again after the parent's next turn, child retries against an unchanged, advanced or busy parent, an unconfirmed parent, a fork of a fork, and the parent reservation (a paused child refusing the parent's turn, release on every exit path, retries, concurrent forks).

  • TestForkOverWire: controller.Fork on a real parent journal, then the child under its own UID over harnesswire.

  • Claude Code 2.1.311 against a local fake API with an isolated config dir: --resume P --fork-session --session-id C reports C, leaves P.jsonl byte-identical and writes a self-contained C.jsonl. --session-id with --resume and no --fork-session, a child id already in use, and a missing parent transcript each exit 1.
  • Diff: 336 lines (+252 / -84) across 4 files Reviewer: aramase Review duration: 1325m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 336 lines diff across 4 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #284"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.2% (MEDIUM) · Higher = larger blast radius
    47.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.6% · Safe to merge
    18.6%