Skip to content
This repository was archived by the owner on Oct 9, 2026. It is now read-only.
This repository was archived by the owner on Oct 9, 2026. It is now read-only.

Harden external-agent spawn graph and cancellation handling #85

Closed

Description

@shiny-code-bot

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_agent or 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_command backend 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-core tests 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_command lifecycle 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

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.

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_agent or 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_command backend 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-core tests 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

  1. added
    plan:donePlan completed or superseded
    and removed
    plan:activePlan is actionable now
    on Jun 14, 2026
  2. shiny-code-bot commented on Jun 14, 2026

    @shiny-code-bot
    CollaboratorAuthor

    Completed by PR #86.

    Evidence:

    • PR Harden external agent lifecycle #86 merged at commit 1c45e6d7fa5a5398802a681032c0efcf1e97eb00.
    • External-command children are persisted in the spawn graph before task launch.
    • External live-child traversal, close/cancel parent notification, pre-launch cancellation, and close-vs-shutdown persisted edge semantics are covered by focused tests.
    • CI for PR Harden external agent lifecycle #86 was green before merge: build-test, codespell, cargo-deny, macOS app build, and Codex exec harness all passed.

    Validation run before PR creation:

    • cargo fmt --all -- --check
    • cargo test -p codex-core pre_cancelled_external_agent_does_not_launch_subprocess --lib
    • cargo test -p codex-core multi_agent_v2_external_command --lib

    Read-only agent review was used before PR creation and caught two lifecycle semantic issues plus a repeat-close race; those were fixed before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    planDurable planning issueplan:donePlan completed or superseded

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions