The best way to control Claude Code, Codex and more from any computer or phone
fix(server): side chat fork context recovers history from the parent thread (#34845)
Julius Marminge committed
Nov 11, 2026 at 23:32 UTC
6be26850fc2e47e90c7602ff593104cc579cd046
3 files changed
+45
-2
apps/server/src/orchestration-v2/ContextHandoffService.ts
+7
-1
@@ -69,6 +69,8 @@ export interface ContextHandoffServiceV2Shape {
69
}) => Effect.Effect<OrchestrationV2ContextHandoff, ContextHandoffServiceV2Error>;
70
readonly prepareProviderHandoff: (input: {
71
readonly threadId: ThreadId;
72
+ /** Thread the items came from, when it is not `threadId` (a fork's source). */
73
+ readonly sourceThreadId?: ThreadId;
74
readonly targetRunId: RunId;
75
readonly transferId: OrchestrationV2ContextHandoff["transferId"];
76
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
@@ -487,6 +489,7 @@ const makeContextHandoffService = Effect.fn("orchestrationV2.ContextHandoffServi
489
"orchestrationV2.contextHandoff.prepareProviderHandoff",
490
)(function* (input: {
491
readonly threadId: ThreadId;
492
+ readonly sourceThreadId?: ThreadId;
493
readonly targetRunId: RunId;
494
readonly transferId: OrchestrationV2ContextHandoff["transferId"];
495
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
@@ -521,7 +524,10 @@ const makeContextHandoffService = Effect.fn("orchestrationV2.ContextHandoffServi
524
),
525
);
526
const runStatuses = new Map(input.runs?.map((run) => [run.id, run.status]));
524
- const coverage = handoffCoverage(input);
527
+ const coverage = handoffCoverage({
528
+ ...input,
529
+ threadId: input.sourceThreadId ?? input.threadId,
530
+ });
531
const selected = selectHistory({
532
messages: input.items.flatMap((item) => {
533
const message = historicalMessage(item);
apps/server/src/orchestration-v2/Orchestrator.ts
+4
-1
@@ -7897,6 +7897,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7897
: yield* contextHandoffService
7898
.prepareProviderHandoff({
7899
threadId: command.threadId,
7900
+ sourceThreadId: sourceProjection.thread.id,
7901
targetRunId: runId,
7902
transferId: pendingForkTransfer.id,
7903
fromProviderThreadIds:
@@ -8336,7 +8337,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
8337
)
8338
: {}),
8339
};
8339
- const activeHandoff = portableForkHandoff ?? mergeBackHandoff ?? providerSwitchHandoff;
8340
+ // A side chat's "Context from" divider already marks its copied context.
8341
+ const activeHandoff =
8342
+ (sideChatFork ? null : portableForkHandoff) ?? mergeBackHandoff ?? providerSwitchHandoff;
8343
const handoffSourceRuns =
8344
portableForkHandoff !== null
8345
? sourceRun === null
apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
+34
@@ -935,6 +935,40 @@ it.effect("resolves an explicit checkpoint fork to its source run", () =>
935
}).pipe(Effect.provide(forkCases[0]!.layer)),
936
);
937
938
+it.effect("a side chat of a busy parent points history recovery at the parent", () =>
939
+ Effect.gen(function* () {
940
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
941
+ const parentId = ThreadId.make("side-chat-recovery-parent");
942
+ const sideChatId = ThreadId.make("side-chat-recovery-child");
943
+ yield* createParent(parentId);
944
+ yield* writeParentRun({
945
+ threadId: parentId,
946
+ runId: RunId.make("side-chat-recovery-stable-run"),
947
+ ordinal: 1,
948
+ status: "completed",
949
+ text: "Earlier parent history",
950
+ stable: true,
951
+ });
952
+ yield* writeParentRun({
953
+ threadId: parentId,
954
+ runId: RunId.make("side-chat-recovery-busy-run"),
955
+ ordinal: 2,
956
+ status: "running",
957
+ text: "Parent work in progress",
958
+ });
959
+ yield* forkSideChat("side-chat-recovery-fork", parentId, sideChatId);
960
+ yield* askSideChat(sideChatId, "side-chat-recovery-first-message");
961
+
962
+ const started = yield* orchestrator.getThreadProjection(sideChatId);
963
+ assert.equal(started.contextTransfers[0]?.resolution?.strategy, "portable_context");
964
+ const handoff = started.contextHandoffs.find((item) => item.strategy === "full_thread_summary");
965
+ const coverage = handoff?.history?.coverage ?? "";
966
+ assert.include(coverage, `t3_thread_read({threadId:"${parentId}"`);
967
+ assert.notInclude(coverage, `threadId:"${sideChatId}"`);
968
+ assert.isFalse(started.turnItems.some((item) => item.type === "handoff"));
969
+ }).pipe(Effect.provide(forkCases[0]!.layer)),
970
+);
971
+
972
it.effect("a side chat of an idle parent still starts with the framing note", () =>
973
Effect.gen(function* () {
974
const orchestrator = yield* Orchestrator.OrchestratorV2;