-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat(native-chat): Codex sessions write their subagents into the host status store #22553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f424bd
42bf8b4
7513e36
4ccb972
d88c397
b63cd14
bd28276
4801fcb
e342134
acf3516
91be06a
ba30b8b
9a6b75d
e7239f1
b22661d
e930da1
754da3a
6b2e70c
d85668e
77bf4ca
9ef9114
d514f6a
637397d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { | |
| import { codexChildTurnState } from './codex-subagent-executions' | ||
| import { readRecord } from './codex-item-field-readers' | ||
| import { readCodexThreadItem } from './codex-structured-item-translation' | ||
| import { readCodexProviderVerdict } from './codex-structured-journal-provider-verdicts' | ||
| import { readCodexTurnId } from './codex-structured-thread-facts' | ||
|
|
||
| export type CodexBackgroundTaskFrame = | ||
|
|
@@ -15,24 +16,59 @@ export type CodexBackgroundTaskFrame = | |
| agentThreadId: string | ||
| label: string | null | ||
| parentTurnId: string | null | undefined | ||
| /** The reporting thread, for a `started` activity: the agent that spawned the child. */ | ||
| spawnerThreadId: string | undefined | ||
| } | ||
| | { | ||
| kind: 'turn' | ||
| threadId: string | ||
| turnId: string | ||
| state: NativeChatSubagentState | ||
| } | ||
| | { | ||
| /** A child turn that ended with no `turn/completed`. No `turnId`: the one it is running. */ | ||
| kind: 'turn-ended' | ||
| threadId: string | ||
| turnId: string | null | ||
| state: CodexChildTurnEnding | ||
| } | ||
|
|
||
| type CodexChildTurnEnding = Extract<NativeChatSubagentState, 'failed' | 'unverifiable'> | ||
|
|
||
| export type CodexBackgroundTaskEvent = { | ||
| method: string | ||
| threadId: string | ||
| params: unknown | ||
| } | ||
|
|
||
| /** | ||
| * The two ways Codex ends a child's turn without `turn/completed`. An `error` it will not retry is | ||
| * that turn's own end: the verdict the transcript settles the same turn on. A closed thread ran | ||
| * its last turn, and Codex never said how it went. A `systemError` status is neither: Codex raises | ||
| * it for errors that leave the turn running too (a refused steer), and a turn one ends also | ||
| * carries the `error`. | ||
| */ | ||
| function readCodexChildTurnEnding( | ||
| event: CodexBackgroundTaskEvent | ||
| ): CodexBackgroundTaskFrame | null { | ||
| if (readCodexProviderVerdict(event.method, event.params) === 'turn-failed') { | ||
| const turnId = readCodexTurnId(event.params) | ||
| return { kind: 'turn-ended', threadId: event.threadId, turnId, state: 'failed' } | ||
| } | ||
| return event.method === 'thread/closed' | ||
| ? { kind: 'turn-ended', threadId: event.threadId, turnId: null, state: 'unverifiable' } | ||
| : null | ||
|
Comment on lines
+58
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Technical details# Is a child's `thread/closed` reachable through Orca's connection?
## Affected sites
- `src/main/codex/codex-background-task-frames.ts:58-60` — the `thread/closed` → `turn-ended` (`unverifiable`) arm
- `src/main/codex/codex-subagent-executions.ts:93-103` — `endTurn` with a null `turnId` is reached only from this arm
## Evidence
- Codex emits `ThreadClosedNotification` from `unload_thread_without_subscribers`, which fires only when the thread's subscriber set is empty (codex-rs `app-server/src/request_processors/thread_lifecycle.rs`).
- Orca's connection is attached as a listener to every created thread (codex-rs `app-server/src/lib.rs` → `try_attach_thread_listener`), so a child's subscriber set stays non-empty while the session is held.
- Attribution itself is sound: `ThreadClosedNotification` carries a required `threadId` and is broadcast, and `readCodexThreadId(params)` resolves it.
## Open questions for the human
Can a child's `thread/closed` reach Orca's connection in any supported scenario (a second client unloading the thread, a session-end unsubscribe race)? If not, the arm is dead and the `unverifiable` ending it produces never fires. |
||
| } | ||
|
|
||
| export function readCodexBackgroundTaskFrame( | ||
| event: CodexBackgroundTaskEvent, | ||
| primaryThreadId: string | ||
| ): CodexBackgroundTaskFrame | null { | ||
| // The session's own turn ends through the journal's turn boundaries, never here. | ||
| const ending = event.threadId === primaryThreadId ? null : readCodexChildTurnEnding(event) | ||
| if (ending) { | ||
| return ending | ||
| } | ||
| if (event.method === 'turn/started' || event.method === 'turn/completed') { | ||
| const turnId = readCodexTurnId(event.params) | ||
| if (turnId === null) { | ||
|
|
@@ -67,6 +103,8 @@ export function readCodexBackgroundTaskFrame( | |
| parentTurnId: | ||
| activity.kind === 'started' || activity.kind === 'interacted' | ||
| ? readCodexTurnId(event.params) | ||
| : undefined | ||
| : undefined, | ||
| // Only `started` names the spawner: other kinds ride whichever agent acted. | ||
| spawnerThreadId: activity.kind === 'started' ? event.threadId : undefined | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.