Skip to content

feat(native-chat): Codex sessions write their subagents into the host status store - #22553

Merged
brennanb2025 merged 23 commits into
mainfrom
brennanb2025/c4-codex-producer
Sep 28, 2026
Merged

brennanb2025 merged 23 commits into
mainfrom
brennanb2025/c4-codex-producer

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1320 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1302
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​705 $\color{#cf222e}{\Huge{\mathbf{−}}}$​88 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​617

Scope

Codex native chat only: the structured chat that runs Codex through its app-server, behind the experimental structured native chat setting. Codex running in a terminal pane is unchanged; its subagent rows come from Codex's hooks, a separate lane.

ELI5

When a Codex chat starts a subagent, or runs a shell command, Orca now keeps one record for it on the machine that runs the chat. A subagent's record says whether it is working, which command it is running right now (for example Bash: npm test), whether it is waiting for your approval, what it said last, its token use, and how it ended (finished, failed, stopped, or ended with no reason given). A command's record exists only while the command's process is running, and goes away the moment it stops. The sidebar and the chat strip will read these records (#22565, #22614), so both show the same thing for Codex as they already do for Claude.

What Changed

What you see with this PR alone. Almost nothing on screen reads the new records yet. Three things in today's chat strip do change, all fixes:

  • A Codex subagent that dies on an error Codex will not retry, or whose thread closes, leaves the strip. Before, it could say "working" for the rest of the session.
  • A command you approved from an approval card is listed while it runs. Before, the strip never listed it, so a dev server you approved looked like nothing was running.
  • A command leaves the strip when its thread closes, or when you dismiss its approval card without answering. Before, a closed thread's command could stay listed for the rest of the session.

Once #22565 and #22614 land, a Codex subagent gets its own row in the sidebar and the strip, like CLI and Claude subagents: it shows its current command and approval waits, keeps a finished/failed row after it ends, reopens the same row as a second run on a follow-up, and the parent reads "monitoring background tasks" while a command it left running is still alive.

Mechanism. This PR adds the Codex producer for the per-child records #22536 introduced for Claude, reusing that PR's delivery path, ingest and reducer.

  • Subagents come from the child thread's own frames. A child's own turn/started opens a run; its own turn/completed settles it (completed→succeeded, interrupted→cancelled, failed→failed, else unknown). A non-retry error settles it failed; thread/closed settles it unknown; session end settles any still-live child unknown. A parent turn ending settles nothing, because Codex children routinely outlive the turn that spawned them. A follow-up turn on a finished child reopens the same record as generation 2. Current command, last message, tokens and waiting (from the child's own thread/status/changed flags) ride along.
  • Commands have one owner, the command tracker. It admits every agent commandExecution whatever source Codex tags it with, and ends it when its process exits, when its thread closes, when an approval the turn abandoned leaves it never-run, or when the session ends. The producer mirrors that owner one-to-one: a command is a live record from its start (owned by the subagent that launched it, or by nobody for the main agent) and is removed when it stops. A running shell is also its subagent's current command.
  • Shared reducer: a host-internal removed edge (never serialized or sent across a process), and no cap on settled children: the previous 32-per-session cap is gone, for Claude too. Settled subagent records stay until the host drops the session's row.
  • Abandoned approvals: Codex starts an approval-path command item before it asks, and never completes it if the question is withdrawn. The prompt registry, which already owns "was this approval answered", reports the approvals a turn dropped unanswered, and the tracker ends those commands on the same frame.
  • Host-internal contract change: a thread's run is named by a new alias kind turn_id (a task's run stays tool_use_id). Aliases are host memory only, so no wire negotiation is needed.

Why

Both providers have to write the same kind of record per subagent, so one piece of UI can show them the same way and the sidebar and strip cannot disagree. Without this PR, Claude chats get the new rows and Codex chats stay on today's one-line "working" display.

Why commands are keyed on the process, not on source. Current Codex runs every agent shell through unified exec, so every shell (even a 0 ms rg) arrives tagged unifiedExecStartup, and the approval path starts a command tagged agent and completes it tagged unifiedExecStartup. The tag says how Codex launched a command, not how long it lives, and Codex never says a command was left running. Two earlier versions of this PR read the tag as a lifetime and each produced a user-visible defect: a subagent never named its shell, and every quick shell became a kept "finished" record that pushed finished subagents out of the 32-record cap. Tracking every command from start to process exit in one owner removes that class: nothing reads the tag, "still running" is true from the start (so the parent never flickers to done at a turn end with a command still running), and every live command has a way to end.

Why finished commands are removed rather than kept. A finished command is history, which the transcript already shows. Keeping it as a status record adds nothing a user needs and crowds the records that do matter.

Alternatives considered:

  • Record a command only once it outlives its turn. Rejected: at the turn boundary the parent row is published before the command record exists, so the parent reads done for a moment with a dev server still running, and approved commands (tagged agent) were never tracked at all.
  • Record an approval-path command only once it is accepted. Rejected: Codex gives no process signal after Accept (it suppresses that start), automatically reviewed approvals have no Orca answer to hook, and telling a request from a real start at item/started would mean reading source again.
  • Settle children when the parent's turn ends. Rejected: Codex children keep working after the spawning turn ends; no turn-end edge is sent, and every Codex child is background residency, which the reducer's turn sweep never touches.
  • A Codex run counter of its own. Rejected: the child's turn id is the run handle; the reducer's existing run verdict resumes on a new one and fences a late frame from an old one.

Deviations, recorded:

  • A Codex child whose turn completed can take a follow-up; this PR records it as finished (succeeded) and reopens the same record as a new run, rather than modelling an idle, resumable child. Otherwise a Codex child could never show "finished".
  • A command waiting on an approval card is listed as a running command, because Codex has already started its item; the approval card beside it says it is waiting. If it is dismissed, the command is removed.
  • A process the agent fully detaches (&, nohup, a new session) is invisible to Codex too, so the chat reads done while it runs; nothing Orca receives can see it.

Merge order

#22532, #22520, #22521 and #22536 are merged. This PR merges next, then #22619 → #22565 → #22614.

Linked Issue

None — part of the structured chat status program.

Visual Proof

Live on a real Codex (codex-cli 0.157.1, multi-agent v2) in a background dev build on a separate Mac, with the host's records read in-process at every change. Final head: d514f6a1710; the approval and subagent-left-running shots are from the rounds that tested those paths (no code on those paths changed since).

A subagent runs a shell. Its record is live with Bash: /bin/zsh -lc 'sleep 20; echo CHILD_DONE' as its current command, and the shell is a live command record owned by it. At the process exit the command record is removed; the subagent then settles succeeded and stays.

M1-1-running.jpg
M1-2-finished.jpg

A follow-up to the finished subagent reopens the same record as generation 2 and settles it again.

M3-1-finished.jpg

The main agent leaves sleep 45 running and replies. The command record stays live past the turn end and the strip lists it; the parent never reads done while it runs. At the exit the record is removed and the parent goes done.

M2-1-after-turn-strip.jpg

A subagent leaves a command running after it finishes. The subagent settles succeeded; its command stays a live record it owns for the ~41 s it keeps running.

C4-1-subagent-settled-cmd-live.jpg

An approval dismissed before it is answered. While the card is up the command is a live record; after the turn is stopped it is removed, nothing ran, and the chat settles.

S2-1-approval-pending.jpg
S2-2-after-stop.jpg

Also verified live: 40 separate quick shells leave 0 command records and no finished subagent is dropped; an approved command stays live until it exits; closing a chat tab removes every record of that session; a plain turn makes no records; no renderer or main-process errors from this code.

Testing

  • pnpm run typecheck exit 0 at the final head; full oxlint on every changed file and check:code-quality:changed report 0 findings.

  • Vitest over src/main/codex, src/shared/agent-status*, src/main/runtime and src/main/claude (the real-CLI test excluded): 13,132 passed, 0 failed at 77bf4ca0657, the PR head before the last main merge. At the merged head the Codex, agent-status and runtime scope passes except one load-timing test (codex-session-index-heal-state) that passes when run alone and is untouched here.

  • 30 tests in 3 new files plus additions to the prompt-registry and reconciliation tests. Among them: a parity script through the real adapter that checks, at every journal write (not only at frame end), that the parent state folded from the records equals today's and never reads done while a command is live; every child ending (turn status, non-retry error, thread closed, session end); follow-up runs and late-ending fences; current command open/close including the approval path; a 0 ms shell and 40 shells leaving no command records; 100 settled subagents all kept; stop at an unanswered approval for the main agent and a subagent; an answered approval kept running past the turn; the runtime hop to the status sink under the session's own address.

  • Ablations: each removed mechanism turns tests red — source-tag admission restored (2), thread-close ending dropped (1), settle instead of remove (6), the 32 trim restored (1), records only at the turn boundary (7), the abandoned-approval hand-off dropped (1) or its registry recording dropped (2), the runtime wiring hop (1).

  • Platforms: unit tests on macOS; live QA on macOS. The code is platform-neutral and host-side (runs where the chat runs, including an SSH host).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Known, not fixed here:

  • The transcript still decides a command's lifetime from its source tag, so an approved dev server's transcript row reads "interrupted" at turn end while its record and the strip correctly show it running. Follow-up.
  • Claude's finished background commands still settle rather than disappear (Claude's own lane; unchanged here), and now stay until the row drops.
  • With no settled cap, one extremely long chat could in principle fill the store-wide 8,192-child limit; reaching it needs thousands of subagents in one session. How feat(native-chat): the chat strip and the sidebar read the host's child records #22614 bounds the rows it displays is its decision.
  • A command whose unanswered approval is evicted from the prompt registry's bounded maps stays live until session end; a guardian review interrupted past Codex's 100 ms grace window is unverified live.
  • Codex's thread/backgroundTerminals/list could later re-derive the live command set from Codex itself and make commands stoppable.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no new inputs cross a trust boundary; evidence is host-internal.
  • Cross-platform / SSH: host-side only; the records live on the host that runs the chat, and nothing new is sent to clients.
  • Mobile / backwards compatibility: the strip's published shape is unchanged; old paired clients see only the three strip fixes above.
  • Performance: one reducer batch per command start and per exit, the same count as today's strip republishes; about 55–160 µs per batch for 10–500 settled subagents in a session.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Two correctness gaps in the new producer's run fencing and lifecycle, both latent until the next PR starts reading the records.

Reviewed changes

This run reviewed the full 18-file diff at 1df7e358c0 (base brennanb2025/c3-claude-producer).

  • New Codex child-work producer (codex-child-work-evidence.ts, codex-child-work-translation.ts) — re-derives one child's whole observation per frame: open calls, last message, tokens, waiting, and the child's own turn/completed as the terminal edge. Decodes, shared reducer decides.
  • Tracker/command wiring (codex-background-task-tracker.ts, codex-background-command-tracker.ts) — observe now returns a started/ended command decision, adds threadTasks, and drains/publishes evidence via a session-bound sink.
  • Delivery ordering (adapter emit, handleCodexSessionExit, runtime) — evidence is delivered after the journal row and the legacy republish on every notification, and session-ended on every close path.
  • Contract change — new turn_id run-alias kind; a task runs under tool_use_id, a thread under turn_id; owner lookup still accepts only spawn calls. I traced this against the existing task path and the store's alias-key scoping and found it behavior-preserving there.
  • Tests — ran the three new files locally: 22/22 pass.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

...(lastMessage ? { lastMessage } : {}),
...(totalTokens !== undefined ? { totalTokens } : {})
}))
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the child's turn ends before its announcement, this branch emits only an ended edge and returns before requeueOwnedBy. The reducer can settle but never create from ended, so a child that started and finished before its subAgentActivity announcement gets no record at all, and any persistent command or nested child it launched stays ownerless.

