Repository navigation
Harden external-agent spawn graph and cancellation handling #85
Description
Finish Line
The external_command dogfood backend is lifecycle-safe enough to rely on during Codex Lab dogfood work: external children are tracked in the same spawn graph paths as internal children, cancellation cannot race into launching a subprocess after cancellation was already requested, and parent wait/mailbox flows receive a terminal notification when an external child is cancelled or closed.
Acceptance Criteria
- Persist external children in the spawn graph before the launch path can return control or enter a state where cancellation/parent lookup may race.
- External children are discoverable by the existing descendant/list/close paths that rely on spawn graph state.
- Cancelling or closing an external child sends the parent a terminal notification so
wait_for_agentor equivalent waiting flows do not hang. - Check cancellation immediately before launching the external subprocess, and do not start the subprocess when cancellation was already requested.
- Cover the regression cases with focused tests: external child appears in the spawn graph, close/cancel notifies the parent, and pre-launch cancellation prevents subprocess spawn.
- Keep scope on the PR Add external command agent dogfood path #82
external_commandbackend and existing MultiAgent V2 lifecycle paths; do not broaden into provider-agnostic worker redesign, streaming, resume/fork semantics, or Code Bridge. - Validate with focused
codex-coretests and a broader MultiAgent V2 regression command before merge.
Current Status
Created 2026-06-14 by Code after background Auto Review reported three target-applicable external-agent lifecycle findings on the PR #82 / #58 dogfood path:
- P1: external children are not persisted in the spawn graph before returning.
- P1: cancelling or closing an external child does not notify the parent path that waiting flows depend on.
- P2: cancellation can still race into launching the subprocess.
Implementation Notes
- The issue should fix the existing
external_commandlifecycle behavior, not reopen Implement native third-party agent dogfood path #58 or expand Provider-agnostic worker decision spike #2's provider strategy scope. - The spawn graph fix should preserve the internal-agent descendant/list/close semantics for external children and avoid orphaned external registry state.
- Parent notification should avoid double terminal messages while ensuring cancelled/closed external children still unblock waiting flows.
- Cancellation-before-launch tests should avoid process-leak flakiness by asserting deterministic terminal behavior rather than relying only on eventual process cleanup.
Relationships
- Child/follow-up under Validate Auto Review and third-party agents for dogfood MVP #53.
- Follow-up to Implement native third-party agent dogfood path #58 / PR Add external command agent dogfood path #82; Implement native third-party agent dogfood path #58 remains complete.
- Related to Provider-agnostic worker decision spike #2 only as later provider-worker evidence; this issue is not blocked by Provider-agnostic worker decision spike #2.
Relationships
Child/follow-up under #53.
Follow-up to #58 / PR #82; #58 remains complete.
Related to #2 only as later provider-worker evidence; this issue is not blocked by #2.
- related: Implement native third-party agent dogfood path #58 - Implement native third-party agent dogfood path #58
Finish Line
The external_command dogfood backend is lifecycle-safe enough to rely on during Codex Lab dogfood work: external children are tracked in the same spawn graph paths as internal children, cancellation cannot race into launching a subprocess after cancellation was already requested, and parent wait/mailbox flows receive a terminal notification when an external child is cancelled or closed.
Acceptance Criteria
- Persist external children in the spawn graph before the launch path can return control or enter a state where cancellation/parent lookup may race.
- External children are discoverable by the existing descendant/list/close paths that rely on spawn graph state.
- Cancelling or closing an external child sends the parent a terminal notification so
wait_for_agentor equivalent waiting flows do not hang. - Check cancellation immediately before launching the external subprocess, and do not start the subprocess when cancellation was already requested.
- Cover the regression cases with focused tests: external child appears in the spawn graph, close/cancel notifies the parent, and pre-launch cancellation prevents subprocess spawn.
- Keep scope on the PR Add external command agent dogfood path #82
external_commandbackend and existing MultiAgent V2 lifecycle paths; do not broaden into provider-agnostic worker redesign, streaming, resume/fork semantics, or Code Bridge. - Validate with focused
codex-coretests and a broader MultiAgent V2 regression command before merge.
Current Status
Created 2026-06-14 by Code after background Auto Review reported three target-applicable external-agent lifecycle findings on the PR #82 / #58 dogfood path:
- P1: external children are not persisted in the spawn graph before returning.
- P1: cancelling or closing an external child does not notify the parent path that waiting flows depend on.
- P2: cancellation can still race into launching the subprocess.
Agent planning review recommends keeping this issue narrow: fix the existing external_command lifecycle behavior, add focused regression tests, and do not reopen #58 or expand #2's provider strategy scope.
Implementation notes:
- The spawn graph fix should preserve the internal-agent descendant/list/close semantics for external children and avoid orphaned external registry state.
- Parent notification should avoid double terminal messages while ensuring cancelled/closed external children still unblock waiting flows.
- Cancellation-before-launch tests should avoid process-leak flakiness by asserting deterministic terminal behavior rather than relying only on eventual process cleanup.
Activity
shiny-code-bot commentedon Jun 14, 2026
Completed by PR #86.
Evidence:
1c45e6d7fa5a5398802a681032c0efcf1e97eb00.Validation run before PR creation:
cargo fmt --all -- --checkcargo test -p codex-core pre_cancelled_external_agent_does_not_launch_subprocess --libcargo test -p codex-core multi_agent_v2_external_command --libRead-only agent review was used before PR creation and caught two lifecycle semantic issues plus a repeat-close race; those were fixed before merge.