Skip to content

fix(codex): close a finished subagent's row before the parent turn ends - #461

Merged
makeitfutureDev merged 3 commits into
betafrom
fix/codex-child-completion
Dec 3, 2026
Merged

makeitfutureDev merged 3 commits into
betafrom
fix/codex-child-completion

Conversation

@makeitfutureDev

Copy link
Copy Markdown
Owner

Problem (SLK-203, Codex)

A Codex subagent that finishes while its sibling and the parent turn are still working keeps showing as running on the progress card until the parent turn closes. Live QA on beta saw two named child rows (file_one, file_two): the parent already reported file_two's result, but both rows kept spinning and the heartbeat said two subagents were running until the parent ended; then both closed together.

Cause:

  • src/engines/codex.js announceChildAgents opened a row once per child and then skipped that child for good (announcedChildren).
  • listCodexChildThreads (src/engines/codex-usage.js) returned identity only, no completion.
  • Every terminal child event, and the accounting, was emitted only inside the parent's close handler.
  • The Slack card already accepts separate terminal states per row (src/slack/progress.js agent()), so nothing there needs to change.

Fix (shared engine core, no chat-system branch)

  • listCodexChildThreads also returns each child's own lifecycle. A child counts as finished when its last task event after its own first task is a task_complete. That boundary is the one the accounting already uses, so the older task_complete in the copied parent history is ignored. A finished child also carries durationMs and tokens, computed by the same helpers the accounting uses (childOwnUsage, childDurationMs). Children the caller already closed (settledIds) are not read again.
  • The runner keeps a state per child (running | completed) and emits only changes. A finished child gets its terminal agent_activity event (same thread id, with elapsed time and tokens) as soon as its rollout shows it finished. Siblings keep running.
  • While any child is still running, the runner re-scans every 5 s (CG_CODEX_CHILD_POLL_MS). It has to: stdout says nothing when one child finishes while the parent waits on all of them. The timer is unref'd and cleared on close or error.
  • The parent-close pass skips rows already closed live. Billing still comes only from usageAccounting.children at parent close, so each child is billed exactly once.

Tests

  • New stub e2e: test/codex-message-to-reply-e2e.test.js, "a Codex child that finishes before its sibling and the parent closes its row live". New stub mode CODEX_STUB_STAGGERED_CHILDREN in test/fixtures/codex. child-b's row closes with 6,010 tokens while child-a and the parent are still live, and child-a stays running. Each child then has exactly one running event, one completed event and one billing row. Fails on the pre-fix runner (timed out waiting for child-b's own completion while the parent is live) and passes with the fix.
  • Adjusted the existing SLK-203 identity test. Its children have already finished at the first scan, so they now close straight from their rollouts. The test now checks that each row closes exactly once and is never reopened.
  • Touched/related suites: codex-message-to-reply-e2e, codex-usage-accounting, codex-completion, codex-args, codex-runtime-usage, slack-progress, progress-report, platform-run-details: 222/222 pass.
  • npm run check:static passed · npm run check:dco -- origin/beta..HEAD passed · npm run secret-scan clean.

Not executed

  • Live Codex acceptance (TEST-PLAN SLK-203 live case, updated): two children of clearly different length. The short child's row must stop spinning, with metrics, while the long one and the parent still run. Claude comparison in a Claude channel. This needs a deployment of this branch and an exact retest by the QA coordinator.
  • Not covered: a child closed live that the parent later hands more work does not reopen its row. Its billing is still correct.

🤖 Generated with Claude Code

tbiyss and others added 3 commits December 3, 2026 09:02
A Codex child that finished while its sibling and the parent were still
working kept its spinner until the parent closed. The live child scan
opened a row once and then skipped that child forever, and every
terminal row came from the parent-close accounting pass.

The live scan now also reads each child's own lifecycle from its rollout
(the last own task event after the copied parent history is a
task_complete) and emits the terminal event with its elapsed time and
tokens as soon as it appears. While any child is still running the
runner re-reads the rollouts every 5 s (CG_CODEX_CHILD_POLL_MS), because
stdout says nothing when one child of a parent waiting on all of them
finishes. The parent-close pass skips rows already closed live; billing
still comes only from that pass, so each child is accounted once, and
rows stay keyed on the child's thread id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tiberiu Socaci <tsocaci@makeitfuture.com>
Review of #461: a child closed live was never re-read, so a reused child kept
its first metrics (or a spinner a stdout collab item reopened). Re-read every
child each scan, emit on any change of state or final metrics, mark a child
reopened by a stdout collaboration item, and let the parent-close pass skip
only a child whose live close carries exactly its final metrics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tiberiu Socaci <tsocaci@makeitfuture.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tiberiu Socaci <tsocaci@makeitfuture.com>
@makeitfutureDev
makeitfutureDev merged commit ab4bd78 into beta Dec 3, 2026
5 checks passed
@makeitfutureDev
makeitfutureDev deleted the fix/codex-child-completion branch December 3, 2026 08:06
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.

2 participants