The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
fix(server): preserve native history in busy Codex forks (#29239)
Co-authored-by: GPT-6.1 Sol at high effort <noreply@openai.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 at medium effort, merge integration <noreply@anthropic.com>
Alb11747 committed
Nov 19, 2026 at 01:14 UTC
23c339e8be81e7660a192f8fd11f66c5b4a0de7e
6 files changed
+276
-59
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+1
@@ -273,6 +273,7 @@ export const CodexProviderCapabilitiesV2 = {
273
canRollbackThread: true,
274
canForkThread: true,
275
canForkFromTurn: true,
276
+ canForkWhileSourceRunning: true,
277
canForkFromSubagentThread: true,
278
exposesNativeThreadId: true,
279
},
apps/server/src/orchestration-v2/CommandPolicy.test.ts
+55
-23
@@ -312,6 +312,7 @@ layer("CommandPolicyV2", (it) => {
312
capabilities: CursorProviderCapabilitiesV2,
313
sameProvider: true,
314
hasStrongNativeSource: true,
315
+ hasNativeTurnBoundary: false,
316
sourceRunStatus: "completed",
317
fromSpecificTurn: true,
318
sourceBusy: false,
@@ -321,29 +322,60 @@ layer("CommandPolicyV2", (it) => {
322
}),
323
);
324
324
- it.effect("forks a busy source natively only where the provider supports it", () =>
325
- Effect.gen(function* () {
326
- const policy = yield* CommandPolicy.CommandPolicyV2;
327
- const decide = (
328
- provider: "codex" | "claudeAgent",
329
- capabilities: OrchestrationV2ProviderCapabilities,
330
- sourceBusy: boolean,
331
- ) =>
332
- policy.decideForkExecution({
333
- commandId,
334
- threadId,
335
- providerInstanceId: ProviderInstanceId.make(provider),
336
- capabilities,
337
- sameProvider: true,
338
- hasStrongNativeSource: true,
339
- sourceRunStatus: "completed",
340
- fromSpecificTurn: true,
341
- sourceBusy,
342
- });
325
+ it.effect.each([
326
+ {
327
+ provider: "codex",
328
+ capabilities: CodexProviderCapabilitiesV2,
329
+ hasNativeTurnBoundary: true,
330
+ busyStrategy: "native_fork",
331
+ },
332
+ {
333
+ provider: "codex without busy forks",
334
+ capabilities: {
335
+ ...CodexProviderCapabilitiesV2,
336
+ threads: { ...CodexProviderCapabilitiesV2.threads, canForkWhileSourceRunning: undefined },
337
+ },
338
+ hasNativeTurnBoundary: true,
339
+ busyStrategy: "portable_context",
340
+ },
341
+ {
342
+ provider: "codex",
343
+ capabilities: CodexProviderCapabilitiesV2,
344
+ hasNativeTurnBoundary: false,
345
+ busyStrategy: "portable_context",
346
+ },
347
+ {
348
+ provider: "claudeAgent",
349
+ capabilities: ClaudeProviderCapabilitiesV2,
350
+ hasNativeTurnBoundary: false,
351
+ busyStrategy: "native_fork",
352
+ },
353
+ ] satisfies ReadonlyArray<{
354
+ provider: string;
355
+ capabilities: OrchestrationV2ProviderCapabilities;
356
+ hasNativeTurnBoundary: boolean;
357
+ busyStrategy: CommandPolicy.ForkExecutionPolicyV2;
358
+ }>)(
359
+ "forks a busy $provider source with hasNativeTurnBoundary=$hasNativeTurnBoundary as $busyStrategy",
360
+ ({ capabilities, hasNativeTurnBoundary, busyStrategy }) =>
361
+ Effect.gen(function* () {
362
+ const policy = yield* CommandPolicy.CommandPolicyV2;
363
+ const decide = (sourceBusy: boolean) =>
364
+ policy.decideForkExecution({
365
+ commandId,
366
+ threadId,
367
+ providerInstanceId: ProviderInstanceId.make("custom-instance"),
368
+ capabilities,
369
+ sameProvider: true,
370
+ hasStrongNativeSource: true,
371
+ hasNativeTurnBoundary,
372
+ sourceRunStatus: "completed",
373
+ fromSpecificTurn: true,
374
+ sourceBusy,
375
+ });
376
344
- assert.equal(yield* decide("codex", CodexProviderCapabilitiesV2, false), "native_fork");
345
- assert.equal(yield* decide("codex", CodexProviderCapabilitiesV2, true), "portable_context");
346
- assert.equal(yield* decide("claudeAgent", ClaudeProviderCapabilitiesV2, true), "native_fork");
347
- }),
377
+ assert.equal(yield* decide(false), "native_fork");
378
+ assert.equal(yield* decide(true), busyStrategy);
379
+ }),
380
);
381
});
apps/server/src/orchestration-v2/CommandPolicy.ts
+18
-2
@@ -123,6 +123,20 @@ export function isActiveRun(run: OrchestrationV2Run): boolean {
123
);
124
}
125
126
+/**
127
+ * Providers that key forks on native turn ids can only fork a busy source from a turn with one;
128
+ * a synthetic or missing boundary would fork the live conversation, including the running turn.
129
+ */
130
+export function canForkBusySourceNatively(
131
+ capabilities: OrchestrationV2ProviderCapabilities,
132
+ hasNativeTurnBoundary: boolean,
133
+): boolean {
134
+ return (
135
+ capabilities.threads.canForkWhileSourceRunning === true &&
136
+ (hasNativeTurnBoundary || !capabilities.turns.exposesNativeTurnId)
137
+ );
138
+}
139
+
140
/** The run a follow-up to a finished child binds to: the latest active one, else the last that ran. */
141
export function followUpOwnerRun(
142
runs: ReadonlyArray<OrchestrationV2Run>,
@@ -226,9 +240,10 @@ export interface CommandPolicyV2Shape {
240
input: CapabilityCheckInput & {
241
readonly sameProvider: boolean;
242
readonly hasStrongNativeSource: boolean;
243
+ readonly hasNativeTurnBoundary: boolean;
244
readonly sourceRunStatus: OrchestrationV2Run["status"];
245
readonly fromSpecificTurn: boolean;
231
- /** Later source runs are still active; providers cannot fork a thread mid-turn. */
246
+ /** Later source runs are still active. */
247
readonly sourceBusy: boolean;
248
},
249
) => Effect.Effect<ForkExecutionPolicyV2, CommandPolicyV2Error>;
@@ -395,7 +410,8 @@ const decideForkExecution: CommandPolicyV2Shape["decideForkExecution"] = (input)
410
(input.sourceRunStatus === "completed" || input.sourceRunStatus === "waiting") &&
411
input.sameProvider &&
412
input.hasStrongNativeSource &&
398
- (!input.sourceBusy || input.capabilities.threads.canForkWhileSourceRunning === true) &&
413
+ (!input.sourceBusy ||
414
+ canForkBusySourceNatively(input.capabilities, input.hasNativeTurnBoundary)) &&
415
input.capabilities.threads.canForkThread &&
416
(!input.fromSpecificTurn || input.capabilities.threads.canForkFromTurn) &&
417
input.capabilities.identity.nativeThreadIds === "strong";
apps/server/src/orchestration-v2/Orchestrator.ts
+3
@@ -8620,6 +8620,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
8620
sameProvider:
8621
pendingForkTransfer.sourceProviderInstanceId === modelSelection.instanceId,
8622
hasStrongNativeSource: sourceProviderThread?.nativeThreadRef?.strength === "strong",
8623
+ hasNativeTurnBoundary:
8624
+ sourceProjection?.providerTurns.find((turn) => turn.id === sourceProviderTurnId)
8625
+ ?.nativeTurnRef != null,
8626
sourceRunStatus: sourceRun.status,
8627
fromSpecificTurn: sourceRun !== null,
8628
sourceBusy: sourceRunsAfterFork.some(isActiveRun),
apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts
+178
-24
@@ -23,6 +23,7 @@ import {
23
RunAttemptId,
24
RunId,
25
ThreadId,
26
+ TurnItemId,
27
ProjectId,
28
EnvironmentId,
29
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
@@ -456,6 +457,7 @@ function makeLocalCommandHarness(input: {
457
readonly steeringRestart?: boolean;
458
readonly nativeGoals?: boolean;
459
readonly canForkWhileSourceRunning?: boolean;
460
+ readonly exposesNativeTurnId?: boolean;
461
readonly goalDriver?: "opencode" | "antigravity";
462
readonly worktreePath?: string;
463
readonly worktreesDir?: string;
@@ -497,6 +499,8 @@ function makeLocalCommandHarness(input: {
499
readonly acceptedResume?: boolean;
500
readonly restartedResume?: boolean;
501
readonly nativeForkFrom?: "idle" | "busy";
502
+ readonly sourceBoundary?: "native" | "synthetic";
503
+ readonly sourceRolledBack?: boolean;
504
readonly switchedProvider?: boolean;
505
readonly threadRuntimeMode?: OrchestrationV2ThreadProjection["thread"]["runtimeMode"];
506
};
@@ -702,11 +706,14 @@ function makeLocalCommandHarness(input: {
706
providerThreadId: parentProviderThread.id,
707
nodeId: rootNodeId,
708
runAttemptId: RunAttemptId.make(`side-chat-parent-attempt-${ordinal}`),
705
- nativeTurnRef: {
706
- driver: providerThread.driver,
707
- nativeId: `side-chat-parent-native-turn-${ordinal}`,
708
- strength: "strong" as const,
709
- },
709
+ nativeTurnRef:
710
+ ordinal === 1 && input.sideChat?.sourceBoundary === "synthetic"
711
+ ? null
712
+ : {
713
+ driver: providerThread.driver,
714
+ nativeId: `side-chat-parent-native-turn-${ordinal}`,
715
+ strength: "strong" as const,
716
+ },
717
ordinal,
718
status: "completed" as const,
719
startedAt: now,
@@ -729,7 +736,10 @@ function makeLocalCommandHarness(input: {
736
ordinal: 1,
737
providerThreadId: parentProviderThread.id,
738
activeAttemptId: parentTurns[0]!.attempt.id,
732
- status: "completed" as const,
739
+ status:
740
+ input.sideChat?.sourceRolledBack === true
741
+ ? ("rolled_back" as const)
742
+ : ("completed" as const),
743
completedAt: now,
744
},
745
{
@@ -1101,10 +1111,14 @@ function makeLocalCommandHarness(input: {
1111
...CodexProviderCapabilitiesV2,
1112
threads: {
1113
...CodexProviderCapabilitiesV2.threads,
1104
- canForkWhileSourceRunning: input.canForkWhileSourceRunning,
1114
+ canForkWhileSourceRunning:
1115
+ input.canForkWhileSourceRunning ??
1116
+ CodexProviderCapabilitiesV2.threads.canForkWhileSourceRunning,
1117
},
1118
turns: {
1119
...CodexProviderCapabilitiesV2.turns,
1120
+ exposesNativeTurnId:
1121
+ input.exposesNativeTurnId ?? CodexProviderCapabilitiesV2.turns.exposesNativeTurnId,
1122
...(input.nativeGoals === undefined ? {} : { supportsNativeGoals: input.nativeGoals }),
1123
},
1124
},
@@ -1135,7 +1149,7 @@ function makeLocalCommandHarness(input: {
1149
strength: "strong" as const,
1150
},
1151
};
1138
- const forkThread = vi.fn((_fork: ProviderAdapter.ProviderAdapterV2ForkThreadInput) =>
1152
+ const forkThread = vi.fn<ProviderAdapter.ProviderAdapterV2SessionRuntime["forkThread"]>(() =>
1153
Effect.succeed(sideChatThread),
1154
);
1155
const sideChatSession = {
@@ -1258,6 +1272,21 @@ function makeLocalCommandHarness(input: {
1272
const getThreadRecords = vi.fn<ProjectionStore.ProjectionStoreV2Shape["getThreadRecords"]>((id) =>
1273
Effect.succeed(id === parentThreadId ? parentRecords : projection),
1274
);
1275
+ const prepareProviderHandoff = vi.fn<
1276
+ ContextHandoffService.ContextHandoffServiceV2["Service"]["prepareProviderHandoff"]
1277
+ >((handoff) =>
1278
+ input.sideChat?.nativeForkFrom === undefined
1279
+ ? Effect.die("history read must fail first")
1280
+ : Effect.succeed({
1281
+ ...handoff,
1282
+ id: ContextHandoffId.make("side-chat-fork-context"),
1283
+ createdByProviderInstanceId: handoff.toProviderInstanceId,
1284
+ status: "ready",
1285
+ summaryMessageId: null,
1286
+ summaryText: "PARENT_HISTORY",
1287
+ updatedAt: handoff.createdAt,
1288
+ }),
1289
+ );
1290
const getTurnStartContext = vi.fn(() =>
1291
Effect.succeed({
1292
...projection,
@@ -1297,18 +1326,7 @@ function makeLocalCommandHarness(input: {
1326
Layer.provide(
1327
Layer.mergeAll(
1328
Layer.mock(ContextHandoffService.ContextHandoffServiceV2)({
1300
- prepareProviderHandoff: (handoff) =>
1301
- input.sideChat?.nativeForkFrom === undefined
1302
- ? Effect.die("history read must fail first")
1303
- : Effect.succeed({
1304
- ...handoff,
1305
- id: ContextHandoffId.make("side-chat-fork-context"),
1306
- createdByProviderInstanceId: handoff.toProviderInstanceId,
1307
- status: "ready",
1308
- summaryMessageId: null,
1309
- summaryText: "PARENT_HISTORY",
1310
- updatedAt: handoff.createdAt,
1311
- }),
1329
+ prepareProviderHandoff,
1330
}),
1331
Layer.mock(EventSink.EventSinkV2)({
1332
writeIfRunCurrent,
@@ -1403,6 +1421,7 @@ function makeLocalCommandHarness(input: {
1421
startRootRun,
1422
startTurn,
1423
forkThread,
1424
+ prepareProviderHandoff,
1425
interruptTurn,
1426
tryHandlePromptCommand,
1427
events,
@@ -2345,9 +2364,34 @@ effectIt.effect.each([
2364
);
2365
2366
effectIt.effect.each([
2348
- { nativeForkFrom: "idle", forks: true, transferStatus: "consumed", handoffIds: [] },
2367
+ {
2368
+ nativeForkFrom: "idle",
2369
+ canForkWhileSourceRunning: false,
2370
+ sourceBoundary: "native",
2371
+ forks: true,
2372
+ transferStatus: "consumed",
2373
+ handoffIds: [],
2374
+ },
2375
{
2376
nativeForkFrom: "busy",
2377
+ canForkWhileSourceRunning: true,
2378
+ sourceBoundary: "native",
2379
+ forks: true,
2380
+ transferStatus: "consumed",
2381
+ handoffIds: [],
2382
+ },
2383
+ {
2384
+ nativeForkFrom: "busy",
2385
+ canForkWhileSourceRunning: false,
2386
+ sourceBoundary: "native",
2387
+ forks: false,
2388
+ transferStatus: "resolved_portable",
2389
+ handoffIds: ["side-chat-fork-context"],
2390
+ },
2391
+ {
2392
+ nativeForkFrom: "busy",
2393
+ canForkWhileSourceRunning: true,
2394
+ sourceBoundary: "synthetic",
2395
forks: false,
2396
transferStatus: "resolved_portable",
2397
handoffIds: ["side-chat-fork-context"],
@@ -2355,17 +2399,19 @@ effectIt.effect.each([
2399
{
2400
nativeForkFrom: "busy",
2401
canForkWhileSourceRunning: true,
2402
+ exposesNativeTurnId: false,
2403
+ sourceBoundary: "synthetic",
2404
forks: true,
2405
transferStatus: "consumed",
2406
handoffIds: [],
2407
},
2408
] as const)(
2363
- "runs a planned native side chat fork when the parent is $nativeForkFrom (fork while running: $canForkWhileSourceRunning)",
2364
- ({ nativeForkFrom, forks, transferStatus, handoffIds, ...capability }) =>
2409
+ "runs a planned native side chat fork when the parent is $nativeForkFrom with canForkWhileSourceRunning=$canForkWhileSourceRunning, sourceBoundary=$sourceBoundary and exposesNativeTurnId=$exposesNativeTurnId",
2410
+ ({ nativeForkFrom, sourceBoundary, forks, transferStatus, handoffIds, ...capability }) =>
2411
Effect.gen(function* () {
2412
const harness = makeLocalCommandHarness({
2413
text: "What is the main thread doing?",
2368
- sideChat: { contextRun: "current", nativeForkFrom },
2414
+ sideChat: { contextRun: "current", nativeForkFrom, sourceBoundary },
2415
...capability,
2416
});
2417
@@ -2376,6 +2422,11 @@ effectIt.effect.each([
2422
expect(
2423
harness.forkThread.mock.calls[0]?.[0].sourceProviderTurns?.map((turn) => turn.id),
2424
).toEqual(forks ? ["side-chat-parent-turn-1"] : undefined);
2425
+ if (forks) {
2426
+ expect(harness.forkThread).toHaveBeenCalledWith(
2427
+ expect.objectContaining({ providerTurnId: "side-chat-parent-turn-1" }),
2428
+ );
2429
+ }
2430
expect(harness.projection().contextTransfers).toMatchObject([
2431
{ id: "side-chat-fork", status: transferStatus },
2432
]);
@@ -2430,6 +2481,109 @@ effectIt.effect.each(
2481
}),
2482
);
2483
2484
+effectIt.effect.each(["before-start", "during-fork"] as const)(
2485
+ "recovers a planned native fork after the parent rolls back %s",
2486
+ (rollback) =>
2487
+ Effect.gen(function* () {
2488
+ const harness = makeLocalCommandHarness({
2489
+ text: "Continue from the selected turn",
2490
+ sideChat: {
2491
+ contextRun: "current",
2492
+ nativeForkFrom: "idle",
2493
+ sourceRolledBack: rollback === "before-start",
2494
+ },
2495
+ });
2496
+ const parentThreadId = ThreadId.make("side-chat-parent");
2497
+ let parent = {
2498
+ ...harness.projection(),
2499
+ ...(yield* harness.getThreadRecords(parentThreadId, [
2500
+ "runs",
2501
+ "attempts",
2502
+ "providerThreads",
2503
+ "providerTurns",
2504
+ "turnItems",
2505
+ ])),
2506
+ };
2507
+ const selectedRun = parent.runs[0]!;
2508
+ const earlierRun = {
2509
+ ...selectedRun,
2510
+ id: RunId.make("side-chat-kept-run"),
2511
+ ordinal: 1,
2512
+ activeAttemptId: null,
2513
+ status: "completed" as const,
2514
+ };
2515
+ const items = [earlierRun, selectedRun].map((sourceRun, ordinal) => ({
2516
+ type: "user_message" as const,
2517
+ id: TurnItemId.make(`parent-item-${ordinal}`),
2518
+ threadId: parentThreadId,
2519
+ runId: sourceRun.id,
2520
+ nodeId: null,
2521
+ providerThreadId: sourceRun.providerThreadId,
2522
+ providerTurnId: null,
2523
+ nativeItemRef: null,
2524
+ parentItemId: null,
2525
+ ordinal,
2526
+ status: "completed" as const,
2527
+ title: null,
2528
+ startedAt: parent.updatedAt,
2529
+ completedAt: parent.updatedAt,
2530
+ updatedAt: parent.updatedAt,
2531
+ createdBy: "user" as const,
2532
+ creationSource: "server" as const,
2533
+ messageId: MessageId.make(`parent-message-${ordinal}`),
2534
+ text: ordinal === 0 ? "KEPT_HISTORY" : "ROLLED_BACK_HISTORY",
2535
+ inputIntent: "turn_start" as const,
2536
+ attachments: [],
2537
+ }));
2538
+ parent = {
2539
+ ...parent,
2540
+ runs: [
2541
+ earlierRun,
2542
+ ...parent.runs.map((sourceRun) => ({ ...sourceRun, ordinal: sourceRun.ordinal + 1 })),
2543
+ ],
2544
+ turnItems: items,
2545
+ };
2546
+ harness.getThreadRecords.mockImplementation((id) =>
2547
+ Effect.succeed(id === parentThreadId ? parent : harness.projection()),
2548
+ );
2549
+ harness.forkThread.mockImplementation(() =>
2550
+ Effect.sync(() => {
2551
+ parent = {
2552
+ ...parent,
2553
+ runs: parent.runs.map((sourceRun) =>
2554
+ sourceRun.id === selectedRun.id ? { ...sourceRun, status: "rolled_back" } : sourceRun,
2555
+ ),
2556
+ };
2557
+ }).pipe(
2558
+ Effect.andThen(
2559
+ Effect.fail(
2560
+ new ProviderAdapter.ProviderAdapterForkThreadError({
2561
+ driver: ProviderDriverKind.make("codex"),
2562
+ providerThreadId: ProviderThreadId.make("side-chat-parent-provider-thread"),
2563
+ cause: "Selected native turn was removed by rollback",
2564
+ }),
2565
+ ),
2566
+ ),
2567
+ ),
2568
+ );
2569
+
2570
+ yield* harness.start;
2571
+
2572
+ expect(harness.forkThread).toHaveBeenCalledTimes(rollback === "before-start" ? 0 : 1);
2573
+ expect(harness.projection().contextTransfers).toMatchObject([
2574
+ { id: "side-chat-fork", status: "resolved_portable" },
2575
+ ]);
2576
+ expect(harness.startTurn.mock.calls[0]?.[0].message.text).toContain("PARENT_HISTORY");
2577
+ expect(harness.projection().providerThreads[0]?.handoffIds).toEqual([
2578
+ "side-chat-fork-context",
2579
+ ]);
2580
+ expect(harness.settledRuns).toEqual([]);
2581
+ expect(
2582
+ harness.prepareProviderHandoff.mock.calls[0]?.[0].items.map((item) => item.id),
2583
+ ).toEqual([items[0]!.id]);
2584
+ }),
2585
+);
2586
+
2587
effectIt.effect.each([
2588
{ runStatus: "failed", turnStatus: "completed" },
2589
{ runStatus: "completed", turnStatus: "completed" },
apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+21
-10
@@ -45,7 +45,7 @@ import { makeRestoreMissingWorktree } from "../workspace/restoreMissingWorktree.
45
import * as EventSink from "./EventSink.ts";
46
import * as ProviderUsageAnalytics from "../telemetry/ProviderUsageAnalytics.ts";
47
import * as ContextHandoffService from "./ContextHandoffService.ts";
48
-import { isActiveRun } from "./CommandPolicy.ts";
48
+import { canForkBusySourceNatively, isActiveRun } from "./CommandPolicy.ts";
49
import { contextBoundaryOrdinal } from "./contextBoundary.ts";
50
import {
51
DEFAULT_HANDOFF_TOKEN_CAP,
@@ -1260,7 +1260,7 @@ export const layer: Layer.Layer<
1260
let recoveryTurnItem: OrchestrationV2TurnItem | undefined;
1261
const loadedProviderThread = yield* Effect.gen(function* () {
1262
if (nativeForkTransfer !== undefined) {
1263
- const sourceProjection = yield* projectionStore.getThreadRecords(
1263
+ let sourceProjection = yield* projectionStore.getThreadRecords(
1264
nativeForkTransfer.sourceThreadId,
1265
["runs", "providerThreads", "attempts", "providerTurns"],
1266
);
@@ -1284,15 +1284,19 @@ export const layer: Layer.Layer<
1284
cause: `Native fork transfer ${nativeForkTransfer.id} has no source provider execution.`,
1285
});
1286
}
1287
- // Most providers refuse to fork a busy thread, so a source that started a turn after
1288
- // dispatch planned this fork gets the portable context dispatch gives a busy source.
1289
- const sourceBusy =
1290
- session.providerSession.capabilities.threads.canForkWhileSourceRunning !== true &&
1291
- sourceProjection.runs.some(
1292
- (candidate) => candidate.ordinal > sourceRun.ordinal && isActiveRun(candidate),
1293
- );
1287
+ // The source may have started a turn after dispatch planned this fork.
1288
+ const sourceBusy = sourceProjection.runs.some(
1289
+ (candidate) => candidate.ordinal > sourceRun.ordinal && isActiveRun(candidate),
1290
+ );
1291
let nativeForkFailure: string | undefined;
1295
- if (!sourceBusy) {
1292
+ if (
1293
+ (sourceRun.status === "completed" || sourceRun.status === "waiting") &&
1294
+ (!sourceBusy ||
1295
+ canForkBusySourceNatively(
1296
+ session.providerSession.capabilities,
1297
+ sourceProviderTurn?.nativeTurnRef != null,
1298
+ ))
1299
+ ) {
1300
// Rolled-back turns are no longer in the source conversation, so they cannot bound a fork.
1301
const rolledBackAttemptIds = new Set(
1302
sourceProjection.attempts
@@ -1335,6 +1339,13 @@ export const layer: Layer.Layer<
1339
message: startFailureMessage(forked.failure),
1340
class: "provider_error",
1341
}).message;
1342
+ sourceProjection = {
1343
+ ...sourceProjection,
1344
+ ...(yield* projectionStore.getThreadRecords(nativeForkTransfer.sourceThreadId, [
1345
+ "runs",
1346
+ "attempts",
1347
+ ])),
1348
+ };
1349
}
1350
const nativeForkFailed = nativeForkFailure !== undefined;
1351
const sourceItems = yield* ContextHandoffService.readForkHistoryItems(