Repository navigation
fix(pi): stop pi-subagents workflows from pinning a pane on working - #22533
Conversation
Awaited workflow children announce subagent:async-started but never get a subagent:async-complete, so the stablyai#21882 roster kept their ids forever and suppressed every later agent_end. Treat subagent:process-terminal (the runner exiting) as the end signal for tracked runs, with a short grace so runs that report their own completion keep settling through that path. Also accept completion events that carry only runId. Fixes stablyai#22527
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe agent status handler now emits subagent roster setup and event-handling code from dedicated source generators. The roster tracks active and exited child IDs, listens for runner-terminal events, and uses a 2,000 ms grace check before attempting settlement after a runner exit. Session shutdown and switch clear exited IDs. New tests cover completion ordering, untracked runs, runId-only completion events, and reload behavior. Merge Risk: ⚪ Minimal · up to Pi panes now return to done after pi-subagents workflows whose awaited children finish, while explicitly async children that outlive their workflow still keep the pane working. The added tests cover completion ordering and reload behavior. No outstanding merge-blocking risk was identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Pi subagent roster extraction — the
pi.events-hostedlifecycleStateroster and itsonEventhandler moved fromagent-status-handler-source.tsinto the newagent-status-subagent-roster-source.ts(getPiSubagentRosterSetupSourceLines/getPiSubagentRosterEventSourceLines); the move is behavior-preserving and the setup/event split keeps both files under the size limit. - Process-exit liveness signal — the generated extension now listens for
subagent:process-terminaland records the affected run in a newlifecycleState.exitedset;postAgentEndOnce()prunesexitedids fromactivebefore deciding whether children still hold the pane, so awaited workflow children that never emitsubagent:async-completeno longer pin the pane. - Bounded grace for self-reporting runs — a single shared, unref'd 2s
RUNNER_EXIT_GRACE_MStimer is armed (and rescheduled per exit) only whilewaiting, so a run that reports its own completion ~150ms after exit, plus the wake turn it triggers, still settles first. runId-only completions —onEventnow falls back torunIdwhenidis absent, matching pi-subagents' ownid ?? runIdresolution (itsresult-watcheremits{...data, runId}, wheredata.idcan be missing).- Reload/reset handling — a separate
runnerExitListenerguard lets a roster object created by an older in-process build still subscribe;exitedis cleared onsession_shutdown/session_switch; the field is optional so an older-build roster still works. - Tests — new
agent-status-extension-async-subagents.test.tsreplays recorded event orderings (awaited background/foreground workflows, late child exit,async: truechild outliving its workflow, untracked/interleaved exits,runId-only completion, reload).
I verified the load-bearing external contract against the published [email protected] tarball: subagent:process-terminal carries runId, is emitted only from the runner's proc.once('close') handler (so even a proof with state: "unknown" still means the process closed), and foreground workflows route through async-execution.js's executeAsyncSingle/executeAsyncChain, so their children emit both async-started and process-terminal. I also ran the touched suites plus the two sibling extension suites (22 passed), and traced the reported event ordering — the awaited-child case settles whether child exits land before or after the workflow completion.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When Pi hands work to a pi-subagents workflow, Orca keeps the pane "working" until every helper it saw start has finished. Helpers inside a workflow never say they are finished; only the workflow does. So Orca waited for them forever, and the pane stayed "working" even after later prompts. Now Orca also counts a helper as finished when its process exits.
What Changed
Before: once Pi ran a
subagentworkflow script, the pane stayed "working" for as long as that Pi process lived. New prompts ran and finished, but the pane never went back to done, and/reloaddidn't help. #22527 describes a remote host where one pane stayed stuck for more than two hours.After: the pane goes to done when the turn after the workflow finishes, the same as it does for a single background subagent. A child started with
async: truethat keeps running after its workflow ends still holds the pane on "working" until it finishes.How it works: the change is in the generated Pi status extension. The roster code moved out of
agent-status-handler-source.tsintoagent-status-subagent-roster-source.tsto keep that file under the size limit.subagent:async-startedadds an id,subagent:async-completeremoves it, andagent_endis held back while the list has anything in it.async, pi-subagents runs it as an "awaited" background run. It sendssubagent:async-startedwithparentWorkflowRunId, but its result goes straight to the workflow. Nosubagent:async-completeis ever sent for it; only the workflow's own id completes. Foreground (async: false) workflows have the same gap.subagent:process-terminal, which pi-subagents sends when a run's process exits. Before deciding whether children still hold the pane, it removes any tracked run whose process has exited.runIdare now accepted too. pi-subagents' own status bridge readsrunId ?? id.Why
parentWorkflowRunId. The traces show that children launched withasync: truecarry that field too and can outlive their workflow, so ignoring them would bring Pi appears finished while async pi-subagents are still running #18031 back for that case./reload, which is why fix(pi): keep panes working while async subagents run #21882 left plain Pi's list alone at those boundaries.Linked Issue
Fixes #22527
Follow-up to #21882 (#18031).
Visual Proof
N/A: this changes when the status extension reports completion. Nothing in the interface changes. Recorded before and after results from real runs are under Testing.
Testing
agent-status-extension-async-subagents.test.tsreplays event orders recorded from real pi-subagents 0.71.0 runs:async: truechild that outlives its workflow (must stay working, with no early done)runIdSix of the eight fail on main. The two regression guards pass on both.
End to end on Linux, I ran Pi 0.87.1 in RPC mode with pi-subagents 0.71.0 and the generated extension posting to a local test listener. The workflows had two
delegatechildren each. Last status posted:agent_start(stuck)agent_endagent_start(stuck)agent_endasync: truechild running 45 s after the workflow endedagent_endpnpm tc,pnpm test src/main/pi/(265 passed) andpnpm run check:code-quality:changedpass.wsl-hook-relay-manager.test.tshas one failure on this host, and it fails the same way on unmodified main.AI Disclosure
Written with Claude Opus 5.5 in the pi coding agent, reviewed by me.
Review
agent_endand thenagent_starta few milliseconds apart. I recorded the same thing on main; Keep Pi active while async subagents run #18032 addresses it.subagent:async-started, so it was never tracked, and that hasn't changed. If a run process exits while Pi is in the middle of a/reload, pi-subagents can drop the exit event. That run then waits for its own completion event, as it does today.subagent:process-terminalbehave exactly as they do today.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security: the extension only reads run ids from these events, and nothing new leaves the host. Cross-platform: pi-subagents sends the exit event from the process
closehandler on every platform, and the grace timer is unref'd. Remote/SSH/WSL: SSH and WSL hosts get the same generated extension, and it posts the same hook events as before, so mixed client and server versions are unaffected. Mobile: no change. Performance: one more listener and at most one pending 2 s timer.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)