Skip to content

Commit de16b30

Browse files
committed
fix(codex): show sub-agent models
1 parent c8aba25 commit de16b30

10 files changed

Lines changed: 762 additions & 37 deletions

File tree

‎apps/server/src/orchestration/ThreadBackgroundLiveness.test.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vite-plus/test";
22
import * as ThreadBackgroundLiveness from "./ThreadBackgroundLiveness.ts";
33

44
describe("ThreadBackgroundLiveness", () => {
5-
it("does not let status-free progress restart an idle task", () => {
5+
it("does not let status-free progress or metadata restart an idle task", () => {
66
const liveness = ThreadBackgroundLiveness.make();
77
liveness.recordTaskLiveness({
88
threadId: "thread",
@@ -25,6 +25,36 @@ describe("ThreadBackgroundLiveness", () => {
2525
status: undefined,
2626
kind: "progress",
2727
});
28+
liveness.recordTaskLiveness({
29+
threadId: "thread",
30+
taskId: "task",
31+
taskType: undefined,
32+
status: undefined,
33+
kind: "updated",
34+
});
35+
expect(liveness.getThreadBackgroundLiveness("thread")).toBeNull();
36+
37+
liveness.recordTaskLiveness({
38+
threadId: "thread",
39+
taskId: "completed-task",
40+
taskType: undefined,
41+
status: undefined,
42+
kind: "started",
43+
});
44+
liveness.recordTaskLiveness({
45+
threadId: "thread",
46+
taskId: "completed-task",
47+
taskType: undefined,
48+
status: "completed",
49+
kind: "completed",
50+
});
51+
liveness.recordTaskLiveness({
52+
threadId: "thread",
53+
taskId: "completed-task",
54+
taskType: undefined,
55+
status: undefined,
56+
kind: "updated",
57+
});
2858
expect(liveness.getThreadBackgroundLiveness("thread")).toBeNull();
2959
});
3060

‎apps/server/src/orchestration/ThreadBackgroundLiveness.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ export function make(): ThreadBackgroundLivenessService["Service"] {
130130
return;
131131
}
132132

133-
// Status-free progress is a description tick, not a restart. A delayed
134-
// progress event after idle must not put the task back in the live set
135-
// (#7128).
136-
if (input.kind === "progress" && input.status === undefined) {
133+
// Status-free progress and metadata updates are not restarts. A delayed
134+
// row after idle must not put the task back in the live set (#7128).
135+
if ((input.kind === "progress" || input.kind === "updated") && input.status === undefined) {
137136
const existing = stateByThreadId.get(input.threadId);
138137
const stillLive =
139138
existing !== undefined &&

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,89 @@ function startLifecycleRuntime() {
557557
}
558558

559559
lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
560+
it.effect("carries child model metadata through every task event", () =>
561+
Effect.gen(function* () {
562+
const { adapter, runtime } = yield* startLifecycleRuntime();
563+
const eventsFiber = yield* Stream.runCollect(Stream.take(adapter.streamEvents, 10)).pipe(
564+
Effect.forkChild,
565+
);
566+
567+
const cases = [
568+
["collabAgent/started", {}],
569+
["collabAgent/activity", { activityKind: "started" }],
570+
["collabAgent/turnStarted", {}],
571+
["collabAgent/turnCompleted", { turn: { status: "completed" } }],
572+
["collabAgent/statusChanged", { status: { type: "active", activeFlags: [] } }],
573+
["collabAgent/tokenUsage", { tokenUsage: { total: { totalTokens: 42 } } }],
574+
["collabAgent/item", { item: { type: "commandExecution", command: "pwd" } }],
575+
["collabAgent/closed", {}],
576+
["collabAgent/metadataUpdated", {}],
577+
] as const;
578+
579+
for (const [index, [method, extra]] of cases.entries()) {
580+
yield* runtime.emit({
581+
id: asEventId(`evt-child-model-${index}`),
582+
kind: "notification",
583+
provider: ProviderDriverKind.make("codex"),
584+
createdAt: "2026-01-01T00:00:00.000Z",
585+
method,
586+
threadId: asThreadId("thread-1"),
587+
turnId: asTurnId("turn-1"),
588+
payload: {
589+
agentThreadId: "child-model",
590+
agentPath: "/root/model-check",
591+
model: " gpt-5.6-sol ",
592+
effort: " high ",
593+
...extra,
594+
},
595+
});
596+
}
597+
yield* runtime.emit({
598+
id: asEventId("evt-child-model-blank"),
599+
kind: "notification",
600+
provider: ProviderDriverKind.make("codex"),
601+
createdAt: "2026-01-01T00:00:00.000Z",
602+
method: "collabAgent/metadataUpdated",
603+
threadId: asThreadId("thread-1"),
604+
turnId: asTurnId("turn-1"),
605+
payload: {
606+
agentThreadId: "child-model",
607+
model: " ",
608+
effort: "",
609+
},
610+
});
611+
612+
const events = Array.from(yield* Fiber.join(eventsFiber));
613+
NodeAssert.deepStrictEqual(
614+
events.map((event) => event.type),
615+
[
616+
"task.started",
617+
"task.started",
618+
"task.updated",
619+
"task.updated",
620+
"task.updated",
621+
"task.progress",
622+
"task.progress",
623+
"task.updated",
624+
"task.updated",
625+
"task.updated",
626+
],
627+
);
628+
for (const event of events.slice(0, -1)) {
629+
const payload = event.payload as Record<string, unknown>;
630+
NodeAssert.equal(payload.model, "gpt-5.6-sol");
631+
NodeAssert.equal(payload.effort, "high");
632+
}
633+
634+
const metadataPayload = events[8]?.payload as Record<string, unknown>;
635+
NodeAssert.equal("status" in metadataPayload, false);
636+
const blankMetadataPayload = events[9]?.payload as Record<string, unknown>;
637+
NodeAssert.equal("status" in blankMetadataPayload, false);
638+
NodeAssert.equal("model" in blankMetadataPayload, false);
639+
NodeAssert.equal("effort" in blankMetadataPayload, false);
640+
}),
641+
);
642+
560643
it.effect("does not reactivate an idle child after a parent interaction", () =>
561644
Effect.gen(function* () {
562645
const { adapter, runtime } = yield* startLifecycleRuntime();

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,16 @@ function mapCollabAgentEvent(
535535
// finding: progress rows renamed math_one to its UUID).
536536
const knownName = nickname ?? pathLeaf;
537537
const title = knownName ?? agentThreadId;
538+
const model = typeof payload.model === "string" ? payload.model.trim() : "";
539+
const effort = typeof payload.effort === "string" ? payload.effort.trim() : "";
538540
// Identity repeated on every status patch so rows are self-describing when
539541
// the start row ages out of activity retention (review finding: a
540542
// reconstructed agent had a UUID name and no role/path).
541-
const statusLinkage = {
543+
const linkage = {
542544
role,
543545
...(knownName ? { title: knownName } : {}),
546+
...(model ? { model } : {}),
547+
...(effort ? { effort } : {}),
544548
...(agentPath ? { agentPath } : {}),
545549
timelineBypass: true,
546550
} as const;
@@ -555,23 +559,29 @@ function mapCollabAgentEvent(
555559
taskId,
556560
description: title,
557561
title,
558-
role,
559-
...(agentPath ? { agentPath } : {}),
562+
...linkage,
560563
...(typeof payload.parentThreadId === "string"
561564
? { parentAgentId: payload.parentThreadId }
562565
: {}),
563-
timelineBypass: true,
564566
},
565567
},
566568
];
569+
case "collabAgent/metadataUpdated":
570+
return [
571+
{
572+
...base,
573+
type: "task.updated",
574+
payload: { taskId, ...linkage },
575+
},
576+
];
567577
case "collabAgent/activity": {
568578
const activityKind = typeof payload.activityKind === "string" ? payload.activityKind : "";
569579
if (activityKind === "interrupted") {
570580
return [
571581
{
572582
...base,
573583
type: "task.updated",
574-
payload: { taskId, status: "interrupted", ...statusLinkage },
584+
payload: { taskId, status: "interrupted", ...linkage },
575585
},
576586
];
577587
}
@@ -588,9 +598,7 @@ function mapCollabAgentEvent(
588598
taskId,
589599
description: title,
590600
title,
591-
role,
592-
...(agentPath ? { agentPath } : {}),
593-
timelineBypass: true,
601+
...linkage,
594602
},
595603
},
596604
];
@@ -604,7 +612,7 @@ function mapCollabAgentEvent(
604612
{
605613
...base,
606614
type: "task.updated",
607-
payload: { taskId, status: "running", ...statusLinkage },
615+
payload: { taskId, status: "running", ...linkage },
608616
},
609617
];
610618
case "collabAgent/turnCompleted": {
@@ -624,7 +632,7 @@ function mapCollabAgentEvent(
624632
{
625633
...base,
626634
type: "task.updated",
627-
payload: { taskId, status, ...statusLinkage },
635+
payload: { taskId, status, ...linkage },
628636
},
629637
];
630638
}
@@ -640,7 +648,7 @@ function mapCollabAgentEvent(
640648
{
641649
...base,
642650
type: "task.updated",
643-
payload: { taskId, status: "failed", ...statusLinkage },
651+
payload: { taskId, status: "failed", ...linkage },
644652
},
645653
];
646654
}
@@ -653,7 +661,7 @@ function mapCollabAgentEvent(
653661
{
654662
...base,
655663
type: "task.updated",
656-
payload: { taskId, status: waiting ? "waiting" : "running", ...statusLinkage },
664+
payload: { taskId, status: waiting ? "waiting" : "running", ...linkage },
657665
},
658666
];
659667
}
@@ -662,7 +670,7 @@ function mapCollabAgentEvent(
662670
{
663671
...base,
664672
type: "task.updated",
665-
payload: { taskId, status: "idle", ...statusLinkage },
673+
payload: { taskId, status: "idle", ...linkage },
666674
},
667675
];
668676
}
@@ -709,9 +717,8 @@ function mapCollabAgentEvent(
709717
payload: {
710718
taskId,
711719
description: title,
712-
...(knownName ? { title: knownName } : {}),
720+
...linkage,
713721
typedUsage,
714-
timelineBypass: true,
715722
},
716723
},
717724
];
@@ -741,9 +748,8 @@ function mapCollabAgentEvent(
741748
payload: {
742749
taskId,
743750
description: title,
744-
...(knownName ? { title: knownName } : {}),
751+
...linkage,
745752
summary,
746-
timelineBypass: true,
747753
},
748754
},
749755
];
@@ -753,7 +759,7 @@ function mapCollabAgentEvent(
753759
{
754760
...base,
755761
type: "task.updated",
756-
payload: { taskId, status: "interrupted", ...statusLinkage },
762+
payload: { taskId, status: "interrupted", ...linkage },
757763
},
758764
];
759765
default:

0 commit comments

Comments
 (0)