Pi integration: track async subagent lifecycle for working/idle state #935
desideratum
started this conversation in
Ideas
Replies: 1 comment
|
I would like this as well. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
The Pi integration (
herdr-agent-state.ts, integration version 3) does not track async subagent lifecycle. When a Pi session dispatches an async subagent vianicobailon/pi-subagents(the most widely used Pi subagent package), the parent agent'sagent_endevent fires immediately after dispatch, causing herdr to transition the pane to idle — even though the async subagent is still executing in the background.Current behavior
The Pi integration hooks only Pi core lifecycle events:
agent_start,agent_end,session_start,session_shutdown, plus a customherdr:blockedevent. When the parent Pi agent finishes its turn after dispatching an async subagent,agent_endfires, and herdr shows the pane as idle (after the 250ms debounce). The async subagent runs in a detached child process with no corresponding events visible to the integration.Expected behavior
The pane should show as working while one or more async subagents are running, and transition to idle only when all async runs have completed (or failed/paused).
Available events
The
nicobailon/pi-subagentsextension already emits lifecycle events onpi.events:subagent:async-started— fired when an async run launchessubagent:async-complete— fired when an async run finishessubagent:control-event— fired on control state changes (e.g.,needs_attention)These are defined in
pi-subagents/src/shared/types.tsand consumed internally by pi-subagents' own async job tracker. They are available to any Pi extension that subscribes viapi.events.on().Suggested approach
The integration already uses a counter pattern for blocked state (
blockedCount). A similarasyncRunCountincremented onsubagent:async-startedand decremented onsubagent:async-completewould feed intodesiredState()to keep the pane in working while async runs are active. Thesubagent:control-eventcould optionally surfaceneeds_attentionas blocked.This mirrors the approach already taken for Claude Code (subagent hook events, #198) and OpenCode (subagent permission prompts as blocked, #838).
Environment
nicobailon/pi-subagents): v0.31.xAll reactions