Technical details
# A child that ends before its announcement is dropped

## Affected sites
- `src/main/codex/codex-child-work-evidence.ts:194-209` — ended branch emits `ended` and returns
- `:233-235` — `requeueOwnedBy` is reached only from the working branch
- `src/shared/agent-status-child-work-reconciliation.ts:49-51` — `applyEnded` returns when no record exists

## Required outcome
A child the producer has seen run a turn gets a record even if the turn ended before the announcement, and work it launched is re-announced with its owner.

## Suggested approach
On the first observation (`facts.published === undefined`) in the ended branch, emit a live edge (to admit the record) before the ended edge, and/or call `requeueOwnedBy` before returning.

## Open questions for the human
Is dropping such a child acceptable as matching today's strip, which never showed it? The PR body's "no record until the announcement lands" claim implies it should still land.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues in the delta — one lifecycle observation inline; the earlier run-fencing concern is fixed.

Reviewed changes

This run reviewed the two commits since the prior pullfrog review (1df7e358c0 → f098d8db9e) against the full 18-file diff (base brennanb2025/c3-claude-producer).

  • Run fence fixed for turn-less child item frames — record now falls back to the child's tracked turn and ofTurn is strict, so an open call or last message recorded under one run can no longer leak into the next.
  • A child turn now ends without turn/completed — a new turn-ended frame kind ends the child's turn on a non-retry error (→ failed) or a thread/closed (→ unverifiable) through a new CodexSubagentExecutions.endTurn, so the strip and the record settle on the same frame; a systemError status deliberately does not end a turn.
  • Tests — new evidence tests for each ending (error naming a turn / naming none / thread close), first-ending-wins, retried-error and systemError keeping the turn running, and a turn-less message never leaking into the next run; plus a LINTER child in the parity script that ends on a fatal error.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +58 to +60
return event.method === 'thread/closed'
? { kind: 'turn-ended', threadId: event.threadId, turnId: null, state: 'unverifiable' }
: null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread/closed may not be reachable while Orca holds the session. Codex emits it only from its "unload a thread with no subscribers" path, and Orca's connection is auto-subscribed to every thread it creates, including children — so a child's close may never notify us, leaving this arm defensive-only. Worth confirming with a live capture; if it cannot fire, a child whose only ending is a close still reads working until session end.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues in the delta — the only net-new commit is a test-only parity assertion that passes; nothing to change.

