Skip to content

[Cross-Ref] Subagent Lifecycle — Cancel, Shutdown, and Session Management #3

@howardpen9

Description

@howardpen9

Pattern

Subagent (child agent) lifecycle management is broken across all CLIs — agents don't stop when cancelled, sessions leak, and inter-agent communication is limited.

Occurrences

Claude Code

  • #31469 — Plugin hooks not propagated to subagents
  • #31451 — Agent iTerm session not closed after shutdown
  • #31389 — Teammate ignores shutdown_request, loops indefinitely
  • #31439 — Can't distinguish subagent vs main agent in UI

OpenCode

  • #16311 — /fork is incredibly slow for long sessions
  • #16341 — No timestamps in subagent session picker

Kimi CLI

  • #1315 — Subagents keep running after hitting ESC
  • #1297 — Cancelling subagents displays errors
  • #1312 — Feature request: subagent sessions

Analysis

All CLIs struggle with the same subprocess lifecycle problem:

  1. Spawned agents don't respect cancellation signals
  2. No graceful shutdown protocol (just kill)
  3. Resource cleanup (temp files, connections) is missed
  4. Parent agent has no visibility into child agent state

Recommended Solution

  • Implement cooperative cancellation (signal → grace period → force kill)
  • Track child process PIDs and ensure cleanup on parent exit
  • Add agent state machine: SPAWNING → RUNNING → CANCELLING → STOPPED
  • Propagate hooks/permissions to child agents

Contribution Target

Kimi CLI — Fix #1315 (ESC doesn't stop subagents) with proper signal propagation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions