@devries-cameron20 / t3code-1 / commits / 81fd06998c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): steering onto another Codex instance keeps its context handoff row (#38320)

Julius Marminge committed Nov 17, 2026 at 12:34 UTC 81fd06998c6656b48265157fa6dea44aed350ba2
2 files changed +79 -8
apps/server/src/orchestration-v2/Orchestrator.ts
+56 -1
@@ -6157,6 +6157,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6157 readonly providerThreadId: OrchestrationV2ProviderThread["id"];
6158 readonly providerInstanceId: ProviderInstanceId;
6159 readonly modelSwitch?: OrchestrationV2ModelSwitch | undefined;
6160 + readonly ordinal?: number;
6161 }) {
6162 const message: OrchestrationV2ConversationMessage = {
6163 createdBy: input.createdBy,
@@ -6200,7 +6201,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6201 providerTurnId: messageInput.providerTurnId,
6202 nativeItemRef: null,
6203 parentItemId: null,
6203 - ordinal: yield* nextTurnItemOrdinal(input.projection),
6204 + ordinal: messageInput.ordinal ?? (yield* nextTurnItemOrdinal(input.projection)),
6205 status: "completed",
6206 title: null,
6207 startedAt: now,
@@ -6700,6 +6701,59 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6701 messageId: targetRun.userMessageId,
6702 now,
6703 });
6704 + const steeringOrdinal = yield* nextTurnItemOrdinal(input.projection);
6705 + if (restartHandoff !== null) {
6706 + const covered = restartHandoff.coveredRunOrdinals;
6707 + const coveredRuns = input.projection.runs.filter(
6708 + (run) => run.ordinal >= covered.from && run.ordinal <= covered.to,
6709 + );
6710 + yield* emitEvent({
6711 + type: "turn-item.updated",
6712 + threadId: input.command.threadId,
6713 + runId: targetRun.id,
6714 + nodeId: nextRootNodeId,
6715 + providerInstanceId: input.modelSelection.instanceId,
6716 + occurredAt: now,
6717 + payload: {
6718 + id: idAllocator.derive.runSignalTurnItem({
6719 + runId: targetRun.id,
6720 + signal: `context-handoff:${restartHandoff.id}`,
6721 + }),
6722 + threadId: input.command.threadId,
6723 + runId: targetRun.id,
6724 + nodeId: nextRootNodeId,
6725 + providerThreadId: restartProviderThread.id,
6726 + providerTurnId: null,
6727 + nativeItemRef: null,
6728 + parentItemId: null,
6729 + ordinal: steeringOrdinal,
6730 + status: "completed",
6731 + title: "Provider handoff",
6732 + startedAt: now,
6733 + completedAt: now,
6734 + updatedAt: now,
6735 + type: "handoff",
6736 + contextHandoffId: restartHandoff.id,
6737 + fromProviderThreadIds: restartHandoff.fromProviderThreadIds,
6738 + toProviderThreadId: restartHandoff.toProviderThreadId,
6739 + fromProviderInstanceIds: Array.from(
6740 + new Set(coveredRuns.map((run) => run.providerInstanceId)),
6741 + ),
6742 + toProviderInstanceId: input.modelSelection.instanceId,
6743 + fromModelSelections: Array.from(
6744 + new Map(
6745 + coveredRuns.map((run) => [
6746 + `${run.modelSelection.instanceId}\0${run.modelSelection.model}`,
6747 + run.modelSelection,
6748 + ]),
6749 + ).values(),
6750 + ),
6751 + toModel: input.modelSelection.model,
6752 + strategy: restartHandoff.strategy,
6753 + summary: restartHandoff.summaryText,
6754 + },
6755 + });
6756 + }
6757 yield* appendSteeringMessage({
6758 runId: targetRun.id,
6759 nodeId: nextRootNodeId,
@@ -6708,6 +6762,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6762 providerInstanceId: input.modelSelection.instanceId,
6763 // Measured on the pre-restart projection, so the rewritten run is not its own baseline.
6764 ...(restartHandoff === null ? modelSwitchSince(input.projection, input.modelSelection) : {}),
6765 + ordinal: restartHandoff === null ? steeringOrdinal : steeringOrdinal + 1,
6766 });
6767 const interruptedAttemptId = targetRun.activeAttemptId;
6768 if (interruptedAttemptId === null) {
apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts
+23 -7
@@ -865,11 +865,22 @@ it.live(
865 }),
866 );
867
868 -it.live.each(["active", "idle", "selection-command", "pooled", "separate-home"] as const)(
868 +const accountSwitchModes = [
869 + "active",
870 + "idle",
871 + "selection-command",
872 + "pooled",
873 + "separate-home",
874 + "active-separate-home",
875 +] as const;
876 +
877 +it.live.each(accountSwitchModes)(
878 "preserves native history only for compatible account switches (%s)",
879 (mode) =>
880 Effect.gen(function* () {
881 const name = `shared-home-${mode}`;
882 + const active = mode === "active" || mode === "active-separate-home";
883 + const separateHome = mode === "separate-home" || mode === "active-separate-home";
884 const cwd = yield* checkpointWorkspace(name);
885 const threadId = ThreadId.make(`thread:${name}`);
886 const targetId = ProviderInstanceId.make("codex-shadow-account");
@@ -918,8 +929,7 @@ it.live.each(["active", "idle", "selection-command", "pooled", "separate-home"]
929 getMetadata: (instanceId) =>
930 Effect.succeed({
931 driver,
921 - continuationKey:
922 - mode === "separate-home" ? `codex:home:/${instanceId}` : "codex:home:/shared",
932 + continuationKey: separateHome ? `codex:home:/${instanceId}` : "codex:home:/shared",
933 enabled: true,
934 capabilities,
935 }),
@@ -929,7 +939,7 @@ it.live.each(["active", "idle", "selection-command", "pooled", "separate-home"]
939 const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
940 const selection = {
941 ...initialSelection,
932 - model: mode === "active" ? initialSelection.model : "complete",
942 + model: active ? initialSelection.model : "complete",
943 };
944 yield* orchestrator.dispatch({
945 type: "thread.create",
@@ -949,7 +959,7 @@ it.live.each(["active", "idle", "selection-command", "pooled", "separate-home"]
959 Effect.gen(function* () {
960 const terminal = yield* orchestrator.streamDomainEvents.pipe(
961 Stream.filter((event) =>
952 - mode === "active" && step === "first"
962 + active && step === "first"
963 ? event.type === "provider-turn.updated" && event.payload.status === "running"
964 : event.type === "run.updated" && event.payload.status === "completed",
965 ),
@@ -994,14 +1004,20 @@ it.live.each(["active", "idle", "selection-command", "pooled", "separate-home"]
1004 const second = yield* dispatch(
1005 "second",
1006 targetSelection,
997 - mode === "active" ? first.runs[0]!.id : undefined,
1007 + active ? first.runs[0]!.id : undefined,
1008 );
1009 const targetThread = second.providerThreads.find(
1010 (thread) => thread.id === second.thread.activeProviderThreadId,
1011 )!;
1002 - if (mode === "separate-home") {
1012 + if (separateHome) {
1013 assert.notEqual(targetThread.id, originalThread.id);
1014 assert.lengthOf(second.contextHandoffs, 1);
1015 + assert.deepEqual(
1016 + second.turnItems.flatMap((item) =>
1017 + item.type === "handoff" ? [item.contextHandoffId] : [],
1018 + ),
1019 + [second.contextHandoffs[0]!.id],
1020 + );
1021 assert.lengthOf(second.contextTransfers, 1);
1022 assert.isEmpty(resumes);
1023 assert.notEqual(messages[1], "second");