From dab2d82471fbaba5cbad73930235223d4b3b4408 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 17:28:58 +0000 Subject: [PATCH 1/6] test(server): reproduce native fork failing forever when its source session is gone This test reproduces #27709. A natively forked thread whose source provider session no longer exists fails every send with "Provider turn failed to start" instead of starting a fresh native session carrying the fork's inherited history. Co-Authored-By: Claude Opus 5.5 --- .../ThreadFork.execution.test.ts | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts index 3350d31fb708d..a0591ed92a386 100644 --- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts +++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts @@ -16,6 +16,7 @@ import { } from "@t3tools/contracts"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; +import * as Stream from "effect/Stream"; import * as TestClock from "effect/testing/TestClock"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; @@ -607,3 +608,211 @@ it.effect.each([ ); }, ); + +it.effect("a native fork whose source session is gone starts fresh with the source history", () => { + const driver = ProviderDriverKind.make("claudeAgent"); + const instanceId = ProviderInstanceId.make("claudeAgent"); + const modelSelection = { instanceId, model: "test-model" }; + const started: Array = []; + const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { + instanceId, + driver, + getCapabilities: () => Effect.succeed(ClaudeProviderCapabilitiesV2), + planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), + openSession: (input) => + Effect.gen(function* () { + const now = yield* DateTime.now; + return { + instanceId, + driver, + providerSessionId: input.providerSessionId, + providerSession: { + id: input.providerSessionId, + driver, + providerInstanceId: instanceId, + status: "ready", + cwd: "/tmp/fork-missing-native-source", + model: modelSelection.model, + capabilities: ClaudeProviderCapabilitiesV2, + createdAt: now, + updatedAt: now, + lastError: null, + }, + events: Stream.never, + ensureThread: ({ threadId, existingProviderThread }) => + Effect.succeed({ + ...existingProviderThread!, + appThreadId: threadId, + nativeThreadRef: { driver, nativeId: "native-fresh-fork", strength: "strong" }, + status: "idle", + updatedAt: now, + }), + resumeThread: ({ providerThread }) => Effect.succeed(providerThread), + startTurn: (turn) => Effect.sync(() => started.push(turn)), + steerTurn: () => Effect.void, + interruptTurn: () => Effect.void, + respondToRuntimeRequest: () => Effect.void, + readThreadSnapshot: () => Effect.die("unused"), + rollbackThread: () => Effect.die("unused"), + forkThread: ({ sourceProviderThread }) => + Effect.fail( + new ProviderAdapter.ProviderAdapterForkThreadError({ + driver, + providerThreadId: sourceProviderThread.id, + cause: "Session not found: native-deleted-source", + }), + ), + } satisfies ProviderAdapter.ProviderAdapterV2SessionRuntime; + }), + }; + return Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const eventSink = yield* EventSink.EventSinkV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const now = yield* DateTime.now; + const sourceThreadId = ThreadId.make("fork-missing-source"); + const targetThreadId = ThreadId.make("fork-missing-target"); + const providerThreadId = ProviderThreadId.make("fork-missing-native-thread"); + const sourceRunId = RunId.make("fork-missing-source-run"); + const userMessageId = MessageId.make("fork-missing-source-message"); + + yield* orchestrator.dispatch({ + type: "thread.create", + commandId: CommandId.make("fork-missing-create-source"), + threadId: sourceThreadId, + projectId: ProjectId.make("fork-missing-project"), + title: "Fork missing source", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + createdBy: "user", + creationSource: "web", + }); + yield* eventSink.write({ + events: [ + { + id: EventId.make("fork-missing-provider-thread"), + type: "provider-thread.updated", + threadId: sourceThreadId, + occurredAt: now, + payload: { + id: providerThreadId, + driver, + providerInstanceId: instanceId, + providerSessionId: null, + appThreadId: sourceThreadId, + ownerNodeId: null, + nativeThreadRef: { driver, nativeId: "native-deleted-source", strength: "strong" }, + nativeConversationHeadRef: null, + status: "idle", + firstRunOrdinal: 1, + lastRunOrdinal: 1, + handoffIds: [], + forkedFrom: null, + createdAt: now, + updatedAt: now, + }, + }, + { + id: EventId.make("fork-missing-source-run"), + type: "run.created", + threadId: sourceThreadId, + runId: sourceRunId, + occurredAt: now, + payload: { + id: sourceRunId, + threadId: sourceThreadId, + ordinal: 1, + providerInstanceId: instanceId, + modelSelection, + providerThreadId, + userMessageId, + rootNodeId: null, + activeAttemptId: null, + status: "completed", + queuePosition: null, + requestedAt: now, + startedAt: now, + completedAt: now, + checkpointId: null, + contextHandoffId: null, + }, + }, + { + id: EventId.make("fork-missing-user-item"), + type: "turn-item.updated", + threadId: sourceThreadId, + runId: sourceRunId, + occurredAt: now, + payload: { + id: TurnItemId.make("fork-missing-user-item"), + threadId: sourceThreadId, + runId: sourceRunId, + nodeId: null, + providerThreadId, + providerTurnId: null, + nativeItemRef: null, + parentItemId: null, + ordinal: 1, + status: "completed", + title: null, + startedAt: now, + completedAt: now, + updatedAt: now, + type: "user_message", + createdBy: "user", + creationSource: "web", + inputIntent: "turn_start", + messageId: userMessageId, + text: "FORKED_SOURCE_MARKER", + attachments: [], + }, + }, + ], + }); + yield* orchestrator.dispatch({ + type: "thread.fork", + commandId: CommandId.make("fork-missing-fork"), + sourceThreadId, + targetThreadId, + sourcePoint: { type: "run", runId: sourceRunId }, + createdBy: "user", + creationSource: "web", + }); + yield* orchestrator.dispatch({ + type: "message.dispatch", + commandId: CommandId.make("fork-missing-continue"), + threadId: targetThreadId, + messageId: MessageId.make("fork-missing-continue"), + text: "Continue the fork", + attachments: [], + modelSelection, + dispatchMode: { type: "start_immediately" }, + createdBy: "user", + creationSource: "web", + }); + // Run every start attempt so the last one runs with willRetry false. + for (let attempt = 0; attempt < 5; attempt++) { + yield* worker.drain(); + yield* TestClock.adjust("1 second"); + } + + const projection = yield* orchestrator.getThreadProjection(targetThreadId); + assert.deepEqual( + projection.turnItems.flatMap((item) => (item.type === "error" ? [item.title] : [])), + [], + ); + assert.equal(projection.runs[0]?.status, "running"); + assert.lengthOf(started, 1); + assert.include(JSON.stringify(started[0]), "FORKED_SOURCE_MARKER"); + }).pipe( + Effect.provide( + ProviderReplayHarness.layerWithRegistry( + { name: "fork-missing-native-source" }, + ProviderAdapterRegistry.layerFromAdapters([adapter]), + ), + ), + ); +}); From 9740125a7c81714b6f1c57db0c83263fc1f1c00e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 17:36:29 +0000 Subject: [PATCH 2/6] fix(server): a fork whose source session is gone starts fresh with the source history A native fork whose source native session no longer exists failed every send with "Provider turn failed to start", and its pending fork transfer was re-targeted at each new run, so the fork stayed wedged. On the final start attempt, a failed native fork now opens a fresh native session and carries the source thread's history through to the source run as a full-thread context handoff. It resolves the fork transfer as portable so later sends stop retrying the native fork, and clears the provider thread's forkedFrom because the fresh session inherited nothing natively. Earlier attempts still rethrow so transient fork failures keep retrying. Co-Authored-By: Claude Opus 5.5 --- .../ProviderTurnStartService.ts | 95 ++++++++++++++++++- .../ThreadFork.execution.test.ts | 11 ++- 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index fad06732fb48e..fd734ea619c1b 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -765,6 +765,7 @@ export const layer: Layer.Layer< }); let effectiveHandoffs = handoffs; let resumeFellBack = false; + let nativeForkFellBack = false; const userText = projectComposerContextForProvider({ text: message.text, records: message.context?.records ?? [], @@ -1064,7 +1065,7 @@ export const layer: Layer.Layer< cause: `Native fork transfer ${nativeForkTransfer.id} has no source provider execution.`, }); } - return yield* loadFromProvider( + const forked = yield* Effect.result( session.forkThread({ sourceProviderThread, sourceProviderTurns: sourceProjection.providerTurns, @@ -1076,6 +1077,91 @@ export const layer: Layer.Layer< : { providerTurnId: sourceProviderTurn.id }), }), ); + if (forked._tag === "Success") return forked.success; + if (input.willRetry === true) return yield* forked.failure; + if (!(yield* isCurrentAttemptInStatus("starting"))) return undefined; + + // The source native session is gone, so start fresh and carry the source history. + yield* Effect.logWarning("Starting a native fork in a fresh native session", { + driver: session.driver, + providerThreadId: providerThread.id, + sourceProviderThreadId: sourceProviderThread.id, + runId, + errorTag: forked.failure._tag, + }); + const replacement = yield* loadFromProvider( + session.ensureThread({ + threadId: projection.thread.id, + title: projection.thread.title, + modelSelection: run.modelSelection, + runtimePolicy: resolvedRuntimePolicy, + providerSessionId, + existingProviderThread: { + ...providerThread, + nativeThreadRef: null, + forkedFrom: null, + }, + forceNewNativeThread: true, + }), + ); + if (replacement === undefined) return undefined; + const sourceRunIds = new Set( + sourceProjection.runs + .filter((candidate) => candidate.ordinal <= sourceRun.ordinal) + .map((candidate) => candidate.id), + ); + const includeImported = sourceProjection.thread.historyOrigin === "v1_import"; + const createdAt = yield* DateTime.now; + const handoff = yield* contextHandoffService.prepareProviderHandoff({ + threadId: projection.thread.id, + targetRunId: run.id, + transferId: nativeForkTransfer.id, + fromProviderThreadIds: [sourceProviderThread.id], + toProviderThreadId: providerThread.id, + fromProviderInstanceId: sourceRun.providerInstanceId, + toProviderInstanceId: run.providerInstanceId, + coveredRunOrdinals: { from: 1, to: sourceRun.ordinal }, + strategy: "full_thread_summary", + runs: sourceProjection.runs, + items: (yield* projectionStore.getTurnStartHistory(sourceProjection.thread.id)).filter( + (item) => (item.runId === null ? includeImported : sourceRunIds.has(item.runId)), + ), + createdAt, + }); + // Source history predates every other handoff to this fork. + effectiveHandoffs = [handoff, ...effectiveHandoffs]; + nativeForkFellBack = true; + yield* eventSink.write({ + events: [ + { + id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }), + type: "context-handoff.updated", + threadId: projection.thread.id, + runId: run.id, + providerInstanceId: run.providerInstanceId, + occurredAt: createdAt, + payload: handoff, + }, + { + id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }), + type: "context-transfer.updated", + threadId: projection.thread.id, + runId: run.id, + providerInstanceId: run.providerInstanceId, + occurredAt: createdAt, + payload: { + ...nativeForkTransfer, + targetProviderInstanceId: run.providerInstanceId, + targetRunId: run.id, + status: "resolved_portable", + resolution: { strategy: "portable_context", contextHandoffId: handoff.id }, + error: null, + updatedAt: createdAt, + }, + }, + ], + }); + return replacement; } if (providerThread.nativeThreadRef === null) { // Pass the stored provider row for adoption; adapter-minted duplicates make activeProviderThreadId flap. @@ -1266,7 +1352,8 @@ export const layer: Layer.Layer< firstRunOrdinal: providerThread.firstRunOrdinal ?? run.ordinal, lastRunOrdinal: run.ordinal, handoffIds: providerThread.handoffIds, - forkedFrom: providerThread.forkedFrom, + // A fresh session did not inherit the source's native history. + forkedFrom: nativeForkFellBack ? null : providerThread.forkedFrom, status: "active", createdAt: providerThread.createdAt, updatedAt: now, @@ -1311,7 +1398,9 @@ export const layer: Layer.Layer< occurredAt: now, payload: runningProviderThread, }, - ...(nativeForkTransfer === undefined || runningProviderThread.nativeThreadRef === null + ...(nativeForkTransfer === undefined || + nativeForkFellBack || + runningProviderThread.nativeThreadRef === null ? [] : [ { diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts index a0591ed92a386..ddec247bf0ea4 100644 --- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts +++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts @@ -15,6 +15,7 @@ import { TurnItemId, } from "@t3tools/contracts"; import * as DateTime from "effect/DateTime"; +import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; import * as Stream from "effect/Stream"; import * as TestClock from "effect/testing/TestClock"; @@ -613,7 +614,7 @@ it.effect("a native fork whose source session is gone starts fresh with the sour const driver = ProviderDriverKind.make("claudeAgent"); const instanceId = ProviderInstanceId.make("claudeAgent"); const modelSelection = { instanceId, model: "test-model" }; - const started: Array = []; + const started = Deferred.makeUnsafe(); const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { instanceId, driver, @@ -648,7 +649,7 @@ it.effect("a native fork whose source session is gone starts fresh with the sour updatedAt: now, }), resumeThread: ({ providerThread }) => Effect.succeed(providerThread), - startTurn: (turn) => Effect.sync(() => started.push(turn)), + startTurn: (turn) => Deferred.succeed(started, turn).pipe(Effect.asVoid), steerTurn: () => Effect.void, interruptTurn: () => Effect.void, respondToRuntimeRequest: () => Effect.void, @@ -805,8 +806,10 @@ it.effect("a native fork whose source session is gone starts fresh with the sour [], ); assert.equal(projection.runs[0]?.status, "running"); - assert.lengthOf(started, 1); - assert.include(JSON.stringify(started[0]), "FORKED_SOURCE_MARKER"); + // Resolving the fork transfer stops later sends from retrying the native fork. + assert.equal(projection.contextTransfers[0]?.status, "resolved_portable"); + assert.isNull(projection.providerThreads[0]?.forkedFrom); + assert.include(JSON.stringify(yield* Deferred.await(started)), "FORKED_SOURCE_MARKER"); }).pipe( Effect.provide( ProviderReplayHarness.layerWithRegistry( From 1fbb7bd5a1d8e86d9d76056d25a69a5b918fe75c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 17:45:27 +0000 Subject: [PATCH 3/6] test(server): a fork that fails before its last attempt still forks natively Co-Authored-By: Claude Opus 5.5 --- .../ThreadFork.execution.test.ts | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts index ddec247bf0ea4..fe2ad2a5df546 100644 --- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts +++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts @@ -610,11 +610,12 @@ it.effect.each([ }, ); -it.effect("a native fork whose source session is gone starts fresh with the source history", () => { +const runForkWithFailingNativeSource = (forkFailures: number) => { const driver = ProviderDriverKind.make("claudeAgent"); const instanceId = ProviderInstanceId.make("claudeAgent"); const modelSelection = { instanceId, model: "test-model" }; const started = Deferred.makeUnsafe(); + let forkCalls = 0; const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { instanceId, driver, @@ -655,14 +656,21 @@ it.effect("a native fork whose source session is gone starts fresh with the sour respondToRuntimeRequest: () => Effect.void, readThreadSnapshot: () => Effect.die("unused"), rollbackThread: () => Effect.die("unused"), - forkThread: ({ sourceProviderThread }) => - Effect.fail( - new ProviderAdapter.ProviderAdapterForkThreadError({ - driver, - providerThreadId: sourceProviderThread.id, - cause: "Session not found: native-deleted-source", - }), - ), + forkThread: ({ sourceProviderThread, targetThreadId }) => + ++forkCalls <= forkFailures + ? Effect.fail( + new ProviderAdapter.ProviderAdapterForkThreadError({ + driver, + providerThreadId: sourceProviderThread.id, + cause: "Session not found: native-deleted-source", + }), + ) + : Effect.succeed({ + ...sourceProviderThread, + appThreadId: targetThreadId, + nativeThreadRef: { driver, nativeId: "native-forked", strength: "strong" }, + updatedAt: now, + }), } satisfies ProviderAdapter.ProviderAdapterV2SessionRuntime; }), }; @@ -806,10 +814,7 @@ it.effect("a native fork whose source session is gone starts fresh with the sour [], ); assert.equal(projection.runs[0]?.status, "running"); - // Resolving the fork transfer stops later sends from retrying the native fork. - assert.equal(projection.contextTransfers[0]?.status, "resolved_portable"); - assert.isNull(projection.providerThreads[0]?.forkedFrom); - assert.include(JSON.stringify(yield* Deferred.await(started)), "FORKED_SOURCE_MARKER"); + return { projection, turn: yield* Deferred.await(started), forkCalls }; }).pipe( Effect.provide( ProviderReplayHarness.layerWithRegistry( @@ -818,4 +823,23 @@ it.effect("a native fork whose source session is gone starts fresh with the sour ), ), ); -}); +}; + +it.effect("a native fork whose source session is gone starts fresh with the source history", () => + Effect.gen(function* () { + const { projection, turn } = yield* runForkWithFailingNativeSource(Number.POSITIVE_INFINITY); + // Resolving the fork transfer stops later sends from retrying the native fork. + assert.equal(projection.contextTransfers[0]?.status, "resolved_portable"); + assert.isNull(projection.providerThreads[0]?.forkedFrom); + assert.include(JSON.stringify(turn), "FORKED_SOURCE_MARKER"); + }), +); + +it.effect("a native fork that fails before its last attempt still forks natively", () => + Effect.gen(function* () { + const { projection, forkCalls } = yield* runForkWithFailingNativeSource(1); + assert.equal(forkCalls, 2); + assert.equal(projection.contextTransfers[0]?.status, "consumed"); + assert.equal(projection.contextTransfers[0]?.resolution?.strategy, "native_fork"); + }), +); From 5ecaed42fa7815c3e803612c80961f10b15a1f0e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 17:55:26 +0000 Subject: [PATCH 4/6] fix(server): describe the native fork fallback accurately Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/ProviderTurnStartService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index fd734ea619c1b..994ccb07fff8b 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -1081,7 +1081,7 @@ export const layer: Layer.Layer< if (input.willRetry === true) return yield* forked.failure; if (!(yield* isCurrentAttemptInStatus("starting"))) return undefined; - // The source native session is gone, so start fresh and carry the source history. + // Native fork kept failing (e.g. the source session is gone): start fresh with the source history. yield* Effect.logWarning("Starting a native fork in a fresh native session", { driver: session.driver, providerThreadId: providerThread.id, From 8a47c23ddef13e33954b7a7b32ac793b568f7644 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 00:25:38 +0000 Subject: [PATCH 5/6] fix(server): a fork that falls back to a fresh session says why When every native fork attempt fails, the fork now records a system notice carrying the provider's underlying error, so clients show why the fork started from portable history instead of only logging it on the server. AI-assisted; verified with the tests and tools listed above. --- .../ProviderTurnStartService.ts | 66 +++++++++++++++---- .../ThreadFork.execution.test.ts | 5 ++ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 6a62030c05451..0121299f1f5ab 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -115,6 +115,18 @@ const refusedBeforePrompt = (error: unknown): boolean => PROMPT_REFUSAL_TAGS.some((tag) => Predicate.isTagged(error, tag)) || (Predicate.hasProperty(error, "cause") && refusedBeforePrompt(error.cause)); +const startFailureMessage = (error: Error): string => { + const nestedCause = "cause" in error ? error.cause : undefined; + return ( + knownProviderFailureMessage(error) ?? + (nestedCause instanceof Error + ? nestedCause.message + : typeof nestedCause === "string" + ? nestedCause + : error.message) + ); +}; + export interface ProviderTurnStartServiceV2Shape { readonly start: (input: { readonly threadId: ThreadId; @@ -522,7 +534,6 @@ export const layer: Layer.Layer< readonly error: Error; readonly message?: string; }) { - const nestedCause = "cause" in failed.error ? failed.error.cause : undefined; yield* settleRunBeforeStart({ signal: failed.signal, status: "failed", @@ -534,14 +545,7 @@ export const layer: Layer.Layer< title: failed.title, failure: makeProviderFailure({ cause: failed.error, - message: - failed.message ?? - knownProviderFailureMessage(failed.error) ?? - (nestedCause instanceof Error - ? nestedCause.message - : typeof nestedCause === "string" - ? nestedCause - : failed.error.message), + message: failed.message ?? startFailureMessage(failed.error), class: "provider_error", }), }, @@ -1146,7 +1150,7 @@ export const layer: Layer.Layer< const sourceBusy = sourceProjection.runs.some( (candidate) => candidate.ordinal > sourceRun.ordinal && isActiveRun(candidate), ); - let nativeForkFailed = false; + let nativeForkFailure: string | undefined; if (!sourceBusy) { // Rolled-back turns are no longer in the source conversation, so they cannot bound a fork. const rolledBackAttemptIds = new Set( @@ -1185,8 +1189,9 @@ export const layer: Layer.Layer< runId, errorTag: forked.failure._tag, }); - nativeForkFailed = true; + nativeForkFailure = startFailureMessage(forked.failure); } + const nativeForkFailed = nativeForkFailure !== undefined; const sourceItems = yield* ContextHandoffService.readForkHistoryItems( projectionStore, sourceProjection, @@ -1254,6 +1259,45 @@ export const layer: Layer.Layer< updatedAt: createdAt, }, }, + ...(nativeForkFailure === undefined + ? [] + : [ + { + id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }), + type: "turn-item.updated" as const, + threadId: projection.thread.id, + runId: run.id, + providerInstanceId: run.providerInstanceId, + occurredAt: createdAt, + payload: { + id: idAllocator.derive.runSignalTurnItem({ + runId, + signal: "native-fork-fallback", + }), + threadId: projection.thread.id, + runId, + nodeId: rootNode.id, + providerThreadId: providerThread.id, + providerTurnId: null, + nativeItemRef: null, + parentItemId: null, + ordinal: + Math.max( + 0, + ...projection.turnItems + .filter((item) => item.runId === runId) + .map((item) => item.ordinal), + ) + 1, + status: "completed" as const, + title: "Native fork failed", + startedAt: createdAt, + completedAt: createdAt, + updatedAt: createdAt, + type: "system_notice" as const, + message: `Could not fork the source conversation natively (${nativeForkFailure}). Started a fresh session with its history.`, + }, + }, + ]), ], }); return loaded; diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts index 0a970f7decb3b..6930fb161d1c8 100644 --- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts +++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts @@ -1536,6 +1536,11 @@ it.effect("a native fork whose source session is gone starts fresh with the sour assert.equal(projection.contextTransfers[0]?.status, "resolved_portable"); assert.isNull(projection.providerThreads[0]?.forkedFrom); assert.include(JSON.stringify(turn), "FORKED_SOURCE_MARKER"); + const notices = projection.turnItems.flatMap((item) => + item.type === "system_notice" ? [item.message] : [], + ); + assert.lengthOf(notices, 1); + assert.include(notices[0], "Session not found: native-deleted-source"); }), ); From 69d8ff459f0f9e0e9867063ad5975c61fc587a4c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 00:41:05 +0000 Subject: [PATCH 6/6] fix(server): redact the native fork fallback notice The notice shown when a fork falls back to a fresh session now builds its cause through makeProviderFailure, so credentials are redacted and the text is length-bounded like every other provider failure shown to clients. AI-assisted; verified with the tests and tools listed above. --- .../server/src/orchestration-v2/ProviderTurnStartService.ts | 6 +++++- .../src/orchestration-v2/ThreadFork.execution.test.ts | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 0121299f1f5ab..6c87de6b066e5 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -1189,7 +1189,11 @@ export const layer: Layer.Layer< runId, errorTag: forked.failure._tag, }); - nativeForkFailure = startFailureMessage(forked.failure); + nativeForkFailure = makeProviderFailure({ + cause: forked.failure, + message: startFailureMessage(forked.failure), + class: "provider_error", + }).message; } const nativeForkFailed = nativeForkFailure !== undefined; const sourceItems = yield* ContextHandoffService.readForkHistoryItems( diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts index 6930fb161d1c8..fa6fcea911388 100644 --- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts +++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts @@ -1366,7 +1366,8 @@ const runForkWithFailingNativeSource = (forkFailures: number) => { new ProviderAdapter.ProviderAdapterForkThreadError({ driver, providerThreadId: sourceProviderThread.id, - cause: "Session not found: native-deleted-source", + cause: + "Session not found: native-deleted-source; authorization=BearerSyntheticSecret", }), ) : Effect.succeed({ @@ -1541,6 +1542,7 @@ it.effect("a native fork whose source session is gone starts fresh with the sour ); assert.lengthOf(notices, 1); assert.include(notices[0], "Session not found: native-deleted-source"); + assert.notInclude(notices[0], "BearerSyntheticSecret"); }), );