Reviewed changes

Compared 08ca92b26c against the prior run's head (8e22ed0ad2). The branch was rebased onto a newer base, so 11 of the 12 PR commits are SHA churn; the only commit with no counterpart at the prior head is 08ca92b26c. All production files are unchanged.

  • Journal↔record run numbering pinned — codex-structured-child-work-producer.test.ts now stamps each child agentMessage journal row and asserts the journal's run attempt equals the record's invocation.generation across the child's first three runs, including the case where Codex reports the child's first turn before the spawn that announces it. The assertion is exact, so it fails if either numbering diverges (e.g. an unstamped run-2 row reads attempt: 1 against generation: 2); the file's 4 tests pass at this head.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 force-pushed the brennanb2025/c3-claude-producer branch from eada18c to 503eb83 Compare September 24, 2026 23:28
@brennanb2025
brennanb2025 force-pushed the brennanb2025/c4-codex-producer branch from 08ca92b to 358d1a9 Compare September 24, 2026 23:36
@brennanb2025
brennanb2025 force-pushed the brennanb2025/c3-claude-producer branch from 503eb83 to fa71175 Compare September 25, 2026 04:50
@brennanb2025
brennanb2025 force-pushed the brennanb2025/c4-codex-producer branch 3 times, most recently from 36242df to bc928a2 Compare September 25, 2026 10:47

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No code issues in the delta — one stale note in the PR description.

Reviewed changes

This run reviewed the net-new commit bc928a2949 since the prior pullfrog review; the branch was also rebased onto a newer c3-claude-producer (94e5159f52), whose session-ended handling now settles live children instead of erasing them. No production logic changed.

  • Session-end assertions updated to settlement — codex-child-work-evidence.test.ts and codex-structured-child-work-producer.test.ts now assert a live child and its persistent command settle unknown when the session ends, and that already-ended children keep their recorded outcome. clear()'s doc comment was updated to match. All 28 tests in the three Codex child-work files pass at this head.
  • Runtime test comment — structured-codex-child-work-runtime.test.ts now describes a provider exit as reporting the session's end rather than taking its children with it.

ℹ️ The PR description still says a session's end removes the records

The body's frame table ends with "provider exit / close → session-ended → the session's records are removed", and the Decisions and deviations list repeats "Session end removes records instead of settling them". The base branch inverted that rule (35f97191b5, settleLive in agent-status-child-work-reconciliation.ts:93-99 now settles every live owned record unknown), and this delta's tests assert the new behavior. The description should be updated so the next reviewer and the #22614 cutover are not working from the old contract.

Technical details
# Stale session-end decision in the PR description

## Affected sites
- PR description, frame table last row: "provider exit / close | tracker cleared | `session-ended` | the session's records are removed"
- PR description, "Decisions and deviations": "**Session end removes records instead of settling them** (the same rule #22536 applies)."
- Actual behavior: `src/shared/agent-status-child-work-reconciliation.ts:93-99` — `settleLive` settles every live owned record `unknown` on `session-ended`; settled records are trimmed at `STRUCTURED_CHILD_WORK_MAX_SETTLED = 32`.

## Required outcome
The description matches the merged base behavior: session end settles a still-live child (and its owned commands) as `unknown`, and keeps an already-ended child's outcome, rather than erasing the session's records.

## Suggested approach
Update the two description spots to describe settlement. No code change is needed; this delta already pins the behavior.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…ods as a set

Behavior-neutral: the same two methods stamp receipt time. Keeps the file
under the size limit once the child-work sink lands.
… status store

A Codex child thread and each persistent command become host child records,
fed through the same delivery, ingest and reducer the Claude lane uses. The
child's own turn decides it: turn start is live, turn completion settles it
with the outcome Codex reports, and a follow-up turn reopens the same record
as a new run. Its open tool call, last message, usage and waiting-on-user flag
come from its own thread's frames. A parent turn ending settles nothing.
A completion frame need not restate the tool it ran, so reading the tool name
before closing left the call open and the record naming a finished tool.
… the host's records

Child turn start/end/follow-up, open tool call, last message, usage, waiting,
the persistent command a child owns and its monitoring display, a primary
turn end settling nothing, and session end. End to end through the real
adapter: evidence after the journal and the legacy republish, and the parent
state the records imply equals today's at every frame of a scripted session.
Through the production runtime: a Codex session's child work reaches the
status sink under its own address, and a provider exit ends it there.
…s generation

