Files
ai-artifacts/projects/dotfiles/047-pi-subagents-lifecycle-controls-task.md

2.1 KiB

status, claimed-by, claimed-at, completed-at, parent, blocked-by, tags
status claimed-by claimed-at completed-at parent blocked-by tags
resolved 019fba91-eabf-76ae-b086-a37ac061d6e8 2026-08-01T14:05:41-04:00 2026-08-01T14:13:54-04:00 027-pi-subagents-implementation-spec-task
046-pi-subagents-minimal-tracer-bullet-task
ticket/task/afk

Add cancellation, timeout, and shutdown lifecycle controls

Question

Extend the supervisor so cancellation, timeouts, process failures, and parent shutdown cleanup use the same tracked lifecycle path without leaking child processes.

What to build

Make child lifecycle robust after the minimal spawn path exists. The supervisor should own cancellation, startup and runtime timeout behavior, process failure handling, and shutdown cleanup. Cancellation must be idempotent and should cooperate with Pi RPC before escalating to process-tree termination.

Acceptance criteria

  • Cancelling a running subagent is idempotent and reaches cancelled.
  • Startup and runtime timeout paths reach timed_out.
  • Child process exit before semantic settlement reaches a failure state with diagnostics.
  • Parent session shutdown cancels supervised children.
  • Lifecycle tests cover abort, process close, timeout, and repeated cancel calls.

Implementation Notes

Use agent_settled as semantic completion. Use process close for resource cleanup after settlement.

Resolved in branch pi-subagents-tracer-bullet, commit 4e6baed. Cancellation is idempotent, sends RPC abort cooperatively with a bounded grace period, then terminates the child process group on Unix. The supervisor now tracks startup and runtime timers, clears timers on terminal states, marks shutdown cancellation as cancelled, and ignores later lifecycle events once a terminal state is reached. Lifecycle unit tests cover repeated cancel, startup timeout, runtime timeout, process failure, shutdown cleanup, and cancel-after-completion. Verification: nix shell nixpkgs#tsx -c tsx --test modules/agents/pi/extensions/subagents/supervisor.test.ts, managed extension derivation build, Pi RPC command smoke, live repeated cancel smoke, and nix flake check.