Repository navigation
feat: switch on dying sub-agents - #11477
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2fcaf9e89
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Document the shutdown intent model in App when agent threads close. Clarify the difference between thread-switch shutdown suppression and app-exit shutdown tracking, and document the event-ordering invariants that prevent unintended failover during user-requested exit.
|
[codex-generated] Documentation pass follow-up for shutdown/failover clarity in
Validation run:
|
|
[codex-generated] Updated PR Description (Ready To Paste)ProblemWhen a sub-agent thread emits Mental modelThe app has one primary thread and one active thread. A non-primary active thread shutting down Non-goalsNo change to thread lifecycle, thread-manager ownership, or shutdown protocol wire format. TradeoffsThis adds a small local marker ( Architecture
ObservabilityUser-facing info/error messages continue to indicate whether failover to the main thread succeeded. TestsAdded targeted tests for Validated with:
|
[codex-generated]
Updated PR Description (Ready To Paste)
Problem
When a sub-agent thread emits
ShutdownComplete, the TUI switches back to the primary thread.That was also happening for user-requested exits (for example
Ctrl+C), which could prevent aclean app exit and unexpectedly resurrect the main thread.
Mental model
The app has one primary thread and one active thread. A non-primary active thread shutting down
usually means "agent died, fail back to primary," but during
ExitMode::ShutdownFirstshutdownmeans "the user is exiting," not "recover this session."
Non-goals
No change to thread lifecycle, thread-manager ownership, or shutdown protocol wire format.
No behavioral changes to non-shutdown events.
Tradeoffs
This adds a small local marker (
pending_shutdown_exit_thread_id) instead of inferring intentfrom event timing. It is deterministic and simple, but relies on correctly setting and clearing
that marker around exit.
Architecture
Apptracks which thread is intentionally being shut down for exit.active_non_primary_shutdown_targetcentralizes failover eligibility forShutdownCompleteandskips failover when shutdown matches the pending-exit thread.
handle_active_thread_eventhandles non-primary failover before generic forwarding and clears thepending-exit marker only when the matching active thread completes shutdown.
Observability
User-facing info/error messages continue to indicate whether failover to the main thread succeeded.
The shutdown-intent path is now explicitly documented inline for easier debugging.
Tests
Added targeted tests for
active_non_primary_shutdown_targetcovering non-shutdown events,primary-thread shutdown, non-primary shutdown failover, pending exit on active thread (no failover),
and pending exit for another thread (still failover).
Validated with:
cargo test -p codex-tui(pass)