The journal numbers a Codex child's runs by the turns it observed on the
child's thread; the host record numbers them by the runs its evidence
opened. Both are keyed by the child's own turn id, so they must agree run for
run, including when Codex reports the child's first turn before the spawn
that announces it.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/c4-codex-producer branch from bc928a2 to 307537d Compare September 25, 2026 20:04
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/c3-claude-producer to main September 25, 2026 20:04
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e57048c1-585a-40d5-a953-006919f934e6

📥 Commits

Reviewing files that changed from the base of the PR and between 754da3a and d85668e.

📒 Files selected for processing (9)
  • src/main/codex/codex-background-command-tracker.ts
  • src/main/codex/codex-background-task-tracker.ts
  • src/main/codex/codex-child-work-evidence.test.ts
  • src/main/codex/codex-child-work-evidence.ts
  • src/main/codex/codex-child-work-translation.ts
  • src/main/codex/codex-structured-child-work-producer.test.ts
  • src/shared/agent-status-child-work-evidence.ts
  • src/shared/agent-status-child-work-reconciliation.test.ts
  • src/shared/agent-status-child-work-reconciliation.ts
💤 Files with no reviewable changes (1)
  • src/main/codex/codex-child-work-translation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The change adds Codex child-work evidence for child threads and background commands. It tracks thread and turn identity, activity, outcomes, waiting state, and ownership. Structured sessions publish evidence after notification processing and when a session exits. Shared alias resolution supports turn-based run identifiers. Tests cover evidence collection, reconciliation, producer ordering, and runtime delivery.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to d8566

A child that finishes before its announcement can be absent from the host status store, with its work left without the correct owner. Resolve this ordering case before merging unless that loss is explicitly acceptable.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to d8566

Codex subagent activity will become lasting status records rather than only a temporary working indicator. The records do not grant tool or approval authority, but their accuracy during interruption and recovery matters.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Malformed or misleading Codex activity could affect status records under its structured-session parent; the inspected admission and alias controls do not show a path to another parent's records.

Trust Boundaries and Controls

  • observed — This path publishes observational status, including waiting state and non-stoppable command records; the inspected producer and ingestion path does not invoke tool execution or approval mutation.

Resilience and Maintainability Implications

  • observed — Child turns have a run-ID fence and command tracking suppresses retained duplicate frames. Removal evidence has no equivalent command run ID, and waiting-status updates are not checked against a turn ID; recovery reuse and late-event ordering remain unresolved.

Hardening Proposals

  • proposed — Establish whether recovered Codex sessions can reuse a thread-and-item task ID while old evidence remains deliverable; if they can, give command removals a lifetime fence. Likewise, establish ordering for thread waiting-status notifications before relying on them across turns.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: writing Codex subagent records to the host status store.
Description check ✅ Passed The description is detailed and covers the required explanation, changes, rationale, testing, visual proof, scope, compatibility, performance, and checklist items. It states that no linked issue exist…
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…d keeps the ended ones

The host no longer erases a session's children when its provider goes away: a
child still running settles with an outcome nobody reported, and a child that
had already ended keeps what it said. The producer tests now expect exactly
that, from the close path and from an unexpected exit.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/c4-codex-producer branch from 307537d to e7239f1 Compare September 25, 2026 20:30
… process exits

Codex runs every agent shell through unified exec, so every subagent shell
arrives with the source the persistent-command tracker keys on. The producer
skipped those items, so a working subagent never named its shell, and an
approved command (started on the approval path, completed from unified exec)
stayed its open tool until the turn ended. The tracker still records the
process separately, so a command that outlives the turn reads as monitoring.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found in this delta.

Reviewed changes

This run reviewed the single net-new commit since the prior pullfrog run (b22661d8 → e930da150c); every other PR file is unchanged since that run.

  • A subagent's shell is now its open tool — CodexChildWorkEvidence.record stops filtering out commandExecution items whose source is unifiedExecStartup, so a running shell is reported as the child's operation (for example Bash: npm run dev) until its process exits, or until its turn ends (which clears open calls).
  • Tests updated to match — codex-child-work-evidence.test.ts gains a case for a unified-exec shell opening and closing the operation (24 tests now), and the parity script in codex-structured-child-work-producer.test.ts now expects a running dev server to be the child's open call.

I verified against the upstream openai/codex protocol that every agent-initiated shell goes through the unified-exec exec_command tool and is emitted with ExecCommandSource::UnifiedExecStartup (Agent is only the enum default used by synthetic items and tests). The removed filter was therefore a no-op against real Codex child frames, so this is a fix rather than a regression, and the repo's other codexCommandOutlivesTurn users are untouched. All 29 tests in the three child-work files pass at the head.

Approval is withheld only because the earlier thread on a child that ends before its announcement is still open and this commit does not touch it.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…ce it outlives its turn

