Skip to content

Commit 7d7e95a

Browse files
authored
fix: report verified standard subagent directories (#722)
## Summary Continues the original SDK 2.2 audit at specification baseline `d5e9949c3e6a9cd072adebaa44e6f63289590c17`. No later specification features are added. - Extend the existing child configuration/readback owner to publish verified absolute child `cwd` values as standard `subagent_update` frames on the immediate parent. - Do not reset directory fields on announcements or replay. `null` explicitly means inheritance, not unknown placement. Keep retained overrides until verified current data replaces them, rather than temporarily replacing a worktree path with the parent's directory. - Reuse native child-ID, parent-ID, loaded-state, attachment, and pending-read checks. Current native settings outrank older readback. Optional readback does not block child output. - Omit `additionalDirectories`: Codex does not expose an authoritative child ACP additional-directory list. Do not infer it from provider IDs, parent roots, or writable sandbox paths, and do not report `[]` or `null` as a substitute for unknown data. - Keep AIR's legacy subagent-event contract unchanged. ## Validation - `npm run typecheck`: passed - `npm run build`: passed - `npm test`: 2,379 passed, 39 skipped - `npm run test:integration`: all 19 passed; the real-Codex child matrix verifies directory publication before and after reattachment on both protocol versions - `git diff --check`: passed Dual-version wire coverage includes worktree placement, nested parent routing, replay without inheritance resets, unavailable current placement, invalid paths, superseded reads, unload/close, and foreign/mismatched child readback. Existing lifecycle goldens include the verified directory updates; these goldens consistently end with a newline. Includes the same Linux-aware background-process test probe as #720/#721: Linux zombie/dead PIDs are exited even while they remain unreaped. A live process at the close-response boundary still fails the assertion; no post-close wait is added. The real-Codex integration matrix directly verifies directory behavior. Opt-in E2E tests were not run. This PR is independently based on main and does not include #720 or #721. No review Markdown file is included.
1 parent 9c33f86 commit 7d7e95a

24 files changed

Lines changed: 163 additions & 31 deletions

‎docs/subagent-sessions.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ Subagents require bilateral capability negotiation during `initialize`.
2323

2424
`session/load` reconstructs the child tree from Codex history. It reports an orphan as `disconnected` when the history does not prove an outcome. Live timeout, `shutdown`, and `notFound` fallbacks currently use `failed`; this differs from the draft rule for an unknown outcome.
2525

26+
## Standard subagent directories
27+
28+
On standard subagent connections, directory information is part of `subagent_update` on the immediate parent. This applies to both ACP versions. It does not change AIR's legacy subagent events.
29+
30+
A verified loaded-child read reports its absolute `cwd`, including a worktree directory. Known child settings changes update that value. Announcements do not reset directory fields while readback is pending. Omission preserves a retained override; `null` would explicitly restore inheritance from the immediate parent, not report an unknown directory. Readback does not block child output, and a superseded read cannot replace newer settings.
31+
32+
The adapter verifies the child's ID, parent, and loaded state before accepting readback. It does not report relative paths or infer directories from provider IDs. Codex does not expose an authoritative ACP additional-directory list for children, so the adapter omits that field. It does not copy parent roots or treat writable sandbox paths as workspace roots. `[]` would mean explicitly no additional directories, not unknown directories.
33+
2634
## Legacy fallback
2735

2836
Without native negotiation, subagent lifecycle stays an ordinary ACP tool call. Child permission and elicitation requests stay on the root session.

‎src/CodexAcpServer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ export class CodexAcpServer {
686686
private async readSubagentConfiguration(threadId: string, parentThreadId: string): Promise<ObservedSubagentConfiguration | null> {
687687
const thread = await this.codexAcpClient.readSubagentThread(threadId);
688688
if (!thread || thread.id !== threadId || thread.parentThreadId !== parentThreadId || thread.status.type === "notLoaded") return null;
689-
return {model: thread.model, effort: thread.reasoningEffort};
689+
return {model: thread.model, effort: thread.reasoningEffort, cwd: thread.cwd};
690690
}
691691

692692
private getSubagentInteractionHandlers(router: StandardSubagentEventRouter, rootSessionId: string): SubagentInteractionHandlers {

‎src/__tests__/CodexACPAgent/data/live-core-v1-cancel.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
"sessionUpdate": "subagent_update"
5050
}
5151
}
52-
]
52+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-identity.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@
7272
"sessionUpdate": "subagent_update"
7373
}
7474
}
75-
]
75+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-model.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"sessionUpdate": "config_option_update"
3232
}
3333
}
34-
]
34+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-nested.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
"sessionUpdate": "agent_message_chunk"
4949
}
5050
}
51-
]
51+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-ownership-foreign.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"sessionUpdate": "subagent_update"
99
}
1010
}
11-
]
11+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-ownership-owned.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
"sessionUpdate": "subagent_update"
1919
}
2020
},
21+
{
22+
"sessionId": "thread-1",
23+
"update": {
24+
"sessionId": "thread-1:subagent:worker",
25+
"cwd": "/workspace",
26+
"sessionUpdate": "subagent_update"
27+
}
28+
},
2129
{
2230
"sessionId": "thread-1",
2331
"update": {
@@ -48,4 +56,4 @@
4856
"sessionUpdate": "subagent_update"
4957
}
5058
}
51-
]
59+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-terminal.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,13 @@
110110
},
111111
"sessionUpdate": "subagent_update"
112112
}
113+
},
114+
{
115+
"sessionId": "thread-1",
116+
"update": {
117+
"sessionId": "thread-1:subagent:worker",
118+
"cwd": "/workspace",
119+
"sessionUpdate": "subagent_update"
120+
}
113121
}
114-
]
122+
]

‎src/__tests__/CodexACPAgent/data/live-core-v1-unknown.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
"sessionUpdate": "subagent_update"
4040
}
4141
}
42-
]
42+
]

0 commit comments

Comments
 (0)