Skip to content

Commit db85d83

Browse files
committed
fix(server): stop completed Codex threads from staying stuck on working
1 parent 6e9c57f commit db85d83

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

‎apps/server/src/provider/Layers/CodexAdapter.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,67 @@ function startLifecycleRuntime() {
513513
}
514514

515515
lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
516+
it.effect("does not reactivate an idle child after a parent interaction", () =>
517+
Effect.gen(function* () {
518+
const { adapter, runtime } = yield* startLifecycleRuntime();
519+
const eventsFiber = yield* Stream.runCollect(Stream.take(adapter.streamEvents, 3)).pipe(
520+
Effect.forkChild,
521+
);
522+
523+
const childEvent = (id: string, method: string, payload: Record<string, unknown>) => ({
524+
id: asEventId(id),
525+
kind: "notification" as const,
526+
provider: ProviderDriverKind.make("codex"),
527+
createdAt: "2026-01-01T00:00:00.000Z",
528+
method,
529+
threadId: asThreadId("thread-1"),
530+
turnId: asTurnId("turn-1"),
531+
payload,
532+
});
533+
534+
yield* runtime.emit(
535+
childEvent("evt-child-running", "collabAgent/turnStarted", {
536+
agentThreadId: "child-1",
537+
agentPath: "/root/audit",
538+
}),
539+
);
540+
yield* runtime.emit(
541+
childEvent("evt-child-idle", "collabAgent/turnCompleted", {
542+
agentThreadId: "child-1",
543+
agentPath: "/root/audit",
544+
turn: { status: "completed" },
545+
}),
546+
);
547+
yield* runtime.emit(
548+
childEvent("evt-child-interacted", "collabAgent/activity", {
549+
agentThreadId: "child-1",
550+
agentPath: "/root/audit",
551+
activityKind: "interacted",
552+
}),
553+
);
554+
yield* runtime.emit(
555+
childEvent("evt-other-child-running", "collabAgent/turnStarted", {
556+
agentThreadId: "child-2",
557+
agentPath: "/root/other",
558+
}),
559+
);
560+
561+
const events = Array.from(yield* Fiber.join(eventsFiber));
562+
NodeAssert.deepStrictEqual(
563+
events.map((event) =>
564+
event.type === "task.updated"
565+
? { taskId: event.payload.taskId, status: event.payload.status }
566+
: { type: event.type },
567+
),
568+
[
569+
{ taskId: "child-1", status: "running" },
570+
{ taskId: "child-1", status: "idle" },
571+
{ taskId: "child-2", status: "running" },
572+
],
573+
);
574+
}),
575+
);
576+
516577
it.effect("maps completed agent message items to canonical item.completed events", () =>
517578
Effect.gen(function* () {
518579
const { adapter, runtime } = yield* startLifecycleRuntime();

‎apps/server/src/provider/Layers/CodexAdapter.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,9 @@ function mapCollabAgentEvent(
590590
},
591591
];
592592
}
593-
// interacted → the child is (again) actively driven.
594-
return [
595-
{
596-
...base,
597-
type: "task.updated",
598-
payload: { taskId, status: "running", ...statusLinkage },
599-
},
600-
];
593+
// Reading a child's result also emits "interacted" after its turn is idle.
594+
// Only the child's turn or thread lifecycle can prove it resumed work.
595+
return [];
601596
}
602597
case "collabAgent/turnStarted":
603598
return [

0 commit comments

Comments
 (0)