Codex runs every agent shell through unified exec and never says when one is
left running, so the producer turned every shell, even a millisecond `rg`, into
a command record the moment it started. Each settled into the session's pool
of 32 settled records, so a busy turn evicted a finished subagent's record
(its outcome row would vanish) and listed dozens of finished shells beside it.

A command now becomes a record at the first turn boundary of the thread that
launched it while its process still runs: until then it is the agent's open
call. A shell that exits within its turn never becomes a record.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No code issues in the delta — the change is a correct fix; the PR description now describes the old command-recording timing.

Reviewed changes

This run reviewed the single net-new commit since the prior pullfrog review (e930da150c → 754da3a914); the other 18 PR files are unchanged.

  • A shell becomes a command record only once it outlives its turn — CodexBackgroundCommandTracker.observe stops reporting command starts (its type is now CodexBackgroundCommandExit, an exit only), and CodexChildWorkEvidence records the commands a thread still has running at each turn/turn-ended boundary via the new recordCommandsOf (codex-child-work-evidence.ts:155). A shell that starts and exits inside its turn now produces no command record and no ended edge; an exit only surfaces once the command was recorded.
  • Tests — codex-child-work-evidence.test.ts (25) and codex-structured-child-work-producer.test.ts (4) updated: a running dev server stays the child's open call until its turn ends, and 60 short shells across two turns leave the records untouched. All six child-work / command-tracker files pass locally (66 tests).

ℹ️ The PR description still says command records are created on item/started

Technical details
# Stale command-recording rows in the PR description

## Affected sites
- PR body, frame-table row for `commandExecution` with source `unifiedExecStartup`: says `item/started` yields a `live` kind `command` record. It is now recorded only at the thread's next `turn`/`turn-ended` boundary, and only if it outlived the turn.
- PR body, "Supporting changes": "`CodexBackgroundCommandTracker.observe` now returns the decision it made (started, or ended with the item)". `observe` now returns exits only (`CodexBackgroundCommandExit`).
- PR body, "Testing": "27 new tests in 3 new files … `codex-child-work-evidence.test.ts` (23)". Now 25 + 4 + 1 = 30.

## Required outcome
The description matches the merged behavior so the #22614 cutover reads the right contract: a command record is created at the turn boundary the command outlived, not on `item/started`.

## Open questions for the human
None — documentation only; the code and its tests are consistent.

One follow-on for #22614, not a change here: the main agent's own persistent command (primary thread) now gets its record only at the primary turn's end, whereas today's strip lists it immediately (commands.tasks only hides the commands of working child threads). The folded parent state is unaffected, but the raw row set can differ during a main-agent turn.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

… be removed outright

Settled child records now stay until the host drops the session's row; the
32-record trim is gone. A producer can say work stopped with nothing to
report, and its record (and the handles it answered to) goes instead of
settling. Evidence stays host-internal: the producer and the store share
one process.
…ts process stops

The command tracker is now the one owner of a Codex command's lifetime. It
admits every command whatever `source` Codex tags it with (the approval
path starts one as `agent`), and ends it when its process exits, when its
thread closes (Codex stops the processes first, so no exit ever arrives),
or when the session ends. The producer mirrors that one-to-one: a live
record from the start, removed when the command stops, never settled.

This removes the turn-boundary rule: a command that was only recorded at
its turn's end left the parent reading done for one publish when the main
agent's turn ended with a shell still running. The parity script now
checks the parent at every journal write, not only at frame end.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new command lifetime fixes the main-agent flash but introduces one regression: an approval-path commandExecution that a turn transition aborts leaves a command row that never clears. Details inline.

Reviewed changes

This run reviewed the two net-new commits since the prior pullfrog review (754da3a914 → d85668e995); the rest of the branch matches the previously reviewed state. The new test files pass locally (48 tests across the child-work, command-tracker and reconciliation suites).

  • A command is a record from its process start until it stops (d85668e995) — CodexBackgroundCommandTracker admits every commandExecution except unifiedExecInteraction, returns a started/ended change, ends a closed thread's commands (endThread) and returns the ended changes from clear(). The producer mirrors it one-to-one: a live record at start, and a new removed edge (record deleted, not settled) when the process stops. The earlier turn-boundary rule is gone, so a main agent whose turn ends with a shell still running no longer flashes done.
  • The per-session settled cap is removed (6b2e70c5ff) — STRUCTURED_CHILD_WORK_MAX_SETTLED/trimSettled are deleted and applyRemoved is added; settled children now stay until the parent row is dropped. This is shared reconciliation, so the Claude producer changes with it.
  • Tests — codex-child-work-evidence.test.ts (27), codex-structured-child-work-producer.test.ts (the parity script now folds the parent at every journal write, not only at frame end) and the runtime test were updated to the new lifetime.

ℹ️ The PR description still describes the previous command semantics

