Skip to content

fix(server): forks whose source session is gone start fresh instead of failing every send - #27729

Merged
juliusmarminge merged 11 commits into
mainfrom
fix/issue-27709
Nov 11, 2026
Merged

juliusmarminge merged 11 commits into
mainfrom
fix/issue-27709

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Problem

Suppose a thread is forked natively (same provider, "Fork from this response") and its source thread's native provider session no longer exists, for example because it was deleted from OpenCode's session database. Then every send in the fork fails with "Provider turn failed to start", forever. Each provider-turn.start effect retries forkThread 5 times against the missing session. The fork transfer stays pending, and the orchestrator re-targets it at every new run, so the fork can never recover.

To reproduce on main: start an OpenCode thread with two turns. Delete its native session (opencode api DELETE /api/session/<id>). Fork from the first reply and send. Every send fails with Session not found: ses_….

Change

ProviderTurnStartService now treats a native fork the way it already treats a failed resume:

  • While willRetry is true, a failed forkThread still rethrows, so transient failures (for example a source session that is still working) keep their retries and a later attempt can still fork natively.
  • On the final attempt, the turn starts in a fresh native session (ensureThread with forceNewNativeThread). That session receives the fork's history as a full_thread_summary context handoff, built from the source thread's items up to the fork point, as the orchestrator's portable fork does. The fork transfer is resolved as resolved_portable / portable_context, so later sends resume the fresh session and never call forkThread again. The fresh provider thread's forkedFrom is cleared because it did not inherit the source's native history.

A fork whose source session is healthy is unchanged: it still forks natively.

Scope and approval

Fixes #27709

Triaged via the automated issue flow.

Verification

Focused tests, in apps/server/src/orchestration-v2/ThreadFork.execution.test.ts:

  • a native fork whose source session is gone starts fresh with the source history. On main this fails with expected [ 'Provider turn failed to start' ] to deeply equal []. With the fix it passes, and the source user message reaches the fresh session's turn input.
  • a native fork that fails before its last attempt still forks natively asserts 2 forkThread calls and a consumed / native_fork transfer. It fails if the willRetry guard is removed.
  • vp run check:changed passes: format, lint, knip, typecheck, and 43 tests across the 3 related files.

Runtime transcript from the real app: web dev server plus the server CLI, OpenCode 2.2.4, anthropic/claude-haiku-5-5. Each side ran on a fresh synthetic database (T3CODE_DEV_SEED=0). Steps: a parent thread with "Reply PARENT-ONE, remember the codeword BLUEBIRD", then a second turn, then delete the parent's native session, then "Fork from this response" on the first reply in the web UI, then three sends in the fork.

main 8d012a6 (before) this branch 9740125 (after; the implementation is the same at head)
Send 1 in the fork (web UI) "Provider turn failed to start · Session not found: ses_e722739a…" Replies BLUEBIRD (the parent's history reached the fresh session)
Sends 2 and 3 status: failed, error: Session not found: ses_e722739a… status: completed, "Codeword: BLUEBIRD / First message reply: PARENT-ONE"
provider-turn.start attempts per send 5, 5, 5 5 (then the fallback), 1, 1
Fork transfer pending, re-targeted at run 3 resolved_portable / portable_context
Server log — WARN Starting a native fork in a fresh native session
Fork from the latest reply (variant) fails the same way —
Control: fork of a healthy parent completes, REDFOX completes, REDFOX, transfer consumed / native_fork, 1 attempt

Not checked: forks from Codex or Claude sources whose native session is gone. The fallback is in the shared turn-start path and is provider-agnostic, but only OpenCode was run end to end. Screenshots of the two web UI states were captured, but the upload tool was unavailable on the triage machine, so this PR includes none. The table above is the transcript.

Model and harness: Claude Opus 5.5 (claude-opus-5-5) in Claude Code, running in T3 Code; reviews by GPT-6.1 Sol in Codex and Claude Opus 5.5.

🤖 Generated with Claude Code

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fix PR opened by an issue lead; enters the PR loop pr:gate-failed A land gate failed size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

1 participant