The best way to control Claude Code, Codex and more from any computer or phone
fix(server): task_status says starting until the child's provider starts (#24475)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 02:36 UTC
2f2730c11347ec17f5d0136b1158da6b641ddc61
6 files changed
+155
-17
apps/server/src/mcp/OrchestratorMcpService.test.ts
+90
@@ -351,6 +351,95 @@ describe("OrchestratorMcpService", () => {
351
}),
352
);
353
354
+ it.effect("reports a child run the provider has not started yet as starting", () =>
355
+ Effect.gen(function* () {
356
+ const parentThreadId = ThreadId.make("thread:mcp-starting-parent");
357
+ const childThreadId = ThreadId.make("thread:mcp-starting-child");
358
+ const childRunId = RunId.make("run:mcp-starting-child");
359
+ const taskId = NodeId.make("node:mcp-starting-task");
360
+ const parentProjection = {
361
+ thread: { id: parentThreadId },
362
+ runs: [],
363
+ contextTransfers: [],
364
+ subagents: [
365
+ {
366
+ id: taskId,
367
+ threadId: parentThreadId,
368
+ origin: "app_owned",
369
+ childThreadId,
370
+ driver: "codex",
371
+ model: "gpt-5.6-terra",
372
+ status: "running",
373
+ result: null,
374
+ completionDelivery: null,
375
+ },
376
+ ],
377
+ } as unknown as OrchestrationV2ThreadProjection;
378
+ let providerStarted = false;
379
+ const childProjection = () =>
380
+ ({
381
+ thread: { id: childThreadId, title: "Child task" },
382
+ runs: [
383
+ {
384
+ id: childRunId,
385
+ ordinal: 1,
386
+ status: providerStarted ? "running" : "starting",
387
+ startedAt: providerStarted ? DateTime.makeUnsafe("2026-10-24T10:00:00Z") : null,
388
+ delegatedTaskId: taskId,
389
+ },
390
+ ],
391
+ contextTransfers: [],
392
+ messages: [],
393
+ subagents: [],
394
+ providerThreads: [{ status: "not_loaded", pendingBackgroundTasks: [] }],
395
+ providerTurns: [],
396
+ runtimeRequests: [],
397
+ turnItems: [],
398
+ }) as unknown as OrchestrationV2ThreadProjection;
399
+ const layerDependencies = Layer.mergeAll(
400
+ NodeServices.layer,
401
+ NodeCrypto.layer,
402
+ Layer.mock(ThreadManagementService.ThreadManagementService)({
403
+ getThreadRecords: (threadId) =>
404
+ Effect.succeed(threadId === parentThreadId ? parentProjection : childProjection()),
405
+ }),
406
+ ServerSettings.layerTest(),
407
+ Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
408
+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
409
+ list: () => Effect.succeed([]),
410
+ }),
411
+ Layer.mock(ProjectService.ProjectService)({}),
412
+ Layer.mock(SecretRequests.SecretRequests)({}),
413
+ Layer.mock(RemoteDelegation.RemoteDelegation)({}),
414
+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
415
+ );
416
+ const scope: McpInvocationScope = {
417
+ environmentId: EnvironmentId.make("environment:mcp-starting"),
418
+ requestNamespace: "provider-session:mcp-starting",
419
+ thread: {
420
+ threadId: parentThreadId,
421
+ providerSessionId: "provider-session:mcp-starting",
422
+ providerInstanceId: ProviderInstanceId.make("codex"),
423
+ },
424
+ client: undefined,
425
+ capabilities: new Set(["orchestration"]),
426
+ issuedAt: 1,
427
+ };
428
+
429
+ yield* Effect.gen(function* () {
430
+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;
431
+ const waiting = yield* service.taskStatus(scope, taskId);
432
+ assert.equal(waiting.status, "starting");
433
+ assert.equal(waiting.workState, "working");
434
+ assert.equal(waiting.childRunId, childRunId);
435
+ providerStarted = true;
436
+ const started = yield* service.taskStatus(scope, taskId);
437
+ assert.equal(started.status, "running");
438
+ assert.equal(started.workState, "working");
439
+ }).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
440
+ }),
441
+ );
442
+
443
it.effect("tells the parent to end its turn only while its task still runs", () =>
444
Effect.gen(function* () {
445
const parentThreadId = ThreadId.make("thread:mcp-next-parent");
@@ -2665,6 +2754,7 @@ describe("OrchestratorMcpService provider resolution", () => {
2754
const parent = yield* orchestrator.getThreadProjection(parentThreadId);
2755
return { taskId: parent.subagents[0]!.id };
2756
}).pipe(Effect.orDie),
2757
+ runStatus: () => Effect.succeed(null),
2758
});
2759
}),
2760
).pipe(Layer.provide(layerWatchedThreads));
apps/server/src/mcp/OrchestratorMcpService.ts
+10
-7
@@ -457,6 +457,8 @@ function taskStatusForRun(
457
switch (run === undefined ? undefined : runOutcome(run)) {
458
case "queued":
459
return "queued";
460
+ case "starting":
461
+ return "starting";
462
case "waiting":
463
return "waiting";
464
case "completed":
@@ -469,7 +471,6 @@ function taskStatusForRun(
471
case "interrupted":
472
return "interrupted";
473
case "preparing":
472
- case "starting":
474
case "running":
475
case undefined:
476
return "running";
@@ -1669,6 +1670,7 @@ const make = Effect.gen(function* () {
1670
.pipe(Effect.mapError(threadManagementFailure)));
1671
const workState =
1672
task.result !== null ? "result_available" : heldForRestart ? "working" : taskWorkState;
1673
+ const runStatus = taskStatusForRun(taskResultRun ?? childRun);
1674
const status =
1675
task.result !== null
1676
? taskStatusForRun(
@@ -1681,12 +1683,11 @@ const make = Effect.gen(function* () {
1683
)
1684
: workState === "result_available"
1685
? // A cancelled task's finished turn settles it as interrupted.
1684
- task.cancelledRunId !== undefined &&
1685
- taskStatusForRun(taskResultRun ?? childRun) === "completed"
1686
+ task.cancelledRunId !== undefined && runStatus === "completed"
1687
? "interrupted"
1687
- : taskStatusForRun(taskResultRun ?? childRun)
1688
- : taskStatusForRun(taskResultRun ?? childRun) === "queued"
1689
- ? "queued"
1688
+ : runStatus
1689
+ : runStatus === "queued" || runStatus === "starting"
1690
+ ? runStatus
1691
: "running";
1692
const derivedResult =
1693
task.result !== null
@@ -1877,7 +1878,9 @@ const make = Effect.gen(function* () {
1878
): Effect.fn.Return<OrchestratorMcpDelegateTaskResult, OrchestratorMcpFailure> {
1879
const status: OrchestratorMcpDelegateTaskResult["status"] =
1880
task.result === null
1880
- ? "running"
1881
+ ? (yield* remoteDelegation.runStatus(scope, task)) === "starting"
1882
+ ? "starting"
1883
+ : "running"
1884
: task.status === "completed" ||
1885
task.status === "failed" ||
1886
task.status === "cancelled" ||
apps/server/src/peer/RemoteDelegation.test.ts
+9
@@ -952,6 +952,15 @@ it.effect("a task delegated to the box wakes the laptop's parent when it ends th
952
expect(retried.taskId).toBe(delegated.taskId);
953
expect((yield* a.orchestrator.getThreadProjection(parentThreadId)).subagents).toHaveLength(1);
954
955
+ // Its provider there has not started the turn yet.
956
+ yield* Ref.set(thread.status, "starting");
957
+ const starting = yield* a.call("task_status", { taskId: delegated.taskId });
958
+ expect(starting.structuredContent).toMatchObject({
959
+ status: "starting",
960
+ workState: "working",
961
+ });
962
+ yield* Ref.set(thread.status, "running");
963
+
964
const historyReads: Array<string> = [];
965
const historyTracer = Tracer.make({
966
span(options) {
apps/server/src/peer/RemoteDelegation.ts
+23
-1
@@ -121,6 +121,14 @@ export class RemoteDelegation extends Context.Service<
121
readonly clientRequestId?: string | undefined;
122
},
123
) => Effect.Effect<OrchestratorMcpTaskCancelResult, OrchestratorMcpFailure>;
124
+ /**
125
+ * The status of the task's run there, or null when it cannot be read: an
126
+ * unreachable machine reads as no news rather than failing the read here.
127
+ */
128
+ readonly runStatus: (
129
+ scope: ThreadScope,
130
+ task: OrchestrationV2Subagent,
131
+ ) => Effect.Effect<OrchestratorMcpThreadRun["status"] | null>;
132
/**
133
* Follows every open remote task until it ends, including after a
134
* restart, and a finished one again when a Stop here owes it a stop there.
@@ -978,6 +986,20 @@ const make = Effect.gen(function* () {
986
},
987
);
988
989
+ const runStatus = Effect.fn("RemoteDelegation.runStatus")(
990
+ function* (scope: ThreadScope, task: OrchestrationV2Subagent) {
991
+ const remote = task.remoteChild;
992
+ if (remote?.runId === undefined) return null;
993
+ const read = yield* forwarding.readThread(
994
+ followScope(scope.thread, remote),
995
+ remote.environmentId,
996
+ { threadId: remote.threadId, limit: 1, runLimit: 50 },
997
+ );
998
+ return read.recentRuns.find((run) => run.runId === remote.runId)?.status ?? null;
999
+ },
1000
+ Effect.orElseSucceed(() => null),
1001
+ );
1002
+
1003
const start: RemoteDelegation["Service"]["start"] = () =>
1004
forkParked(
1005
Effect.gen(function* () {
@@ -1004,7 +1026,7 @@ const make = Effect.gen(function* () {
1026
}).pipe(Effect.ignoreCause({ log: true })),
1027
);
1028
1007
- return RemoteDelegation.of({ delegate, followUp, cancel, start });
1029
+ return RemoteDelegation.of({ delegate, followUp, cancel, runStatus, start });
1030
});
1031
1032
/** A defect, logged, as a failure, so a retry covers it. */
docs/orchestration-v2/orchestrator-mcp-server.md
+18
-7
@@ -293,7 +293,15 @@ type DelegateTaskResult = {
293
childThreadId: string;
294
childRunId: string | null;
295
childNodeId: string;
296
- status: "queued" | "running" | "waiting" | "completed" | "failed" | "cancelled" | "interrupted";
296
+ status:
297
+ | "queued"
298
+ | "starting"
299
+ | "running"
300
+ | "waiting"
301
+ | "completed"
302
+ | "failed"
303
+ | "cancelled"
304
+ | "interrupted";
305
workState: "working" | "waiting_for_children" | "result_available";
306
hasPendingChildRuns: boolean;
307
providerInstanceId: string;
@@ -318,12 +326,15 @@ type DelegateTaskResult = {
326
327
Reads a delegated task from the parent thread's durable projection. A task ID
328
from another parent thread is rejected. `childRunId` identifies the original
321
-run. `workState` distinguishes active work, a finished turn waiting for children,
322
-and an available result. The task remains nonterminal until its known work
323
-finishes. Its published `summary` and result transfer then remain stable across
324
-later follow-ups. `hasPendingChildRuns` reports later queued or executing turns;
325
-`latestTerminal*` exposes later executed, non-monitor results without replacing
326
-the published task result.
329
+run. `status: "starting"` means the child's provider has not started its turn
330
+yet, so a task that stays there has not begun work. A task in a linked
331
+environment reads its run's status there for this. `workState` distinguishes
332
+active work, a finished turn waiting for children, and an available result. The
333
+task remains nonterminal until its known work finishes. Its published `summary`
334
+and result transfer then remain stable across later follow-ups.
335
+`hasPendingChildRuns` reports later queued or executing turns; `latestTerminal*`
336
+exposes later executed, non-monitor results without replacing the published task
337
+result.
338
339
### `task_cancel`
340
packages/contracts/src/orchestratorMcp.ts
+5
-2
@@ -148,6 +148,7 @@ export type OrchestratorMcpTaskRole = typeof OrchestratorMcpTaskRole.Type;
148
149
export const OrchestratorMcpDelegatedTaskStatus = Schema.Literals([
150
"queued",
151
+ "starting",
152
"running",
153
"waiting",
154
"completed",
@@ -220,7 +221,10 @@ export const OrchestratorMcpDelegateTaskResult = Schema.Struct({
221
link: Schema.optional(Schema.String),
222
childRunId: Schema.NullOr(RunId),
223
childNodeId: NodeId,
223
- status: OrchestratorMcpDelegatedTaskStatus,
224
+ status: OrchestratorMcpDelegatedTaskStatus.annotate({
225
+ description:
226
+ "starting means the child's provider has not started its turn yet, so no work has begun.",
227
+ }),
228
workState: Schema.Literals(["working", "waiting_for_children", "result_available"]),
229
hasPendingChildRuns: Schema.Boolean,
230
latestTerminalRunId: Schema.NullOr(RunId),
@@ -288,7 +292,6 @@ export type OrchestratorMcpCreateThreadsInput = typeof OrchestratorMcpCreateThre
292
export const OrchestratorMcpCreatedThreadStatus = Schema.Union([
293
Schema.Literal("idle"),
294
Schema.Literal("preparing"),
291
- Schema.Literal("starting"),
295
OrchestratorMcpDelegatedTaskStatus,
296
Schema.Literal("rolled_back"),
297
]);