Skip to content

Commit 51005a6

Browse files
feat: report the model of each native subagent session (#678)
After the adapter announces a native subagent session (`subagent_spawned`), it sends a `config_option_update` with the child session ID. The update holds one `select` option of category `model`. Its only entry is the current model of the child, because the client may not change it. The entry has the same `value` and `name` as the same model in the `model` option of the parent session, so a client can compare them. A model that the parent option does not offer, or a parent without a model option, keeps the full model ID as the value and the name. Where the model comes from. The adapter reports only what Codex states about the child, ranked in this order: 1. the `model` of the child thread in `thread/started`. It also counts when it arrives before the spawn names its child, if the thread names this root (or a child of it) as its parent or a spawn of this root is in flight. The root turn end clears these early models; 2. the resolved `model` of the `subAgentActivity` item that announces the child; 3. `thread/settings/updated` of the child, which is a real model change and always wins. A report from a lower source does not replace a higher one, so a `thread/started` of a resume keeps the activity model. A settings change sends a new snapshot. For a child that is not announced yet, the announcement carries the last settings model, and the buffered changes send no more updates. A model that gives the same option value sends no new snapshot. A reopened child (a new generation) gets the same update. ACP v2 gets the same update in the v2 config option shape. The adapter does not guess: it does not use the `spawnAgent` model (a role config can override it) or the model of the parent. A child without a stated model gets no update, which the RFD allows. In Codex 0.164 the `subAgentActivity` that announces a multi-agent v2 child carries the resolved model, so a live child normally has one. History replay sends only the `subAgentActivity` model of the child. Older records without it get no update. No update is sent for a child with no known model, to a client without session configuration (JetBrains 2026.1), or to a client without native subagent sessions. A child that ended, or that a reopen gave another session, gets no report. A failed model report is logged and does not stop the announcement or the replay. Example (ACP v1): ```json {"sessionId": "child-1", "update": {"sessionUpdate": "config_option_update", "configOptions": [ {"id": "model", "name": "Model", "description": "Model Codex uses for the subagent", "category": "model", "type": "select", "currentValue": "gpt-5.2-codex", "options": [{"value": "gpt-5.2-codex", "name": "5.2 Codex", "description": "gpt-5.2-codex model"}]} ]}} ``` This follows [Child configuration](https://github.com/agentclientprotocol/agent-client-protocol/blob/main/docs/rfds/subagents.mdx#child-configuration) in the subagents RFD (see also agentclientprotocol/agent-client-protocol#2482).
1 parent a77829f commit 51005a6

17 files changed

Lines changed: 1051 additions & 19 deletions

‎src/CodexAcpServer.ts‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ import {
170170
clientSupportsSubagents,
171171
type SubagentAwareSessionCapabilities,
172172
} from "./subagents/AcpSubagents";
173-
import {CodexSubagentEventRouter} from "./subagents/CodexSubagentEventRouter";
173+
import {
174+
CodexSubagentEventRouter,
175+
reportSubagentModel,
176+
type SubagentModels,
177+
} from "./subagents/CodexSubagentEventRouter";
174178
import {nameFromAgentPath} from "./subagents/CodexAgentPath";
175179
import {listCodexHooks, trustCodexHooks, type CodexHookIdentity} from "./CodexHookTrust";
176180
import type {HooksListEntry} from "./app-server/v2/HooksListEntry";
@@ -1213,6 +1217,7 @@ export class CodexAcpServer {
12131217
clientSupportsSubagents(this.clientCapabilities),
12141218
new ACPSessionConnection(this.connection, sessionId),
12151219
childSessionId => this.reportingConnection.reports.releaseOpen(childSessionId),
1220+
() => this.subagentModels(sessionState),
12161221
),
12171222
asyncTasks: this.createAsyncTasks(sessionId),
12181223
compactions: new CodexSessionCompactions(),
@@ -3122,6 +3127,19 @@ export class CodexAcpServer {
31223127
await new ACPSessionConnection(this.connection, sessionState.sessionId).update(update);
31233128
}
31243129

3130+
/** The models of a root session, for the configuration of its native subagent sessions. */
3131+
private subagentModels(sessionState: SessionState): SubagentModels | null {
3132+
if (!this.isSessionConfigEnabled()) return null;
3133+
let currentModel: string | null = null;
3134+
try {
3135+
currentModel = ModelId.fromString(sessionState.currentModelId).model;
3136+
}
3137+
catch {
3138+
// A session without a known model gives no current entry to match.
3139+
}
3140+
return {currentModel, availableModels: sessionState.availableModels};
3141+
}
3142+
31253143
private findCurrentModel(models: Model[], currentModelId: string): Model | undefined {
31263144
const modelId = ModelId.fromString(currentModelId);
31273145
return models.find(m => m.id === modelId.model);
@@ -3271,6 +3289,7 @@ export class CodexAcpServer {
32713289
clientSupportsSubagents(this.clientCapabilities),
32723290
new ACPSessionConnection(this.connection, sessionId),
32733291
childSessionId => this.reportingConnection.reports.releaseOpen(childSessionId),
3292+
() => this.subagentModels(sessionState),
32743293
),
32753294
asyncTasks: this.createAsyncTasks(sessionId),
32763295
compactions: new CodexSessionCompactions(),
@@ -3404,7 +3423,11 @@ export class CodexAcpServer {
34043423
isOpen: () => boolean,
34053424
): Promise<void> {
34063425
const session = new ACPSessionConnection(this.connection, sessionId);
3407-
const announced = new Map<string, {generation: number; sessionId: string; terminal: boolean}>();
3426+
const announced = new Map<string, {generation: number; sessionId: string; terminal: boolean; model?: string}>();
3427+
// Sends the model of a replayed child after its announcement, as the live session does. Replay sends only
3428+
// the resolved model that the activity items name for the child, so an older record gets no model option.
3429+
const reportModel = (childSessionId: string, model: string | undefined) =>
3430+
reportSubagentModel(session, childSessionId, this.subagentModels(sessionState), model);
34083431
// v2 only (this path also serves v1's native replay, unchanged there).
34093432
const startedReplayMessages = new Set<string>();
34103433
for await (const items of itemPages) {
@@ -3436,14 +3459,21 @@ export class CodexAcpServer {
34363459
// An interaction that started no child turn is not a new generation.
34373460
if (activityKind === "interacted" && !childItems) continue;
34383461
const name = nameFromAgentPath(item.agentPath, `Agent ${item.agentThreadId.slice(-8)}`);
3462+
const model = item.model || previous?.model;
34393463
await session.update({
34403464
sessionUpdate: "subagent_spawned",
34413465
subagentSessionId: childSessionId,
34423466
name,
34433467
task: `Delegated task for ${name}`,
34443468
capabilities: {},
34453469
});
3446-
announced.set(item.agentThreadId, {generation, sessionId: childSessionId, terminal: false});
3470+
announced.set(item.agentThreadId, {
3471+
generation,
3472+
sessionId: childSessionId,
3473+
terminal: false,
3474+
...(model ? {model} : {}),
3475+
});
3476+
await reportModel(childSessionId, model);
34473477
if (childItems) {
34483478
const commandIds = new Set<string>();
34493479
try {
@@ -3477,6 +3507,7 @@ export class CodexAcpServer {
34773507
const child = announced.get(item.agentThreadId);
34783508
if (!child) {
34793509
const name = nameFromAgentPath(item.agentPath, `Agent ${item.agentThreadId.slice(-8)}`);
3510+
const model = item.model || undefined;
34803511
await session.update({
34813512
sessionUpdate: "subagent_spawned",
34823513
subagentSessionId: item.agentThreadId,
@@ -3488,7 +3519,9 @@ export class CodexAcpServer {
34883519
generation: 1,
34893520
sessionId: item.agentThreadId,
34903521
terminal: false,
3522+
...(model ? {model} : {}),
34913523
});
3524+
await reportModel(item.agentThreadId, model);
34923525
continue;
34933526
}
34943527
if (child.terminal) continue;

‎src/ModelConfigOption.ts‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,31 @@ export function findSupportedEffort(
3333
return options.find(o => o.reasoningEffort === effort)?.reasoningEffort;
3434
}
3535

36-
export function createModelConfigOption(
37-
availableModels: Array<Model>,
38-
currentBaseModelId: string,
39-
recommendedModelId?: string,
40-
): SessionConfigOption {
41-
const options: Array<{ value: string; name: string; description: string | null }> = availableModels.map(model => ({
36+
type ModelOption = { value: string; name: string; description: string | null };
37+
38+
/** The entries of the session `model` option. */
39+
function modelOptions(availableModels: ReadonlyArray<Model>, currentBaseModelId: string | null): Array<ModelOption> {
40+
const options: Array<ModelOption> = availableModels.map(model => ({
4241
value: model.id,
4342
name: formatModelDisplayName(model.displayName),
4443
description: model.description,
4544
}));
46-
if (!availableModels.some(model => model.id === currentBaseModelId)) {
45+
if (currentBaseModelId !== null && !availableModels.some(model => model.id === currentBaseModelId)) {
4746
options.unshift({
4847
value: currentBaseModelId,
4948
name: formatModelDisplayName(currentBaseModelId),
5049
description: null,
5150
});
5251
}
52+
return options;
53+
}
54+
55+
export function createModelConfigOption(
56+
availableModels: Array<Model>,
57+
currentBaseModelId: string,
58+
recommendedModelId?: string,
59+
): SessionConfigOption {
60+
const options = modelOptions(availableModels, currentBaseModelId);
5361

5462
const recommendation = recommendedModelId && options.some(option => option.value === recommendedModelId)
5563
? recommendedModelId
@@ -91,3 +99,33 @@ export function createReasoningEffortConfigOption(
9199
: {}),
92100
};
93101
}
102+
103+
/**
104+
* The model option of a native subagent session. The client may not change the model of a subagent, so the
105+
* option offers only the current model. Its value and name are those of the same model in the `model` option
106+
* of the parent session, so that the client can compare them. A model that the parent option does not offer
107+
* keeps its full id as the value and the name.
108+
*/
109+
export function createSubagentModelConfigOption(
110+
availableModels: ReadonlyArray<Model>,
111+
parentBaseModelId: string | null,
112+
model: string,
113+
): SessionConfigOption {
114+
// Without models the parent session has no model option, so there is nothing to match.
115+
const parentOptions = availableModels.length > 0 ? modelOptions(availableModels, parentBaseModelId) : [];
116+
// Codex can name a model by its `model` slug instead of its id.
117+
const id = availableModels.find(candidate => candidate.id === model)?.id
118+
?? availableModels.find(candidate => candidate.model === model)?.id
119+
?? model;
120+
const option = parentOptions.find(candidate => candidate.value === id)
121+
?? {value: model, name: model, description: null};
122+
return {
123+
id: MODEL_CONFIG_ID,
124+
name: "Model",
125+
description: "Model Codex uses for the subagent",
126+
category: "model",
127+
type: "select",
128+
currentValue: option.value,
129+
options: [option],
130+
};
131+
}

‎src/__tests__/CodexACPAgent/agent-file-change-report.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ async function setupNativeSubagentPrompt(): Promise<{
167167
true,
168168
new ACPSessionConnection(fixture.getAcpConnection(), sessionState.sessionId),
169169
() => {},
170+
() => ({currentModel: null, availableModels: []}),
170171
);
171172
vi.spyOn(fixture.getCodexAcpAgent(), "getSessionState").mockReturnValue(sessionState);
172173
vi.spyOn(fixture.getCodexAppServerClient(), "turnStart")

‎src/__tests__/CodexACPAgent/async-tasks.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ describe("Codex background terminal tasks", () => {
490490
});
491491
const sessionState = createTestSessionState({sessionId: "thread-1"});
492492
const session = new ACPSessionConnection(fixture.getAcpConnection(), sessionState.sessionId);
493-
sessionState.subagents = new CodexSubagentEventRouter(sessionState.sessionId, true, session, () => {});
493+
sessionState.subagents = new CodexSubagentEventRouter(sessionState.sessionId, true, session, () => {}, () => ({currentModel: null, availableModels: []}));
494494
sessionState.asyncTasks = new CodexBackgroundTerminalTasks(
495495
true,
496496
sessionState.sessionId,

‎src/__tests__/CodexACPAgent/collab-agent-events.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
4444
true,
4545
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
4646
() => {},
47+
() => ({currentModel: null, availableModels: []}),
4748
);
4849
return response;
4950
}
@@ -1139,6 +1140,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
11391140
true,
11401141
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
11411142
() => {},
1143+
() => ({currentModel: null, availableModels: []}),
11421144
);
11431145
await router.handle({
11441146
method: "item/started",
@@ -1614,6 +1616,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
16141616
true,
16151617
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
16161618
() => {},
1619+
() => ({currentModel: null, availableModels: []}),
16171620
);
16181621
const activity = (threadId: string, path: string): ServerNotification => ({
16191622
method: "item/started",
@@ -1690,6 +1693,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
16901693
true,
16911694
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
16921695
() => {},
1696+
() => ({currentModel: null, availableModels: []}),
16931697
);
16941698
await router.handle({
16951699
method: "item/started",
@@ -1751,6 +1755,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
17511755
true,
17521756
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
17531757
() => {},
1758+
() => ({currentModel: null, availableModels: []}),
17541759
);
17551760
const spawn = (item: Record<string, unknown>) => router.handle({
17561761
method: "item/started",
@@ -1781,6 +1786,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
17811786
true,
17821787
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
17831788
childSessionId => ended.push(childSessionId),
1789+
() => ({currentModel: null, availableModels: []}),
17841790
);
17851791
const rootItem = (item: Record<string, unknown>) => router.handle({
17861792
method: "item/started",
@@ -1836,6 +1842,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
18361842
true,
18371843
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
18381844
() => {},
1845+
() => ({currentModel: null, availableModels: []}),
18391846
);
18401847
await router.handle({
18411848
method: "item/started",
@@ -1942,6 +1949,7 @@ describe("CodexEventHandler - collab agent tool call events", () => {
19421949
true,
19431950
new ACPSessionConnection(mockFixture.getAcpConnection(), sessionId),
19441951
childSessionId => reports.releaseOpen(childSessionId),
1952+
() => ({currentModel: null, availableModels: []}),
19451953
);
19461954
await router.handle(spawn(childThreadId));
19471955
if (materialize) await router.handle(activity(childThreadId));
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"sessionId": "root",
4+
"update": {
5+
"sessionUpdate": "subagent_spawned",
6+
"subagentSessionId": "child-1",
7+
"name": "Reviewer",
8+
"task": "Review the diff",
9+
"capabilities": {}
10+
}
11+
},
12+
{
13+
"sessionId": "child-1",
14+
"update": {
15+
"sessionUpdate": "config_option_update",
16+
"configOptions": [
17+
{
18+
"id": "model",
19+
"name": "Model",
20+
"description": "Model Codex uses for the subagent",
21+
"category": "model",
22+
"type": "select",
23+
"currentValue": "gpt-5.2-codex",
24+
"options": [
25+
{
26+
"value": "gpt-5.2-codex",
27+
"name": "5.2 Codex",
28+
"description": "gpt-5.2-codex model"
29+
}
30+
]
31+
}
32+
]
33+
}
34+
}
35+
]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[
2+
{
3+
"sessionId": "root",
4+
"update": {
5+
"sessionUpdate": "subagent_spawned",
6+
"subagentSessionId": "child-1",
7+
"name": "Reviewer",
8+
"task": "Review the diff",
9+
"capabilities": {}
10+
}
11+
},
12+
{
13+
"sessionId": "child-1",
14+
"update": {
15+
"sessionUpdate": "config_option_update",
16+
"configOptions": [
17+
{
18+
"id": "model",
19+
"name": "Model",
20+
"description": "Model Codex uses for the subagent",
21+
"category": "model",
22+
"type": "select",
23+
"currentValue": "gpt-5.2-codex",
24+
"options": [
25+
{
26+
"value": "gpt-5.2-codex",
27+
"name": "5.2 Codex",
28+
"description": "gpt-5.2-codex model"
29+
}
30+
]
31+
}
32+
]
33+
}
34+
},
35+
{
36+
"sessionId": "root",
37+
"update": {
38+
"sessionUpdate": "subagent_state_update",
39+
"subagentSessionId": "child-1",
40+
"state": "completed"
41+
}
42+
},
43+
{
44+
"sessionId": "root",
45+
"update": {
46+
"sessionUpdate": "subagent_spawned",
47+
"subagentSessionId": "child-1:generation:2",
48+
"name": "Reviewer",
49+
"task": "Review the diff",
50+
"capabilities": {}
51+
}
52+
},
53+
{
54+
"sessionId": "child-1:generation:2",
55+
"update": {
56+
"sessionUpdate": "config_option_update",
57+
"configOptions": [
58+
{
59+
"id": "model",
60+
"name": "Model",
61+
"description": "Model Codex uses for the subagent",
62+
"category": "model",
63+
"type": "select",
64+
"currentValue": "gpt-5.2-codex",
65+
"options": [
66+
{
67+
"value": "gpt-5.2-codex",
68+
"name": "5.2 Codex",
69+
"description": "gpt-5.2-codex model"
70+
}
71+
]
72+
}
73+
]
74+
}
75+
}
76+
]

0 commit comments

Comments
 (0)