The frame table now contradicts the code on command endings: the commandExecution item/started row correctly says a live command record, but the "same command's item/completed" row still says the command settles (succeeded/failed/cancelled/unknown) — it is now removed, and codexCommandOutcome no longer exists. The final frame-table row still says records are removed "or at the 32-settled cap", which 6b2e70c5ff deleted, and the "Supporting changes" bullet still describes observe returning the old decision shape. The "Testing" counts (23/27) are stale too. Update these before #22614 reads the contract.

ℹ️ Removing the per-session settled cap changes shared behavior

6b2e70c5ff deletes STRUCTURED_CHILD_WORK_MAX_SETTLED = 32 and trimSettled from agent-status-child-work-reconciliation.ts, so a session's settled agent records are now bounded only by the store's aggregate limits (AGENT_STATUS_STORE_LIMITS: 8,192 children / 16 MB). Once that aggregate is reached the store refuses the mutation, and new live children in that session are rejected rather than admitted. The old cap kept per-session headroom and was careful never to drop a settled child that still owns live work; now the trim is gone entirely. This is deliberate per the commit message but shared with the Claude producer and not described in the PR body's "What Changed" — worth confirming the bound is intended.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…ever ran

Codex starts an approval's command item before it asks, and when the turn
ends with the question unanswered (the user stops at the approval), it drops
the question and never completes the item. The command tracker admitted that
start as a running process, so the strip kept a phantom command row and the
session row read working until the session ended.

The prompt registry, which owns which approvals are still unanswered, reports
the command approvals a turn ended without; the tracker ends those commands
with the frame that ended the turn. An answered approval keeps its command.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run reviewed the single net-new commit since the prior pullfrog review (d85668e995 → 77bf4ca065); the other 22 PR files are unchanged since that run.

  • An approval abandoned by a turn transition no longer strands a live command — CodexPromptRegistry now records the item's own unanswered command approval (an approvalId subcommand prompt is excluded) when a turn is cleared, and the adapter hands that list to the tracker, whose new endUnapproved ends the matching command. This closes the orphan flagged last run: an agent-source commandExecution whose approval the app-server drops on a turn transition used to show a running command row with no exit until thread close or session end. An answered approval is forgotten before turn end, so its command correctly stays live.
  • Tests — codex-prompt-registry-retention.test.ts pins that only an unanswered item-level command approval is reported (the approvalId prompt and a fileChange prompt are excluded, and a second drain is empty); codex-structured-child-work-producer.test.ts covers a child's and the primary agent's approval aborted at turn end, plus an answered approval whose command stays live past its turn. Verified locally at 77bf4ca065: 5/5 retention tests, 65/65 across the child-work, command-tracker and runtime suites, and pnpm tc:node exits 0.

