@devries-cameron20 / t3code Mirror · read-only / commits / 5731c0222a
Fork 0

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 22, 09:30 UTC

fix(server): queued delegated completions keep a newer model choice (#22579)

F4llen committed Oct 31, 2026 at 22:22 UTC 5731c0222a977656ea96f3bf8082f0a7007d0ed8
2 files changed +112 -2
apps/server/src/orchestration-v2/Orchestrator.ts
+2 -2
@@ -767,7 +767,8 @@ function followsCurrentConversation(
767 message: OrchestrationV2ConversationMessage | undefined,
768 ): boolean {
769 return (
770 - message?.notification?.source.kind === "monitor" && !isBufferedProviderNotification(message)
770 + message?.delegatedCompletion !== undefined ||
771 + (message?.notification?.source.kind === "monitor" && !isBufferedProviderNotification(message))
772 );
773 }
774
@@ -776,7 +777,6 @@ function queuedRunModelSelection(
777 run: OrchestrationV2Run,
778 ): ModelSelection {
779 const message = projection.messages.find((candidate) => candidate.id === run.userMessageId);
779 - // App-owned monitor updates follow the agent currently handling the thread.
780 return followsCurrentConversation(message)
781 ? projection.thread.modelSelection
782 : run.modelSelection;
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+110
@@ -5714,6 +5714,116 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
5714 }),
5715 );
5716
5717 + it.effect.each([
5718 + { ...modelSelection, model: "gpt-5.5", options: [{ id: "reasoningEffort", value: "high" }] },
5719 + { instanceId: alternateInstanceId, model: "gpt-5.5" },
5720 + ])(
5721 + "starts a queued delegated completion on a selection set while it waited: %j",
5722 + (newerSelection) =>
5723 + Effect.gen(function* () {
5724 + const orchestrator = yield* Orchestrator.OrchestratorV2;
5725 + const eventSink = yield* EventSink.EventSinkV2;
5726 + const threadId = ThreadId.make(
5727 + `runtime-layer-queued-delegated-completion-selection-${newerSelection.instanceId}`,
5728 + );
5729 + const taskId = NodeId.make(`${threadId}:task`);
5730 + const completionMessageId = MessageId.make(`${threadId}:completion`);
5731 + yield* orchestrator.dispatch({
5732 + type: "thread.create",
5733 + commandId: CommandId.make(`${threadId}:create`),
5734 + threadId,
5735 + projectId: ProjectId.make(`${threadId}:project`),
5736 + createdBy: "user",
5737 + creationSource: "web",
5738 + title: "Delegated completion selection",
5739 + modelSelection,
5740 + runtimeMode: "full-access",
5741 + interactionMode: "default",
5742 + branch: null,
5743 + worktreePath: process.cwd(),
5744 + });
5745 + yield* orchestrator.dispatch({
5746 + type: "message.dispatch",
5747 + commandId: CommandId.make(`${threadId}:active`),
5748 + threadId,
5749 + messageId: MessageId.make(`${threadId}:active`),
5750 + text: "Delegate a task",
5751 + attachments: [],
5752 + modelSelection,
5753 + dispatchMode: { type: "start_immediately" },
5754 + createdBy: "user",
5755 + creationSource: "web",
5756 + });
5757 + const active = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
5758 + const now = yield* DateTime.now;
5759 + yield* eventSink.write({
5760 + events: [
5761 + {
5762 + id: EventId.make(`${threadId}:cohort`),
5763 + type: "run.updated",
5764 + threadId,
5765 + runId: active.id,
5766 + occurredAt: now,
5767 + payload: {
5768 + ...active,
5769 + delegatedCompletion: {
5770 + disposition: "open",
5771 + nextGeneration: 2,
5772 + delivery: { messageId: completionMessageId, generation: 1, taskIds: [taskId] },
5773 + },
5774 + },
5775 + },
5776 + ],
5777 + });
5778 + yield* orchestrator.dispatch({
5779 + type: "message.dispatch",
5780 + commandId: CommandId.make(`${threadId}:completion`),
5781 + threadId,
5782 + messageId: completionMessageId,
5783 + text: "Delegated task finished",
5784 + attachments: [],
5785 + dispatchMode: { type: "queue_after_active" },
5786 + createdBy: "agent",
5787 + creationSource: "server",
5788 + delegatedCompletion: { parentRunId: active.id, generation: 1, taskIds: [taskId] },
5789 + });
5790 + yield* orchestrator.dispatch({
5791 + type: "thread.model-selection.set",
5792 + commandId: CommandId.make(`${threadId}:select-newer`),
5793 + threadId,
5794 + modelSelection: newerSelection,
5795 + });
5796 + const waiting = yield* orchestrator.getThreadProjection(threadId);
5797 + yield* eventSink.write({
5798 + events: [
5799 + {
5800 + id: EventId.make(`${threadId}:completed`),
5801 + type: "run.updated",
5802 + threadId,
5803 + runId: active.id,
5804 + occurredAt: now,
5805 + payload: {
5806 + ...waiting.runs.find((run) => run.id === active.id)!,
5807 + status: "completed",
5808 + completedAt: now,
5809 + },
5810 + },
5811 + ],
5812 + });
5813 + yield* orchestrator.resumeQueuedRuns;
5814 + const after = yield* orchestrator.getThreadProjection(threadId);
5815 + const delivered = after.runs.find((run) => run.userMessageId === completionMessageId)!;
5816 + assert.equal(delivered.status, "starting");
5817 + assert.deepEqual(delivered.modelSelection, newerSelection);
5818 + assert.equal(
5819 + after.attempts.find((attempt) => attempt.id === delivered.activeAttemptId)
5820 + ?.providerInstanceId,
5821 + newerSelection.instanceId,
5822 + );
5823 + assert.deepEqual(after.thread.modelSelection, newerSelection);
5824 + }),
5825 + );
5826 +
5827 it.effect("keeps the queue after a user interrupts the active run", () =>
5828 Effect.gen(function* () {
5829 const orchestrator = yield* Orchestrator.OrchestratorV2;