TypeScript
fix(codex): show sub-agent models (#8502)
Theo Browne49f6241ddeee
diff --git a/apps/server/src/orchestration/ThreadBackgroundLiveness.test.ts b/apps/server/src/orchestration/ThreadBackgroundLiveness.test.tsindex 4a4b68ced59..b4c528480fc 100644--- a/apps/server/src/orchestration/ThreadBackgroundLiveness.test.ts+++ b/apps/server/src/orchestration/ThreadBackgroundLiveness.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from "vite-plus/test";import * as ThreadBackgroundLiveness from "./ThreadBackgroundLiveness.ts";describe("ThreadBackgroundLiveness", () => {- it("does not let status-free progress restart an idle task", () => {+ it("does not let status-free progress or metadata restart an idle task", () => {const liveness = ThreadBackgroundLiveness.make();liveness.recordTaskLiveness({threadId: "thread",@@ -25,6 +25,36 @@ describe("ThreadBackgroundLiveness", () => {status: undefined,kind: "progress",});+ liveness.recordTaskLiveness({+ threadId: "thread",+ taskId: "task",+ taskType: undefined,+ status: undefined,+ kind: "updated",+ });+ expect(liveness.getThreadBackgroundLiveness("thread")).toBeNull();++ liveness.recordTaskLiveness({+ threadId: "thread",+ taskId: "completed-task",+ taskType: undefined,+ status: undefined,+ kind: "started",+ });+ liveness.recordTaskLiveness({+ threadId: "thread",+ taskId: "completed-task",+ taskType: undefined,+ status: "completed",+ kind: "completed",+ });+ liveness.recordTaskLiveness({+ threadId: "thread",+ taskId: "completed-task",+ taskType: undefined,+ status: undefined,+ kind: "updated",+ });expect(liveness.getThreadBackgroundLiveness("thread")).toBeNull();});diff --git a/apps/server/src/orchestration/ThreadBackgroundLiveness.ts b/apps/server/src/orchestration/ThreadBackgroundLiveness.tsindex d4d6da06dfc..2781e4981f7 100644--- a/apps/server/src/orchestration/ThreadBackgroundLiveness.ts+++ b/apps/server/src/orchestration/ThreadBackgroundLiveness.ts@@ -130,10 +130,9 @@ export function make(): ThreadBackgroundLivenessService["Service"] {return;}- // Status-free progress is a description tick, not a restart. A delayed- // progress event after idle must not put the task back in the live set- // (#7128).- if (input.kind === "progress" && input.status === undefined) {+ // Status-free progress and metadata updates are not restarts. A delayed+ // row after idle must not put the task back in the live set (#7128).+ if ((input.kind === "progress" || input.kind === "updated") && input.status === undefined) {const existing = stateByThreadId.get(input.threadId);const stillLive =existing !== undefined &&diff --git a/apps/server/src/provider/Layers/CodexAdapter.test.ts b/apps/server/src/provider/Layers/CodexAdapter.test.tsindex 4986d02c9b6..f01192f8d70 100644--- a/apps/server/src/provider/Layers/CodexAdapter.test.ts+++ b/apps/server/src/provider/Layers/CodexAdapter.test.ts@@ -557,6 +557,89 @@ function startLifecycleRuntime() {}lifecycleLayer("CodexAdapterLive lifecycle", (it) => {+ it.effect("carries child model metadata through every task event", () =>+ Effect.gen(function* () {+ const { adapter, runtime } = yield* startLifecycleRuntime();+ const eventsFiber = yield* Stream.runCollect(Stream.take(adapter.streamEvents, 10)).pipe(+ Effect.forkChild,+ );++ const cases = [+ ["collabAgent/started", {}],+ ["collabAgent/activity", { activityKind: "started" }],+ ["collabAgent/turnStarted", {}],+ ["collabAgent/turnCompleted", { turn: { status: "completed" } }],+ ["collabAgent/statusChanged", { status: { type: "active", activeFlags: [] } }],+ ["collabAgent/tokenUsage", { tokenUsage: { total: { totalTokens: 42 } } }],+ ["collabAgent/item", { item: { type: "commandExecution", command: "pwd" } }],+ ["collabAgent/closed", {}],+ ["collabAgent/metadataUpdated", {}],+ ] as const;++ for (const [index, [method, extra]] of cases.entries()) {+ yield* runtime.emit({+ id: asEventId(`evt-child-model-${index}`),+ kind: "notification",+ provider: ProviderDriverKind.make("codex"),+ createdAt: "2026-01-01T00:00:00.000Z",+ method,+ threadId: asThreadId("thread-1"),+ turnId: asTurnId("turn-1"),+ payload: {+ agentThreadId: "child-model",+ agentPath: "/root/model-check",+ model: " gpt-5.6-sol ",+ effort: " high ",+ ...extra,+ },+ });+ }+ yield* runtime.emit({+ id: asEventId("evt-child-model-blank"),+ kind: "notification",+ provider: ProviderDriverKind.make("codex"),+ createdAt: "2026-01-01T00:00:00.000Z",+ method: "collabAgent/metadataUpdated",+ threadId: asThreadId("thread-1"),+ turnId: asTurnId("turn-1"),+ payload: {+ agentThreadId: "child-model",+ model: " ",+ effort: "",+ },+ });++ const events = Array.from(yield* Fiber.join(eventsFiber));+ NodeAssert.deepStrictEqual(+ events.map((event) => event.type),+ [+ "task.started",+ "task.started",+ "task.updated",+ "task.updated",+ "task.updated",+ "task.progress",+ "task.progress",+ "task.updated",+ "task.updated",+ "task.updated",+ ],+ );+ for (const event of events.slice(0, -1)) {+ const payload = event.payload as Record<string, unknown>;+ NodeAssert.equal(payload.model, "gpt-5.6-sol");+ NodeAssert.equal(payload.effort, "high");+ }++ const metadataPayload = events[8]?.payload as Record<string, unknown>;+ NodeAssert.equal("status" in metadataPayload, false);+ const blankMetadataPayload = events[9]?.payload as Record<string, unknown>;+ NodeAssert.equal("status" in blankMetadataPayload, false);+ NodeAssert.equal("model" in blankMetadataPayload, false);+ NodeAssert.equal("effort" in blankMetadataPayload, false);+ }),+ );+it.effect("does not reactivate an idle child after a parent interaction", () =>Effect.gen(function* () {const { adapter, runtime } = yield* startLifecycleRuntime();diff --git a/apps/server/src/provider/Layers/CodexAdapter.ts b/apps/server/src/provider/Layers/CodexAdapter.tsindex 0f7d999662e..c4ed5a044ab 100644--- a/apps/server/src/provider/Layers/CodexAdapter.ts+++ b/apps/server/src/provider/Layers/CodexAdapter.ts@@ -535,12 +535,16 @@ function mapCollabAgentEvent(// finding: progress rows renamed math_one to its UUID).const knownName = nickname ?? pathLeaf;const title = knownName ?? agentThreadId;+ const model = typeof payload.model === "string" ? payload.model.trim() : "";+ const effort = typeof payload.effort === "string" ? payload.effort.trim() : "";// Identity repeated on every status patch so rows are self-describing when// the start row ages out of activity retention (review finding: a// reconstructed agent had a UUID name and no role/path).- const statusLinkage = {+ const linkage = {role,...(knownName ? { title: knownName } : {}),+ ...(model ? { model } : {}),+ ...(effort ? { effort } : {}),...(agentPath ? { agentPath } : {}),timelineBypass: true,} as const;@@ -555,15 +559,21 @@ function mapCollabAgentEvent(taskId,description: title,title,- role,- ...(agentPath ? { agentPath } : {}),+ ...linkage,...(typeof payload.parentThreadId === "string"? { parentAgentId: payload.parentThreadId }: {}),- timelineBypass: true,},},];+ case "collabAgent/metadataUpdated":+ return [+ {+ ...base,+ type: "task.updated",+ payload: { taskId, ...linkage },+ },+ ];case "collabAgent/activity": {const activityKind = typeof payload.activityKind === "string" ? payload.activityKind : "";if (activityKind === "interrupted") {@@ -571,7 +581,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status: "interrupted", ...statusLinkage },+ payload: { taskId, status: "interrupted", ...linkage },},];}@@ -588,9 +598,7 @@ function mapCollabAgentEvent(taskId,description: title,title,- role,- ...(agentPath ? { agentPath } : {}),- timelineBypass: true,+ ...linkage,},},];@@ -604,7 +612,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status: "running", ...statusLinkage },+ payload: { taskId, status: "running", ...linkage },},];case "collabAgent/turnCompleted": {@@ -624,7 +632,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status, ...statusLinkage },+ payload: { taskId, status, ...linkage },},];}@@ -640,7 +648,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status: "failed", ...statusLinkage },+ payload: { taskId, status: "failed", ...linkage },},];}@@ -653,7 +661,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status: waiting ? "waiting" : "running", ...statusLinkage },+ payload: { taskId, status: waiting ? "waiting" : "running", ...linkage },},];}@@ -662,7 +670,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status: "idle", ...statusLinkage },+ payload: { taskId, status: "idle", ...linkage },},];}@@ -709,9 +717,8 @@ function mapCollabAgentEvent(payload: {taskId,description: title,- ...(knownName ? { title: knownName } : {}),+ ...linkage,typedUsage,- timelineBypass: true,},},];@@ -741,9 +748,8 @@ function mapCollabAgentEvent(payload: {taskId,description: title,- ...(knownName ? { title: knownName } : {}),+ ...linkage,summary,- timelineBypass: true,},},];@@ -753,7 +759,7 @@ function mapCollabAgentEvent({...base,type: "task.updated",- payload: { taskId, status: "interrupted", ...statusLinkage },+ payload: { taskId, status: "interrupted", ...linkage },},];default:diff --git a/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts b/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.tsindex 5af06efb71d..5bc5940fe53 100644--- a/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts+++ b/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts@@ -81,10 +81,319 @@ function buildScript() {};}+function capturedStartedActivity(childId = CHILD_A) {+ const captured = wireFixture.notifications.find((entry) => {+ const item = (entry.params as { item?: { type?: string; kind?: string } }).item;+ return item?.type === "subAgentActivity" && item.kind === "started";+ });+ assert.isDefined(captured);+ return {+ ...captured,+ params: {+ ...captured.params,+ item: {+ ...captured.params.item,+ agentThreadId: childId,+ agentPath: "/root/model-check",+ },+ },+ };+}++function capturedSpawnedThread(childId = CHILD_A) {+ const captured = wireFixture.notifications.find((entry) => entry.method === "thread/started");+ assert.isDefined(captured);+ return {+ ...captured,+ params: {+ thread: {+ ...captured.params.thread,+ id: childId,+ sessionId: childId,+ parentThreadId: ROOT,+ agentNickname: "model-check",+ agentRole: "verifier",+ source: {+ subAgent: {+ thread_spawn: {+ agent_nickname: "model-check",+ agent_path: "/root/model-check",+ agent_role: "verifier",+ depth: 1,+ parent_thread_id: ROOT,+ },+ },+ },+ },+ },+ };+}++function childSettings(threadId: string, model: string, effort: string) {+ return {+ method: "thread/settings/updated",+ params: {+ threadId,+ threadSettings: {+ approvalPolicy: "on-request",+ approvalsReviewer: "auto_review",+ collaborationMode: { mode: "default", settings: { model } },+ cwd: "/workspace/repo",+ effort,+ model,+ modelProvider: "openai",+ sandboxPolicy: { type: "dangerFullAccess" },+ },+ },+ };+}++function readRecordedRequests() {+ return NodeFS.readFileSync(`${scriptPath}.requests`, "utf8")+ .trim()+ .split("\n")+ .filter((line) => line.length > 0)+ .map((line) => JSON.parse(line) as { method: string; params: Record<string, unknown> });+}+const scriptPath = NodePath.join(import.meta.dirname, "../testFixtures/.collab-script.json");const peerPath = NodePath.join(import.meta.dirname, "../testFixtures/codexCollabMockPeer.sh");describe("CodexSessionRuntime collab integration", () => {+ it.effect("looks up child model metadata once after activity registration", () =>+ Effect.gen(function* () {+ const script = {+ rootThreadId: ROOT,+ recordRequests: true,+ notifications: [+ capturedStartedActivity(),+ capturedStartedActivity(),+ {+ ...capturedStartedActivity(CHILD_B),+ params: {+ ...capturedStartedActivity(CHILD_B).params,+ item: { ...capturedStartedActivity(CHILD_B).params.item, kind: "interacted" },+ },+ },+ { method: "thread/closed", params: { threadId: CHILD_B } },+ capturedSpawnedThread(ROOT),+ ],+ childResumeSnapshots: {+ [CHILD_A]: { model: "gpt-5.6-luna", reasoningEffort: "low" },+ },+ };+ // @effect-diagnostics-next-line preferSchemaOverJson:off+ NodeFS.writeFileSync(scriptPath, JSON.stringify(script), "utf8");+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });+ yield* Effect.addFinalizer(() =>+ Effect.sync(() => {+ NodeFS.rmSync(scriptPath, { force: true });+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });+ }),+ );++ const runtime = yield* makeCodexSessionRuntime({+ threadId: ThreadId.make("thread-collab-model-activity"),+ binaryPath: peerPath,+ cwd: "/tmp",+ runtimeMode: "full-access",+ environment: { ...process.env, T3_CODEX_COLLAB_SCRIPT: scriptPath },+ });+ const metadataFiber = yield* runtime.events.pipe(+ Stream.filter(+ (event) =>+ event.method === "collabAgent/metadataUpdated" &&+ (event.payload as { agentThreadId?: string }).agentThreadId === CHILD_A,+ ),+ Stream.take(1),+ Stream.runCollect,+ Effect.forkScoped,+ );++ const session = yield* runtime.start();+ assert.equal(session.model, "gpt-5.6-sol");+ yield* runtime.sendTurn({ input: "start one child" });+ const metadataEvents = Array.from(yield* Fiber.join(metadataFiber));+ assert.deepInclude(metadataEvents[0]?.payload, {+ agentThreadId: CHILD_A,+ model: "gpt-5.6-luna",+ effort: "low",+ });+ assert.deepEqual(readRecordedRequests(), [+ {+ method: "thread/resume",+ params: { threadId: CHILD_A, excludeTurns: true },+ },+ ]);++ yield* runtime.close;+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),+ );++ it.effect("keeps child settings and reroutes newer than the resume snapshot", () =>+ Effect.gen(function* () {+ const statusChanged = wireFixture.notifications.find(+ (entry) =>+ entry.method === "thread/status/changed" &&+ (entry.params as { threadId?: string }).threadId === CHILD_A,+ );+ assert.isDefined(statusChanged);+ const script = {+ rootThreadId: ROOT,+ recordRequests: true,+ notifications: [+ childSettings(CHILD_A, "child-before", "medium"),+ capturedSpawnedThread(),+ childSettings(CHILD_A, "child-after", "high"),+ {+ method: "model/rerouted",+ params: {+ threadId: CHILD_A,+ turnId: `${CHILD_A}-turn`,+ fromModel: "child-after",+ toModel: "child-rerouted",+ reason: "highRiskCyberActivity",+ },+ },+ {+ method: "model/rerouted",+ params: {+ threadId: ROOT,+ turnId: `${ROOT}-turn`,+ fromModel: "gpt-5.6-sol",+ toModel: "root-rerouted",+ reason: "highRiskCyberActivity",+ },+ },+ ],+ childResumeSnapshots: {+ [CHILD_A]: {+ model: "stale-snapshot",+ reasoningEffort: "low",+ notifications: [statusChanged],+ },+ },+ };+ // @effect-diagnostics-next-line preferSchemaOverJson:off+ NodeFS.writeFileSync(scriptPath, JSON.stringify(script), "utf8");+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });+ yield* Effect.addFinalizer(() =>+ Effect.sync(() => {+ NodeFS.rmSync(scriptPath, { force: true });+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });+ }),+ );++ const runtime = yield* makeCodexSessionRuntime({+ threadId: ThreadId.make("thread-collab-model-spawn"),+ binaryPath: peerPath,+ cwd: "/tmp",+ runtimeMode: "full-access",+ environment: { ...process.env, T3_CODEX_COLLAB_SCRIPT: scriptPath },+ });+ const eventsFiber = yield* runtime.events.pipe(+ Stream.takeUntil(+ (event) =>+ event.method === "collabAgent/statusChanged" &&+ (event.payload as { agentThreadId?: string }).agentThreadId === CHILD_A,+ ),+ Stream.runCollect,+ Effect.forkScoped,+ );++ yield* runtime.start();+ yield* runtime.sendTurn({ input: "start one spawned child" });+ const events = Array.from(yield* Fiber.join(eventsFiber));+ const started = events.find((event) => event.method === "collabAgent/started");+ assert.deepInclude(started?.payload, {+ agentThreadId: CHILD_A,+ model: "child-before",+ effort: "medium",+ });+ const childStatus = events.find((event) => event.method === "collabAgent/statusChanged");+ assert.deepInclude(childStatus?.payload, {+ agentThreadId: CHILD_A,+ model: "child-rerouted",+ effort: "high",+ });+ assert.isTrue(+ events.some(+ (event) =>+ event.method === "model/rerouted" &&+ (event.payload as { threadId?: string }).threadId === ROOT,+ ),+ "the root reroute must stay on the parent path",+ );+ assert.isFalse(+ events.some(+ (event) =>+ (event.method === "thread/settings/updated" || event.method === "model/rerouted") &&+ (event.payload as { threadId?: string }).threadId === CHILD_A,+ ),+ "child metadata notifications must not leak to the parent path",+ );+ assert.equal(readRecordedRequests().length, 1);++ yield* runtime.close;+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),+ );++ it.effect("does not delay the parent turn when the child lookup fails", () =>+ Effect.gen(function* () {+ yield* Effect.addFinalizer(() =>+ Effect.sync(() => {+ NodeFS.rmSync(scriptPath, { force: true });+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });+ }),+ );+ for (const [name, childSnapshot] of [+ ["hang", { hang: true }],+ ["error", { error: "child unavailable" }],+ ] as const) {+ yield* Effect.gen(function* () {+ const marker = `lookup-${name}`;+ const script = {+ rootThreadId: ROOT,+ recordRequests: true,+ resumeRequestMarker: marker,+ notifications: [capturedStartedActivity()],+ childResumeSnapshots: { [CHILD_A]: childSnapshot },+ };+ // @effect-diagnostics-next-line preferSchemaOverJson:off+ NodeFS.writeFileSync(scriptPath, JSON.stringify(script), "utf8");+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });++ const runtime = yield* makeCodexSessionRuntime({+ threadId: ThreadId.make(`thread-collab-model-${name}`),+ binaryPath: peerPath,+ cwd: "/tmp",+ runtimeMode: "full-access",+ environment: { ...process.env, T3_CODEX_COLLAB_SCRIPT: scriptPath },+ });+ const eventsFiber = yield* runtime.events.pipe(+ Stream.takeUntil(+ (event) =>+ event.method === "serverRequest/resolved" &&+ (event.payload as { requestId?: string }).requestId === marker,+ ),+ Stream.runCollect,+ Effect.forkScoped,+ );++ yield* runtime.start();+ yield* runtime.sendTurn({ input: "finish without child metadata" });+ const events = Array.from(yield* Fiber.join(eventsFiber));+ assert.isTrue(events.some((event) => event.method === "turn/completed"));+ assert.equal(readRecordedRequests().length, 1);++ yield* runtime.close;+ NodeFS.rmSync(scriptPath, { force: true });+ NodeFS.rmSync(`${scriptPath}.requests`, { force: true });+ }).pipe(Effect.scoped);+ }+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),+ );+it.effect("replays the captured fan-out into synthetic agent events without child leaks", () =>Effect.gen(function* () {// @effect-diagnostics-next-line preferSchemaOverJson:offdiff --git a/apps/server/src/provider/Layers/CodexCollabWire.test.ts b/apps/server/src/provider/Layers/CodexCollabWire.test.tsindex 50e5e819d1f..363c1560ca5 100644--- a/apps/server/src/provider/Layers/CodexCollabWire.test.ts+++ b/apps/server/src/provider/Layers/CodexCollabWire.test.ts@@ -119,6 +119,8 @@ describe("routeCodexChildNotification", () => {"turn/completed","thread/status/changed","thread/tokenUsage/updated",+ "thread/settings/updated",+ "model/rerouted","item/started","item/completed","thread/closed",@@ -159,6 +161,8 @@ describe("routeCodexChildNotification", () => {"turn/completed","turn/plan/updated","item/plan/delta",+ "thread/settings/updated",+ "model/rerouted",]) {assert.notEqual(routeCodexChildNotification(method),diff --git a/apps/server/src/provider/Layers/CodexSessionRuntime.ts b/apps/server/src/provider/Layers/CodexSessionRuntime.tsindex b34067b7fb9..d83489763f5 100644--- a/apps/server/src/provider/Layers/CodexSessionRuntime.ts+++ b/apps/server/src/provider/Layers/CodexSessionRuntime.ts@@ -137,6 +137,12 @@ const CodexTurnStartParamsWithCollaborationMode = EffectCodexSchema.V2TurnStartPconst decodeCodexTurnStartParamsWithCollaborationMode = Schema.decodeUnknownEffect(CodexTurnStartParamsWithCollaborationMode,);+const CodexChildResumeMetadata = Schema.Struct({+ thread: Schema.Struct({ id: Schema.String }),+ model: Schema.String,+ reasoningEffort: Schema.optionalKey(Schema.NullOr(Schema.String)),+});+const decodeCodexChildResumeMetadata = Schema.decodeUnknownEffect(CodexChildResumeMetadata);export type CodexTurnStartParamsWithCollaborationMode =typeof CodexTurnStartParamsWithCollaborationMode.Type;@@ -731,7 +737,9 @@ function readNotificationThreadId(notification: CodexServerNotification): stringcase "thread/unarchived":case "thread/closed":case "thread/name/updated":+ case "thread/settings/updated":case "thread/tokenUsage/updated":+ case "model/rerouted":case "turn/started":case "hook/started":case "turn/completed":@@ -904,6 +912,35 @@ interface CollabChildAgentState {readonly spawnTurnId: TurnId | undefined;}+interface CollabChildMetadataState {+ readonly model: string | undefined;+ readonly effort: string | undefined;+ readonly lookupStarted: boolean;+ readonly closed: boolean;+}++function collabChildIdentity(+ child: CollabChildAgentState,+ metadata: CollabChildMetadataState | undefined,+) {+ return {+ agentThreadId: child.agentThreadId,+ ...(child.nickname ? { nickname: child.nickname } : {}),+ ...(child.role ? { role: child.role } : {}),+ ...(child.agentPath ? { agentPath: child.agentPath } : {}),+ ...(metadata?.model ? { model: metadata.model } : {}),+ ...(metadata?.effort ? { effort: metadata.effort } : {}),+ };+}++function nonEmptyMetadataValue(value: unknown): string | undefined {+ if (typeof value !== "string") {+ return undefined;+ }+ const trimmed = value.trim();+ return trimmed.length > 0 ? trimmed : undefined;+}+function readThreadSpawnSource(thread: { readonly source: unknown }):| {nickname: string | undefined;@@ -969,7 +1006,9 @@ function shouldSuppressChildConversationNotification(method === "thread/closed" ||method === "thread/compacted" ||method === "thread/name/updated" ||+ method === "thread/settings/updated" ||method === "thread/tokenUsage/updated" ||+ method === "model/rerouted" ||method === "turn/started" ||method === "turn/completed" ||method === "turn/plan/updated" ||@@ -1000,6 +1039,8 @@ const CHILD_AGENT_EVENT_METHODS: ReadonlySet<string> = new Set(["turn/completed","thread/status/changed","thread/tokenUsage/updated",+ "thread/settings/updated",+ "model/rerouted","item/started","item/completed","thread/closed",@@ -1018,7 +1059,6 @@ const CHILD_CHATTER_METHODS: ReadonlySet<string> = new Set(["turn/plan/updated","turn/diff/updated","thread/name/updated",- "thread/settings/updated","rawResponseItem/completed",// Child-owned thread lifecycle: the parent adapter maps these onto the// PARENT thread (archived/compacted state), so a child compacting would@@ -1126,6 +1166,7 @@ export const makeCodexSessionRuntime = (const pendingUserInputsRef = yield* Ref.make(new Map<ApprovalRequestId, PendingUserInput>());const collabReceiverTurnsRef = yield* Ref.make(new Map<string, TurnId>());const collabChildAgentsRef = yield* Ref.make(new Map<string, CollabChildAgentState>());+ const collabChildMetadataRef = yield* Ref.make(new Map<string, CollabChildMetadataState>());/** Child provider-thread id → its currently running provider turn id. */const collabChildLiveTurnsRef = yield* Ref.make(new Map<string, string>());const suppressMemoryConsolidationNotification = makeMemoryConsolidationNotificationFilter();@@ -1221,6 +1262,133 @@ export const makeCodexSessionRuntime = (message,});+ const updateCollabChildMetadata = (+ agentThreadId: string,+ update: { readonly model?: string; readonly effort?: string },+ overwriteKnown: boolean,+ ) =>+ Ref.modify(collabChildMetadataRef, (current) => {+ const previous = current.get(agentThreadId) ?? {+ model: undefined,+ effort: undefined,+ lookupStarted: false,+ closed: false,+ };+ const model =+ update.model && (overwriteKnown || !previous.model) ? update.model : previous.model;+ const effort =+ update.effort && (overwriteKnown || !previous.effort) ? update.effort : previous.effort;+ const changed = model !== previous.model || effort !== previous.effort;+ if (!changed) {+ return [false, current] as const;+ }+ const next = new Map(current);+ next.set(agentThreadId, { ...previous, model, effort });+ return [true, next] as const;+ });++ const markCollabChildClosed = (agentThreadId: string) =>+ Ref.update(collabChildMetadataRef, (current) => {+ const previous = current.get(agentThreadId) ?? {+ model: undefined,+ effort: undefined,+ lookupStarted: false,+ closed: false,+ };+ if (previous.closed) {+ return current;+ }+ const next = new Map(current);+ next.set(agentThreadId, { ...previous, closed: true });+ return next;+ });++ const markCollabChildOpen = (agentThreadId: string) =>+ Ref.update(collabChildMetadataRef, (current) => {+ const previous = current.get(agentThreadId);+ if (!previous?.closed) {+ return current;+ }+ const next = new Map(current);+ next.set(agentThreadId, { ...previous, closed: false });+ return next;+ });++ const emitCollabChildMetadataUpdated = Effect.fn(+ "CodexSessionRuntime.emitCollabChildMetadataUpdated",+ )(function* (agentThreadId: string) {+ const child = (yield* Ref.get(collabChildAgentsRef)).get(agentThreadId);+ const metadata = (yield* Ref.get(collabChildMetadataRef)).get(agentThreadId);+ if (!child || metadata?.closed) {+ return;+ }+ yield* emitEvent({+ kind: "notification",+ threadId: options.threadId,+ ...(child.spawnTurnId ? { turnId: child.spawnTurnId } : {}),+ method: "collabAgent/metadataUpdated",+ payload: collabChildIdentity(child, metadata),+ });+ });++ const startCollabChildMetadataLookup = Effect.fn(+ "CodexSessionRuntime.startCollabChildMetadataLookup",+ )(function* (agentThreadId: string) {+ const shouldStart = yield* Ref.modify(collabChildMetadataRef, (current) => {+ const previous = current.get(agentThreadId) ?? {+ model: undefined,+ effort: undefined,+ lookupStarted: false,+ closed: false,+ };+ if (previous.lookupStarted || previous.closed) {+ return [false, current] as const;+ }+ const next = new Map(current);+ next.set(agentThreadId, { ...previous, lookupStarted: true });+ return [true, next] as const;+ });+ if (!shouldStart) {+ return;+ }++ // The child is already loaded. This rejoins it without starting a turn,+ // and excludeTurns avoids loading or replaying its history.+ yield* client.raw+ .request("thread/resume", { threadId: agentThreadId, excludeTurns: true })+ .pipe(+ Effect.flatMap(decodeCodexChildResumeMetadata),+ Effect.timeout("5 seconds"),+ Effect.flatMap((response) =>+ Effect.gen(function* () {+ if (response.thread.id !== agentThreadId) {+ return;+ }+ const child = (yield* Ref.get(collabChildAgentsRef)).get(agentThreadId);+ const metadata = (yield* Ref.get(collabChildMetadataRef)).get(agentThreadId);+ if (!child || metadata?.closed) {+ return;+ }+ const model = nonEmptyMetadataValue(response.model);+ const effort = nonEmptyMetadataValue(response.reasoningEffort);+ const changed = yield* updateCollabChildMetadata(+ agentThreadId,+ {+ ...(model ? { model } : {}),+ ...(effort ? { effort } : {}),+ },+ false,+ );+ if (changed) {+ yield* emitCollabChildMetadataUpdated(agentThreadId);+ }+ }),+ ),+ Effect.catch(() => Effect.void),+ Effect.forkIn(runtimeScope),+ );+ });+const settlePendingApprovals = (decision: ProviderApprovalDecision) =>Ref.get(pendingApprovalsRef).pipe(Effect.flatMap((pendingApprovals) =>@@ -1261,6 +1429,10 @@ export const makeCodexSessionRuntime = (if (!spawn) {return false;}+ const rootProviderThreadId = currentProviderThreadId(yield* Ref.get(sessionRef));+ if (thread.id === rootProviderThreadId) {+ return false;+ }// Merge with any subAgentActivity registration that got here// first. spawnTurnId is REGISTRATION-time-only on both paths: for// an already-known child we keep its value (set or unset) — a@@ -1287,20 +1459,19 @@ export const makeCodexSessionRuntime = (next.set(thread.id, state);return next;});+ const metadata = (yield* Ref.get(collabChildMetadataRef)).get(thread.id);yield* emitEvent({kind: "notification",threadId: options.threadId,method: "collabAgent/started",...(state.spawnTurnId ? { turnId: state.spawnTurnId } : {}),payload: {- agentThreadId: state.agentThreadId,- ...(state.nickname ? { nickname: state.nickname } : {}),- ...(state.role ? { role: state.role } : {}),- ...(state.agentPath ? { agentPath: state.agentPath } : {}),+ ...collabChildIdentity(state, metadata),...(state.depth !== undefined ? { depth: state.depth } : {}),...(state.parentThreadId ? { parentThreadId: state.parentThreadId } : {}),},});+ yield* startCollabChildMetadataLookup(thread.id);return true;}@@ -1350,17 +1521,22 @@ export const makeCodexSessionRuntime = (return next;});const registeredChild = (yield* Ref.get(collabChildAgentsRef)).get(item.agentThreadId);+ const metadata = (yield* Ref.get(collabChildMetadataRef)).get(item.agentThreadId);yield* emitEvent({kind: "notification",threadId: options.threadId,method: "collabAgent/activity",...(registeredChild?.spawnTurnId ? { turnId: registeredChild.spawnTurnId } : {}),payload: {- agentThreadId: item.agentThreadId,- agentPath: item.agentPath,+ ...(registeredChild+ ? collabChildIdentity(registeredChild, metadata)+ : { agentThreadId: item.agentThreadId, agentPath: item.agentPath }),activityKind: item.kind,},});+ if (item.kind === "started") {+ yield* startCollabChildMetadataLookup(item.agentThreadId);+ }return true;}@@ -1376,19 +1552,45 @@ export const makeCodexSessionRuntime = (if (providerConversationId === interceptRootId) {return false;}++ if (+ interceptRootId !== undefined &&+ (notification.method === "thread/settings/updated" ||+ notification.method === "model/rerouted")+ ) {+ const model = nonEmptyMetadataValue(+ notification.method === "thread/settings/updated"+ ? notification.params.threadSettings.model+ : notification.params.toModel,+ );+ const effort =+ notification.method === "thread/settings/updated"+ ? nonEmptyMetadataValue(notification.params.threadSettings.effort)+ : undefined;+ const changed = yield* updateCollabChildMetadata(+ providerConversationId,+ {+ ...(model ? { model } : {}),+ ...(effort ? { effort } : {}),+ },+ true,+ );+ if (changed && (yield* Ref.get(collabChildAgentsRef)).has(providerConversationId)) {+ yield* emitCollabChildMetadataUpdated(providerConversationId);+ }+ return true;+ }+const children = yield* Ref.get(collabChildAgentsRef);const child = children.get(providerConversationId);if (!child) {return false;}- const childIdentity = {- agentThreadId: child.agentThreadId,- ...(child.nickname ? { nickname: child.nickname } : {}),- ...(child.role ? { role: child.role } : {}),- ...(child.agentPath ? { agentPath: child.agentPath } : {}),- };+ const metadata = (yield* Ref.get(collabChildMetadataRef)).get(child.agentThreadId);+ const childIdentity = collabChildIdentity(child, metadata);switch (notification.method) {case "turn/started": {+ yield* markCollabChildOpen(child.agentThreadId);const childTurnId =typeof (notification.params as { turn?: { id?: unknown } }).turn?.id === "string"? ((notification.params as { turn: { id: string } }).turn.id as string)@@ -1472,6 +1674,7 @@ export const makeCodexSessionRuntime = (next.delete(child.agentThreadId);return next;});+ yield* markCollabChildClosed(child.agentThreadId);yield* emitEvent({kind: "notification",threadId: options.threadId,diff --git a/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs b/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjsindex d3bdee36712..4e6d1b26194 100644--- a/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs+++ b/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs@@ -57,7 +57,55 @@ rl.on("line", (line) => {});return;}- if (method === "thread/start" || method === "thread/resume") {+ if (method === "thread/start") {+ write({ id, result: fixture.responses.threadStart });+ return;+ }+ if (method === "thread/resume") {+ if (script.recordRequests) {+ NodeFS.appendFileSync(+ `${process.env.T3_CODEX_COLLAB_SCRIPT}.requests`,+ `${JSON.stringify({ method, params: message.params })}\n`,+ );+ }+ const threadId = message.params?.threadId;+ const childSnapshot = script.childResumeSnapshots?.[threadId];+ if (script.resumeRequestMarker) {+ write({+ jsonrpc: "2.0",+ method: "serverRequest/resolved",+ params: {+ threadId: script.rootThreadId,+ requestId: script.resumeRequestMarker,+ },+ });+ }+ if (childSnapshot?.hang) {+ return;+ }+ if (childSnapshot?.error) {+ write({ id, error: { code: -32000, message: childSnapshot.error } });+ return;+ }+ if (childSnapshot) {+ write({+ id,+ result: {+ ...fixture.responses.threadStart,+ model: childSnapshot.model,+ reasoningEffort: childSnapshot.reasoningEffort,+ thread: {+ ...fixture.responses.threadStart.thread,+ id: threadId,+ sessionId: threadId,+ },+ },+ });+ for (const notification of childSnapshot.notifications ?? []) {+ write({ jsonrpc: "2.0", method: notification.method, params: notification.params });+ }+ return;+ }write({ id, result: fixture.responses.threadStart });return;}diff --git a/docs/user/providers-codex.md b/docs/user/providers-codex.mdindex f696e8877b2..c4ce91e333b 100644--- a/docs/user/providers-codex.md+++ b/docs/user/providers-codex.md@@ -34,6 +34,12 @@ In an existing Codex thread, send `/feedback` or `/feedback` followed by a descrissue. T3 Code uploads the thread and Codex logs to OpenAI and shows a thread ID that you can copyand share with OpenAI employees.+## Sub-agent models++The web and desktop Agents panel shows each sub-agent's model and reasoning effort when Codex+reports them. If Codex does not report either value, T3 Code leaves it out instead of using the+parent agent's settings.+## Approve access to other appsWhen a Codex tool needs access to an app such as Safari, T3 Code shows the app name and asks fordiff --git a/packages/client-runtime/src/state/subagentRuntime.test.ts b/packages/client-runtime/src/state/subagentRuntime.test.tsindex ff0aea7c8a5..f87531f1580 100644--- a/packages/client-runtime/src/state/subagentRuntime.test.ts+++ b/packages/client-runtime/src/state/subagentRuntime.test.ts@@ -603,6 +603,43 @@ describe("model and effort attribution", () => {expect(agents[0]!.effort).toBe("high");});+ it("applies metadata-only updates without changing the current status", () => {+ const waitingRows = [+ activity("task.updated", {+ taskId: "task-metadata",+ title: "Check metadata",+ status: "waiting",+ }),+ activity("task.updated", {+ taskId: "task-metadata",+ model: "gpt-5.6-sol",+ effort: "high",+ }),+ ];+ const waitingAgent = fold(waitingRows)[0]!;+ expect(waitingAgent.status).toBe("waiting");+ expect(formatSubagentModelLabel(waitingAgent.model, waitingAgent.effort)).toBe(+ "gpt-5.6-sol · high",+ );++ const idleRows = [+ ...waitingRows,+ activity("task.updated", { taskId: "task-metadata", status: "idle" }),+ activity("task.updated", { taskId: "task-metadata", model: "gpt-5.6-sol" }),+ ];+ expect(fold(idleRows)[0]!.status).toBe("idle");++ const completedAgent = fold([+ ...idleRows,+ activity("task.progress", { taskId: "task-metadata", typedUsage: { totalTokens: 42 } }),+ activity("task.completed", { taskId: "task-metadata", status: "completed" }),+ activity("task.updated", { taskId: "task-metadata", effort: "high" }),+ ])[0]!;+ expect(completedAgent.status).toBe("completed");+ expect(completedAgent.model).toBe("gpt-5.6-sol");+ expect(completedAgent.effort).toBe("high");+ });+it("formatSubagentModelLabel compacts ids and appends effort", () => {expect(formatSubagentModelLabel("claude-sonnet-5[1m]", "high")).toBe("sonnet-5[1m] · high");expect(formatSubagentModelLabel("claude-opus-4-20250514", null)).toBe("opus-4");