Approval is withheld only because the two earlier open threads (a child that ends before its subAgentActivity announcement, and the live reachability of a child's thread/closed) remain open and this commit does not touch them.

The prior review's inline thread on the agent-source command orphan is resolved.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…e removed hold

Main no longer has host.hold: creating the session starts its child, and
nothing a viewer does keeps it running. The test attaches and asserts the
one child that attach started, then drives it as before.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status — ready for review

Head: d514f6a1710 (the PR merged with current main, including #22835).

Review loops. Five review passes, run until one came back clean, plus a separate architecture challenge once the same kind of defect turned up twice.

  • Loop 1 was clean at the previous head.
  • Loops 2 and 3 each found a real defect that came from reading Codex's source tag as a command's lifetime: a subagent never named its shell, and every quick shell became a kept "finished" record that pushed finished subagents out of the 32-record cap.
  • The architecture challenge replaced that approach. The command tracker now owns every command, whatever its tag, from start to process exit; commands are removed when they stop; the 32-record cap is gone. The PR body describes the final design.
  • Loop 4 found one defect in the new design (a command stranded after its approval card was dismissed unanswered) and fixed it using the prompt registry's own "was this answered" record.
  • Loop 5 came back clean. It compared that fix with tracking approval-path commands only after Accept, and kept the fix.

Live QA. Six rounds on a real Codex (0.157.1, multi-agent v2) in a background dev build on a separate Mac, reading the host's records at every change. All pass at the heads they tested; the final smoke run was at d514f6a1710. Covered:

  • A subagent shell: its current command while running; its command record removed at exit.
  • A follow-up reopening the same subagent record as run 2.
  • 40 quick shells leaving no command records and dropping no finished subagent.
  • Approved commands tracked while they run.
  • Commands left running past a turn, by the main agent and by a subagent, with the parent never reading done in between.
  • Stopping at an unanswered approval, for the main agent and a subagent.
  • Closing the tab removing every record of the session.
  • A plain turn making no records.

No renderer or main-process errors came from this code. Screenshots are in the PR body.

Readiness checklist. PASS at the start and at the end, with no P0 or P1 items.

CI. All checks green on d514f6a1710: 30 passed, 12 skipped. The Windows persistence job failed once in orcad-bun-launcher.integration.test.ts, which this PR does not touch, and passed on re-run.

For the reviewer to decide:

  • Pending approvals. While an approval card is up, main's strip lists that command as a running shell command, because Codex reports the item as started before it asks. The alternative (track it only after Accept) has no signal to use: Codex sends no start after Accept, and automatically reviewed approvals have no Orca answer.
  • Display bound for finished rows. With the settled cap removed, how many finished subagent rows the UI shows is feat(native-chat): the chat strip and the sidebar read the host's child records #22614's decision. The store-wide limit of 8,192 child records is not reachable in practice.

Follow-ups, not in this PR:

  • The transcript still reads the source tag, so an approved dev server's transcript row says "interrupted" at turn end while the strip and records correctly show it running.
  • Claude's finished background commands still settle instead of disappearing.
  • Re-derive the live command set from Codex's background-terminals API.
  • The raw codex item:collabAgentToolCall transcript row is fixed in feat(native-chat): register Codex default-mode helpers as subagents #22619.

…-producer

# Conflicts:
#	src/main/codex/codex-structured-session-state.ts
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[High risk] Codex sessions now write child-work records to the host status store.

The PR appears mergeable, but bounded-retention edge cases can leave child status stale or prevent later child records from being admitted.

Findings

  1. P2 Follow-ups lose their status ▶
  2. P2 Finished children exhaust shared capacity ▶

Summary

The PR adds host-side child-work records for structured Codex subagents and commands, including run outcomes, active operations, approval cleanup, and removal of finished commands.

  • The producer routes Codex frames through the existing child-work reconciliation path.
  • Follow-up handling after tracker eviction, bounded approval retention, and shared-store capacity need attention.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Codex[Codex app-server frames] --> Journal[Session journal]
  Journal --> Tracker[Command and subagent trackers]
  Tracker --> Evidence[Child-work evidence]
  Evidence --> Host[Host status reconciliation]
  Host --> Store[Shared status store]
Loading

Reviews (1) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

private queueChild(threadId: string): void {
const child = this.executions.find(threadId)
const facts = this.facts.get(threadId)
if (!child?.registered || !child.execution || !facts) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Follow-ups lose their status After more than 128 distinct subagents have been observed, the tracker can evict a finished child's registration. If that child receives a follow-up turn, Codex does not announce it again, and this check skips its evidence. The retained status record stays finished while the child works, and the new run is not recorded.

Knowledge Base Used: Agent workspaces and sessions

// own ending, or `unknown` when its session ends while it is still live. It owns only the records
// its own producer admitted, and never claims an outcome the evidence did not report.
// own ending, or `unknown` when its session ends while it is still live; work with nothing to
// report once it stops is removed instead. Settled children stay until the host drops the parent's

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Finished children exhaust shared capacity Settled agents now remain until their session's parent is removed. Because child, alias, and byte limits apply to the whole status store, a long-lived session can fill those limits and cause new child records—including records for other sessions—to be rejected. This makes retained history a risk to later status updates.

Knowledge Base Used: Agent workspaces and sessions

@greptile-apps

greptile-apps Bot commented Sep 28, 2026

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P2 Evicted approvals leave commands live src/main/codex/codex-prompt-registry.ts:245 ▶

    If a pending command approval is evicted from the bounded prompt registry before its turn ends, clearTurn cannot report that the approval was abandoned. A command already admitted at item/started then remains reported as live until its thread or session closes, even though its turn ended without approval.

@brennanb2025
brennanb2025 merged commit 153d3fd into main Sep 28, 2026
43 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
…ts own turn/completed (#23783)

* fix(native-chat): a Codex child's turn ends on its own turn/completed

#22553 ended a child thread's turn on an `error` Codex will not retry, reading
the verdict module #23682 deleted when it made turn/completed the only end of a
Codex turn. The two landed minutes apart with no textual conflict, so main no
longer typechecks.

Codex runs every thread's events, spawned children included, through the same
per-thread handler: a turn-ending error is recorded as the turn's last error and
the turn then completes as failed. So a child's failed turn/completed is its end,
as on the primary thread, and a closed thread stays the one child ending with no
completion.

* refactor(native-chat): a closed Codex child thread is its own frame

With a child's turn now ending only on its own turn/completed, the
turn-ended frame carried a fixed turnId (null) and state (unverifiable),
and endTurn took parameters nothing passed. Name the one remaining case:
a thread-closed frame, and closeThread ending the running turn as
unverifiable. Drop a test step that no longer exercised anything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant