@devries-cameron20 / t3code Mirror · read-only / commits / 9d6da455e2
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 21, 16:00 UTC

fix(server): idle delegated tasks when recovery holds follow-ups (#36529)

Yash Singh committed Nov 14, 2026 at 01:08 UTC 9d6da455e205de3c63ebf7dc7951bce5f2a2204a
2 files changed +97 -1
apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
+93
@@ -48,6 +48,7 @@ import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
48 import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
49 import * as EventSink from "./EventSink.ts";
50 import * as Orchestrator from "./Orchestrator.ts";
51 +import * as ProviderRuntimeRecovery from "./ProviderRuntimeRecoveryService.ts";
52 import { continueRestartedRun } from "./RestartContinuation.ts";
53 import * as RuntimeLayer from "./runtimeLayer.ts";
54 import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts";
@@ -4856,6 +4857,98 @@ it.layer(layerTest)("delegated tasks across a server restart", (it) => {
4857 }),
4858 );
4859
4860 + it.effect("holding a follow-up during runtime recovery makes its parent task idle", () =>
4861 + Effect.gen(function* () {
4862 + const orchestrator = yield* Orchestrator.OrchestratorV2;
4863 + const sink = yield* EventSink.EventSinkV2;
4864 + const now = yield* DateTime.now;
4865 + const threadId = ThreadId.make("thread:held-followup-parent");
4866 + const projectId = ProjectId.make("project:held-followup");
4867 + const runId = RunId.make("run:held-followup-parent");
4868 + const rootNodeId = NodeId.make("node:held-followup-parent");
4869 + yield* seedParentWithTerminalTask({
4870 + threadId,
4871 + projectId,
4872 + runId,
4873 + rootNodeId,
4874 + taskId: NodeId.make("node:held-followup-seed"),
4875 + deliveryState: "delivered",
4876 + now,
4877 + });
4878 + const child = yield* seedRestartCancelledChild({
4879 + parentThreadId: threadId,
4880 + projectId,
4881 + parentRunId: runId,
4882 + rootNodeId,
4883 + name: "held-followup-child",
4884 + completionWake: "always",
4885 + continuationPending: false,
4886 + now,
4887 + });
4888 + yield* orchestrator.recoverDelegatedTasks;
4889 + const parent = yield* orchestrator.getThreadProjection(threadId);
4890 + const original = parent.subagents.find((task) => task.id === child.taskId)!;
4891 + const taskId = NodeId.make("node:held-followup");
4892 + const held = runEvent({
4893 + threadId: child.childThreadId,
4894 + runId: RunId.make("run:held-followup"),
4895 + ordinal: 2,
4896 + status: "queued",
4897 + now,
4898 + });
4899 + yield* sink.write({
4900 + commandId: reconcileCommandId("held-followup"),
4901 + events: [
4902 + {
4903 + ...held,
4904 + payload: {
4905 + ...held.payload,
4906 + delegatedTaskId: taskId,
4907 + startedAt: null,
4908 + completedAt: null,
4909 + queueHeld: false,
4910 + },
4911 + },
4912 + {
4913 + id: EventId.make("event:held-followup-task"),
4914 + type: "subagent.updated",
4915 + threadId,
4916 + runId,
4917 + nodeId: taskId,
4918 + occurredAt: now,
4919 + payload: {
4920 + ...original,
4921 + id: taskId,
4922 + status: "pending",
4923 + result: null,
4924 + completedAt: null,
4925 + completionDelivery: { state: "pending", observedByRunId: null },
4926 + },
4927 + },
4928 + ],
4929 + });
4930 +
4931 + const afterSequence = yield* sink.latestSequence();
4932 + yield* (yield* ProviderRuntimeRecovery.ProviderRuntimeRecoveryService).reconcile("startup");
4933 + yield* sink.stream({ afterSequence, eventType: "subagent.updated" }).pipe(
4934 + Stream.filter(
4935 + (stored) =>
4936 + stored.event.type === "subagent.updated" &&
4937 + stored.event.payload.id === taskId &&
4938 + stored.event.payload.status === "idle",
4939 + ),
4940 + Stream.take(1),
4941 + Stream.runDrain,
4942 + );
4943 +
4944 + const recovered = yield* orchestrator.getThreadProjection(threadId);
4945 + assert.equal(recovered.subagents.find((task) => task.id === taskId)?.status, "idle");
4946 + const queued = (yield* orchestrator.getThreadProjection(child.childThreadId)).runs.at(-1)!;
4947 + assert.equal(queued.status, "queued");
4948 + assert.isTrue(queued.queueHeld);
4949 + }),
4950 + );
4951 +
4952 it.effect("settles a child whose provider failure holds its queued wakes", () =>
4953 Effect.gen(function* () {
4954 const orchestrator = yield* Orchestrator.OrchestratorV2;
apps/server/src/orchestration-v2/Orchestrator.ts
+4 -1
@@ -15515,7 +15515,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
15515 Stream.filter(
15516 (stored) =>
15517 stored.event.type === "run.updated" &&
15518 - !String(stored.commandId).startsWith("command:runtime-reconcile:") &&
15518 + (!String(stored.commandId).startsWith("command:runtime-reconcile:") ||
15519 + (stored.event.payload.delegatedTaskId !== undefined &&
15520 + stored.event.payload.status === "queued" &&
15521 + stored.event.payload.queueHeld === true)) &&
15522 ((stored.event.payload.delegatedTaskId !== undefined &&
15523 (stored.event.payload.status === "queued" ||
15524 stored.event.payload.status === "starting")) ||