Skip to content

Commit 1cc0584

Browse files
committed
fix(web): allow stopping waiting Codex subagents
1 parent 680a025 commit 1cc0584

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,35 @@ it.effect("interrupts only the selected running native Codex subagent", () =>
348348
assert.equal(parent.subagents[0]?.status, "interrupted");
349349
assert.equal(parent.nodes[0]?.status, "interrupted");
350350
assert.equal(parent.turnItems[0]?.status, "interrupted");
351+
yield* projections.apply({
352+
id: EventId.make("turn:waiting-stop"),
353+
type: "provider-turn.updated",
354+
threadId: childThreadId,
355+
occurredAt: now,
356+
payload: providerTurn,
357+
});
358+
yield* projections.apply({
359+
id: EventId.make("task:waiting-stop"),
360+
type: "subagent.updated",
361+
threadId: parentThreadId,
362+
occurredAt: now,
363+
payload: { ...subagent, status: "waiting" },
364+
});
365+
yield* orchestrator.dispatch({
366+
type: "subagent.interrupt",
367+
commandId: CommandId.make("interrupt:waiting-stop"),
368+
threadId: parentThreadId,
369+
subagentId,
370+
});
371+
yield* worker.drain();
372+
assert.equal(
373+
(yield* projections.getThreadProjection(childThreadId)).providerTurns[0]?.status,
374+
"interrupted",
375+
);
376+
assert.equal(
377+
(yield* projections.getThreadProjection(parentThreadId)).subagents[0]?.status,
378+
"interrupted",
379+
);
351380
const eventSink = yield* EventSink.EventSinkV2;
352381
const executor = yield* ThreadCommandExecutor.ThreadCommandExecutor;
353382
const ingestor = yield* ProviderEventIngestor.ProviderEventIngestorV2;
@@ -647,7 +676,7 @@ it.effect("interrupts only the selected running native Codex subagent", () =>
647676
assert.instanceOf(rejected, Orchestrator.OrchestratorDispatchError);
648677
assert.equal(
649678
rejected.cause,
650-
`Subagent ${subagentId} is not a running native Codex subagent with a child thread.`,
679+
`Subagent ${subagentId} is not an active native Codex subagent with a child thread.`,
651680
);
652681
assert.deepEqual(yield* outbox.listByCommandId(settledCommandId), []);
653682
}).pipe(Effect.provide(layerTest)),

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9050,13 +9050,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
90509050
if (
90519051
subagent?.origin !== "provider_native" ||
90529052
subagent.driver !== "codex" ||
9053-
subagent.status !== "running" ||
9053+
(subagent.status !== "running" && subagent.status !== "waiting") ||
90549054
subagent.childThreadId === null
90559055
) {
90569056
return yield* new OrchestratorDispatchError({
90579057
commandId: command.commandId,
90589058
commandType: command.type,
9059-
cause: `Subagent ${command.subagentId} is not a running native Codex subagent with a child thread.`,
9059+
cause: `Subagent ${command.subagentId} is not an active native Codex subagent with a child thread.`,
90609060
});
90619061
}
90629062
const childThreadId = subagent.childThreadId;

‎apps/web/src/components/chat/ThreadRelationshipsControl.agents.test.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ it("stops only active subagents from lineage without opening their thread", asyn
123123
input: { threadId: "parent", subagentId: "agent" },
124124
});
125125

126+
state.command.mockClear();
127+
state.projection = {
128+
...projection,
129+
subagents: [{ ...agent, origin: "provider_native", status: "waiting" }],
130+
};
131+
await act(async () => renderer.update(cloneElement(panel)));
132+
await act(async () => stopButton().props.onClick());
133+
expect(state.command).toHaveBeenCalledWith({
134+
environmentId: "test",
135+
input: { threadId: "parent", subagentId: "agent" },
136+
});
137+
expect(state.navigate).not.toHaveBeenCalled();
138+
126139
state.projection = { ...projection, subagents: [{ ...agent, status: "completed" }] };
127140
await act(async () => renderer.update(cloneElement(panel)));
128141
expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(0);

‎apps/web/src/components/chat/ThreadRelationshipsControl.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export function ThreadRelationshipsPanel(props: {
408408
(supportsSubagentInterrupt &&
409409
agent.origin === "provider_native" &&
410410
agent.driver === "codex" &&
411-
agent.status === "running"));
411+
(agent.status === "running" || agent.status === "waiting")));
412412
const threadTitle = relationshipThreadTitle({
413413
title: node?.thread?.title ?? agent?.title ?? threadId,
414414
isSubagent,

0 commit comments

Comments
 (0)