Skip to content

feat: cancel sub-agents on channel close and shutdown signal in scheduler loop #1613

@bug-ops

Description

@bug-ops

Context

The run_scheduler_loop() tokio::select! introduced in #1603 has two branches that break out of the loop without canceling running sub-agents:

  1. Ok(None) | Err(_) — channel closed
  2. shutdown_signal() fired

Both exit with GraphStatus::Failed but do not call scheduler.cancel_all() or forward Cancel actions to subagent_manager. Sub-agents spawned as tokio tasks will continue running until they complete naturally or timeout, wasting resources.

Impact

Low for MVP — graceful shutdown already handles process exit, and channel close is uncommon during plan execution. However, long-running sub-agent tasks (multi-step tool loops) could consume significant resources after the scheduler loop exits.

Acceptance criteria

In the channel-close and shutdown branches of run_scheduler_loop():

  • Call scheduler.cancel_all() and process the returned Cancel actions via subagent_manager.cancel()
  • Add a log warning indicating abnormal exit with sub-agent count

Labels

enhancement, robustness

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions