Repository navigation
fix(codex): close a finished subagent's row before the parent turn ends - #461
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 reportedfile_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.jsannounceChildAgentsopened a row once per child and then skipped that child for good (announcedChildren).listCodexChildThreads(src/engines/codex-usage.js) returned identity only, no completion.closehandler.src/slack/progress.jsagent()), so nothing there needs to change.Fix (shared engine core, no chat-system branch)
listCodexChildThreadsalso returns each child's own lifecycle. A child counts as finished when its last task event after its own first task is atask_complete. That boundary is the one the accounting already uses, so the oldertask_completein the copied parent history is ignored. A finished child also carriesdurationMsandtokens, computed by the same helpers the accounting uses (childOwnUsage,childDurationMs). Children the caller already closed (settledIds) are not read again.running|completed) and emits only changes. A finished child gets its terminalagent_activityevent (same thread id, with elapsed time and tokens) as soon as its rollout shows it finished. Siblings keep running.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.usageAccounting.childrenat parent close, so each child is billed exactly once.Tests
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 modeCODEX_STUB_STAGGERED_CHILDRENintest/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.npm run check:staticpassed ·npm run check:dco -- origin/beta..HEADpassed ·npm run secret-scanclean.Not executed
🤖 Generated with Claude Code