Skip to content

Commit e0a42fa

Browse files
fix(server): task_status says starting for a linked-environment task too
A remote task's status came only from the parent's local record, so it read running until a result arrived. While it has no result, task_status now reads its run's status there through the link and reports starting until that provider starts. An unreachable machine reads as running, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 53bfb03 commit e0a42fa

5 files changed

Lines changed: 43 additions & 9 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,7 @@ describe("OrchestratorMcpService provider resolution", () => {
25362536
const parent = yield* orchestrator.getThreadProjection(parentThreadId);
25372537
return { taskId: parent.subagents[0]!.id };
25382538
}).pipe(Effect.orDie),
2539+
runStatus: () => Effect.succeed(null),
25392540
});
25402541
}),
25412542
).pipe(Layer.provide(layerWatchedThreads));

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,9 @@ const make = Effect.gen(function* () {
18781878
): Effect.fn.Return<OrchestratorMcpDelegateTaskResult, OrchestratorMcpFailure> {
18791879
const status: OrchestratorMcpDelegateTaskResult["status"] =
18801880
task.result === null
1881-
? "running"
1881+
? (yield* remoteDelegation.runStatus(scope, task)) === "starting"
1882+
? "starting"
1883+
: "running"
18821884
: task.status === "completed" ||
18831885
task.status === "failed" ||
18841886
task.status === "cancelled" ||

‎apps/server/src/peer/RemoteDelegation.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,15 @@ it.effect("a task delegated to the box wakes the laptop's parent when it ends th
952952
expect(retried.taskId).toBe(delegated.taskId);
953953
expect((yield* a.orchestrator.getThreadProjection(parentThreadId)).subagents).toHaveLength(1);
954954

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+
955964
const historyReads: Array<string> = [];
956965
const historyTracer = Tracer.make({
957966
span(options) {

‎apps/server/src/peer/RemoteDelegation.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ export class RemoteDelegation extends Context.Service<
121121
readonly clientRequestId?: string | undefined;
122122
},
123123
) => 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>;
124132
/**
125133
* Follows every open remote task until it ends, including after a
126134
* restart, and a finished one again when a Stop here owes it a stop there.
@@ -978,6 +986,20 @@ const make = Effect.gen(function* () {
978986
},
979987
);
980988

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+
9811003
const start: RemoteDelegation["Service"]["start"] = () =>
9821004
forkParked(
9831005
Effect.gen(function* () {
@@ -1004,7 +1026,7 @@ const make = Effect.gen(function* () {
10041026
}).pipe(Effect.ignoreCause({ log: true })),
10051027
);
10061028

1007-
return RemoteDelegation.of({ delegate, followUp, cancel, start });
1029+
return RemoteDelegation.of({ delegate, followUp, cancel, runStatus, start });
10081030
});
10091031

10101032
/** A defect, logged, as a failure, so a retry covers it. */

‎docs/orchestration-v2/orchestrator-mcp-server.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ Reads a delegated task from the parent thread's durable projection. A task ID
328328
from another parent thread is rejected. `childRunId` identifies the original
329329
run. `status: "starting"` means the child's provider has not started its turn
330330
yet, so a task that stays there has not begun work. A task in a linked
331-
environment reads `running` until it has a result, because the parent does not
332-
read the remote run's status. `workState` distinguishes active work, a finished
333-
turn waiting for children, and an available result. The task remains nonterminal
334-
until its known work finishes. Its published `summary` and result transfer then
335-
remain stable across later follow-ups. `hasPendingChildRuns` reports later
336-
queued or executing turns; `latestTerminal*` exposes later executed, non-monitor
337-
results without replacing the published task result.
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.
338338

339339
### `task_cancel`
340340

0 commit comments

Comments
 (0)