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): a fresh send in a fork that has not run yet starts a fresh session (#38844)
Julius Marminge committed
Nov 18, 2026 at 20:06 UTC
455a60aa3cebe9263dd485cae0cfa33817334647
2 files changed
+85
-1
apps/server/src/orchestration-v2/Orchestrator.ts
+24
-1
@@ -7963,7 +7963,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7963
}
7964
return;
7965
}
7966
- const pendingForkTransfer = pendingForkTransferForThread(projection);
7966
+ // A scheduled fresh run is a side conversation, so it must not drop the fork's context.
7967
+ const supersedesForkTransfer = freshContext && command.scheduledTaskId === undefined;
7968
+ const pendingForkTransfer = supersedesForkTransfer
7969
+ ? undefined
7970
+ : pendingForkTransferForThread(projection);
7971
const pendingMergeBackSourceThreadIds = new Set(
7972
pendingMergeBackTransfers.map((transfer) => transfer.sourceThreadId),
7973
);
@@ -8351,6 +8355,25 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
8355
payload: run,
8356
});
8357
yield* completeSourcePlan(now);
8358
+ const supersededForkTransfer = supersedesForkTransfer
8359
+ ? pendingForkTransferForThread(projection)
8360
+ : undefined;
8361
+ if (supersededForkTransfer !== undefined) {
8362
+ // Superseded, or the next ordinary send would bring the parent's context back.
8363
+ yield* emitEvent({
8364
+ type: "context-transfer.updated",
8365
+ threadId: command.threadId,
8366
+ runId,
8367
+ providerInstanceId: modelSelection.instanceId,
8368
+ occurredAt: now,
8369
+ payload: {
8370
+ ...supersededForkTransfer,
8371
+ status: "superseded",
8372
+ error: "Superseded by a fresh session.",
8373
+ updatedAt: now,
8374
+ },
8375
+ });
8376
+ }
8377
yield* emitEvent({
8378
type: "run-attempt.created",
8379
threadId: command.threadId,
apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
+61
@@ -14,6 +14,7 @@ import {
14
ProviderTurnId,
15
RunAttemptId,
16
RunId,
17
+ ScheduledTaskId,
18
ThreadId,
19
TurnItemId,
20
} from "@t3tools/contracts";
@@ -935,6 +936,66 @@ it.effect("resolves an explicit checkpoint fork to its source run", () =>
936
}).pipe(Effect.provide(forkCases[0]!.layer)),
937
);
938
939
+it.effect("a fresh send in a fork that has not run yet starts without the fork's context", () =>
940
+ Effect.gen(function* () {
941
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
942
+ const parentId = ThreadId.make("fresh-fork-parent");
943
+ const forkId = ThreadId.make("fresh-fork-child");
944
+ yield* createParent(parentId);
945
+ yield* writeParentRun({
946
+ threadId: parentId,
947
+ runId: RunId.make("fresh-fork-parent-run"),
948
+ ordinal: 1,
949
+ status: "completed",
950
+ text: "Work",
951
+ stable: true,
952
+ });
953
+ yield* orchestrator.dispatch({
954
+ type: "thread.fork",
955
+ commandId: CommandId.make("fresh-fork"),
956
+ sourceThreadId: parentId,
957
+ targetThreadId: forkId,
958
+ sourcePoint: { type: "latest_stable" },
959
+ createdBy: "user",
960
+ creationSource: "web",
961
+ });
962
+ const scheduled = yield* orchestrator
963
+ .dispatch({
964
+ type: "message.dispatch",
965
+ commandId: CommandId.make("fresh-fork-scheduled"),
966
+ threadId: forkId,
967
+ messageId: MessageId.make("fresh-fork-scheduled"),
968
+ scheduledTaskId: ScheduledTaskId.make("fresh-fork-task"),
969
+ text: "Scheduled",
970
+ attachments: [],
971
+ freshContext: true,
972
+ dispatchMode: { type: "start_immediately" },
973
+ createdBy: "user",
974
+ creationSource: "web",
975
+ })
976
+ .pipe(Effect.flip);
977
+ assert.include(String(scheduled.cause), "still being applied");
978
+ yield* orchestrator.dispatch({
979
+ type: "message.dispatch",
980
+ commandId: CommandId.make("fresh-fork-send"),
981
+ threadId: forkId,
982
+ messageId: MessageId.make("fresh-fork-send"),
983
+ text: "Start over",
984
+ attachments: [],
985
+ freshContext: true,
986
+ dispatchMode: { type: "start_immediately" },
987
+ createdBy: "user",
988
+ creationSource: "web",
989
+ });
990
+ const fork = yield* orchestrator.getThreadProjection(forkId);
991
+ assert.isTrue(fork.runs.at(-1)?.freshContext === true);
992
+ assert.deepEqual(
993
+ fork.contextTransfers.filter((transfer) => transfer.type === "fork").map((t) => t.status),
994
+ ["superseded"],
995
+ );
996
+ }).pipe(Effect.provide(forkCases[0]!.layer)),
997
+);
998
+
999
it.effect("a side chat of a busy parent points history recovery at the parent", () =>
1000
Effect.gen(function* () {
1001
const orchestrator = yield* Orchestrator.OrchestratorV2;