Repository navigation
fix(server): forks whose source session is gone start fresh instead of failing every send - #27729
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.starteffect retriesforkThread5 times against the missing session. The fork transfer stayspending, 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 withSession not found: ses_….Change
ProviderTurnStartServicenow treats a native fork the way it already treats a failed resume:willRetryis true, a failedforkThreadstill rethrows, so transient failures (for example a source session that is still working) keep their retries and a later attempt can still fork natively.ensureThreadwithforceNewNativeThread). That session receives the fork's history as afull_thread_summarycontext 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 asresolved_portable/portable_context, so later sends resume the fresh session and never callforkThreadagain. The fresh provider thread'sforkedFromis 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 withexpected [ '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 nativelyasserts 2forkThreadcalls and aconsumed/native_forktransfer. It fails if thewillRetryguard is removed.vp run check:changedpasses: 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.BLUEBIRD(the parent's history reached the fresh session)status: failed,error: Session not found: ses_e722739a…status: completed, "Codeword: BLUEBIRD / First message reply: PARENT-ONE"provider-turn.startattempts per sendpending, re-targeted at run 3resolved_portable/portable_contextWARN Starting a native fork in a fresh native sessionREDFOXREDFOX, transferconsumed/native_fork, 1 attemptNot 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