Repository navigation
fix(program-status): keep a Pi row working while a pi-subagents child outlives the parent's done - #33738
Conversation
… outlives the parent's done OSC 7501 projected the root record's done straight onto the row even when live child records remained, so a Pi parent showed Done/IDLE while an async pi-subagents worker kept running. Fold child liveness with the existing foldMainAgentWithRowChildWork; mainAgent keeps the lead's own verdict so the row settles to done once the last child ends. Fixes #33657
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
There was a problem hiding this comment.
🧹 Nitpick comments: 1
src/shared/program-status/agent-status-projector.test.ts: 1
123-140:Trivial · Functional Correctness · Quick win Add the missing waiting-state assertion.
When the root is
doneand the child changes to a turn-scoped question, assert that the row becomeswaiting, whilemainAgent.stateremainsdoneand the child remains represented. The existing assertions already cover the live-child and final child-completion states.Suggested fix
expect(feed(osc('state=done:app=pi'))).toMatchObject([ { state: 'working', mainAgent: { state: 'done', outcome: 'success' }, subagents: [{ id: 'subagents/run1', state: 'working' }] } ]) + const [waiting] = feed( + osc('state=blocked:kind=question:id=subagents/run1:app=pi-subagents') + ) + expect(waiting).toMatchObject({ + state: 'waiting', + mainAgent: { state: 'done', outcome: 'success' }, + subagents: [{ id: 'subagents/run1', state: 'waiting' }] + }) const [settled] = feed(osc('state=done:id=subagents/run1:app=pi-subagents'))

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5d81dff5-3bea-4318-b6e0-93a13ac579a6
Files selected for processing: 2-
src/shared/program-status/agent-status-projector.test.tssrc/shared/program-status/agent-status-projector.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
-
…k verdicts authoritative - Stamp turnCompletedAt on the child-held row and its all-clear so the lead's done is announced once, when it happens, as hook rows do. - Hold only a finished (non-boundary) turn, only for working/waiting children; in-turn rows and failed/idle children keep the root's state. - A settled hook row is never reopened by a program's child-held working row, so the 2-minute silence fallback cannot flip done -> working -> done.
Children report only changes, so a pi-subagents that dies or hangs inside a live Pi would hold the row working until decay. The lease timer now settles a child-held row no report refreshed within AGENT_STATUS_STALE_AFTER_MS minus one renewal interval (20-30 min) to the lead's done, keeping turnCompletedAt so it is not announced again.
There was a problem hiding this comment.
Actionable comments posted: 2

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d4798e0c-8ad1-496d-b8a8-b2e5ec7088c6
Files selected for processing: 5-
src/main/agent-hooks/server/program-status/hook-precedence.test.tssrc/main/agent-hooks/server/program-status/hook-precedence.tssrc/main/runtime/terminal/output/terminal-derived-agent-facts.tssrc/shared/program-status/agent-status-projector.test.tssrc/shared/program-status/agent-status-projector.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
-
| // Why: the hook lane tracks its own children; a program's child roster must not reopen the hook's settled turn. | ||
| if ( | ||
| payload.state === previous.payload.state || | ||
| (previous.payload.state === 'done' && isAgentStatusHeldOpenByChildWork(payload)) |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
cat src/main/agent-hooks/server/program-status/hook-precedence.ts rg -n 'isAgentStatusHeldOpenByChildWork' src rg -n 'programStatusHookYieldEndsAt' src
Repository: stablyai/orca
Length of output: 8834
Script executed:
sed -n '1,80p' src/shared/agent-lead-status-fold.ts echo '-----' sed -n '1,140p' src/main/agent-hooks/server/program-status/hook-precedence.test.ts echo '-----' sed -n '190,235p' src/main/agent-hooks/server/server-ingest-terminal.ts echo '-----' sed -n '85,105p' src/shared/program-status/agent-status-projector.ts
Repository: stablyai/orca
Length of output: 10485
Let a child's waiting request reach the waiting branch after a done hook.
When the hook state is done, the new child-held condition returns Infinity for a child-held waiting payload. That check runs before the done to waiting branch, which can yield once the program reports work after the hook. The waiting state is therefore excluded from the hook-owned path, and the child's request cannot take precedence over the settled done hook. Limit the new condition to non-waiting child-held states, so child-held waiting uses the same intervening-work rule as an ordinary wait.
🐛 Suggested fix
-
--- "a/src/main/agent-hooks/server/program-status/hook-precedence.ts" +++ "b/src/main/agent-hooks/server/program-status/hook-precedence.ts" @@ -23,7 +23,9 @@ // Why: the hook lane tracks its own children; a program's child roster must not reopen the hook's settled turn. if ( payload.state === previous.payload.state || - (previous.payload.state === 'done' && isAgentStatusHeldOpenByChildWork(payload)) + (previous.payload.state === 'done' && + payload.state !== 'waiting' && + isAgentStatusHeldOpenByChildWork(payload)) ) { return Infinity }
Committable suggestion
-
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.Suggested change(previous.payload.state === 'done' && isAgentStatusHeldOpenByChildWork(payload)) (previous.payload.state === 'done' && payload.state !== 'waiting' && isAgentStatusHeldOpenByChildWork(payload))
| rootDoneHeldOpen ||= projection.state === 'done' && state !== 'done' | ||
| const payload: ParsedAgentStatusPayload = { | ||
| state: projection.state, | ||
| state, |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash # Inspect lifecycle writes, reads, and any root-change correction path. rg -n -C 5 \ -e 'recordAgentPromptLifecycleState\s*\(' \ -e 'mapExplicitAgentStateToRuntimeTerminalStatus\s*\(' \ -e 'rootChanges' \ src/main src/shared
Repository: stablyai/orca
Length of output: 17371
Script executed:
#!/bin/bash set -e printf '%s\n' '--- projector state construction ---' nl -ba src/shared/program-status/agent-status-projector.ts | sed -n '1,340p' printf '%s\n' '--- payload consumer ---' nl -ba src/main/runtime/terminal/output/terminal-derived-agent-facts.ts | sed -n '120,190p' printf '%s\n' '--- lifecycle recorder ---' nl -ba src/main/runtime/terminal/output/terminal-output-generation.ts | sed -n '1,90p' printf '%s\n' '--- lifecycle reads and wait implementation ---' rg -n -C 8 -F -e 'agentPromptLifecycleByPtyId' -e 'getTerminalInteractiveWait' -e 'lastAgentStatus' src/main/runtime printf '%s\n' '--- projector and terminal status tests around child-held behavior ---' rg -n -C 12 -e 'child' -e 'mainAgent' -e 'prompt lifecycle' -e 'terminal wait' src/shared/program-status src/main/runtime/terminal src/main/runtime/*wait* 2>/dev/null || true
Repository: stablyai/orca
Length of output: 45667
Script executed:
#!/bin/bash set -e printf '%s\n' '--- display lifecycle definition ---' rg -n -C 12 -F 'function getDisplayPromptLifecycle' src/main src/shared printf '%s\n' '--- interactive wait definition and callers ---' rg -n -C 20 -F 'getTerminalInteractiveWait' src/main printf '%s\n' '--- lifecycle sequence consumers ---' rg -n -C 12 -e 'workingSequence' -e 'getDisplayPromptLifecycle' src/main/runtime src/main | head -n 500 printf '%s\n' '--- focused tests ---' rg -n -C 15 -e 'workingSequence' -e 'recordAgentPromptLifecycleState' -e 'interactive wait' src/main/runtime --glob '*.test.ts' --glob '*.spec.ts' | head -n 500
Repository: stablyai/orca
Length of output: 42382
Script executed:
#!/bin/bash set -e printf '%s\n' '--- prompt activity and lifecycle consumers ---' rg -n -C 18 -e 'getAgentPromptActivity' -e 'workingSequence' -e 'AgentPromptActivity' src/main/runtime --glob '*.ts' | head -n 700 printf '%s\n' '--- terminal interactive wait implementation ---' rg -n -C 18 -e 'async getTerminalInteractiveWait' -e 'getTerminalInteractiveWait\(' src/main/runtime --glob '*.ts' | head -n 700 printf '%s\n' '--- payload type ---' rg -n -C 18 -F 'export type ParsedAgentStatusPayload' src/shared
Repository: stablyai/orca
Length of output: 42540
Record the root state for terminal prompt lifecycle.
When the root is done and a child is active, payload.state is working, but payload.mainAgent.state is done. The lifecycle recorder uses payload.state, so prompt-submission verification can treat child activity as a new root turn. Use the root state for lifecycle tracking and keep the aggregate state for row display.
Suggested fix
-
this.recordAgentPromptLifecycleState( ptyId, - mapExplicitAgentStateToRuntimeTerminalStatus(payload.state) + mapExplicitAgentStateToRuntimeTerminalStatus(payload.mainAgent?.state ?? payload.state) )
ELI5
When Pi starts a background worker through
pi-subagentsand then finishes its own reply, Orca marked the whole Pi row Done and put it in the dashboard's IDLE column, even though the worker was still running underneath it. Now the row stays working while a live child is running. It flips to done only when the last child ends. The parent's own "I finished successfully" verdict is still recorded the whole time.Root cause
The row the reporter captured (
programStatusset,mainAgent: {state: done, outcome: success}, childagentType: "pi-subagents") comes from the OSC 7501 program-status lane, not from the Pi hook extension:donewhen the parent run settles (pi-monopackages/coding-agent/src/modes/interactive/program-status-reporter.ts:36-69).pi-subagentsreports each async run as a separate child recordsubagents/<run>withapp=pi-subagentsand stateworkingwhile it runs ([email protected]src/integrations/program-status.js:3,30,36,87).createProgramStatusProjectorcopied the root's state straight onto the row (state: projection.state) and listed the live children next to it. Nothing folded child liveness into the row. So the projector emitteddonewith aworkingsubagent.The hook path was already correct for this flow: Orca's Pi extension holds
agent_enduntil its roster drains. In the real run below, noagent_endwas posted while the child was alive.What changed
src/shared/program-status/agent-status-projector.tsdoneis passed through the existingfoldMainAgentWithRowChildWork. Onlyworkingandwaitingchildren count. The row staysworkingwhile such a child runs, or showswaitingif a child asks the user a question. It returns todonewith the lead'ssuccess/failureonce the last child ends.mainAgentstill carries the root's own state, outcome, and clock.blockedin place),idlechildren, and idle/boundary roots keep exactly the root's state, as on main.turnCompletedAtset to the root's done time. This matches Claude hook rows: the lead's done is announced once, when it happens (terminal-agent-turn-news.ts,agent-completion-hook-observer.ts). It is not delayed until the children finish, and the all-clear is not announced a second time.src/main/agent-hooks/server/program-status/hook-precedence.tsdoneis never reopened by a program row that is only held open by its children. Without this, after 2 minutes of hook silence the fallback could flip the row done -> working -> done. In the real run the Pi hook lane sees the same pi-subagents children (viasubagent:async-started/async-complete) and holdsagent_enduntil they finish. So normally both lanes agree, and the guard covers cases where they diverge, such as a worker restored after a Pi restart that the hook roster never saw.Reproduction / verification (real Pi)
Isolated setup: temp HOME and
PI_CODING_AGENT_DIR,env -i, a local fake Anthropic server, and a local hook capture server. Nothing posted to a running Orca. Versions: Pi@earendil-works/[email protected]+[email protected]+ this branch's Orca Pi status extension. Pi ran in a real PTY (TUI). The parent calledsubagent({agent: "worker", async: true})and the fake model held the child's reply for 20s.Real Pi OSC 7501 output:
That raw PTY stream was replayed through the real main-side
createTerminalAgentStatusProcessor:state: done, mainAgent done/success, child workingstate: working, mainAgent done/success,turnCompletedAt= parent's done time, child workingstate: donestate: done, mainAgent done/success, sameturnCompletedAt(no second announcement)On main, the first row matches the reporter's
orca worktree pssnapshot exactly.Tests: projector regressions (held row + stamp + all-clear; narrowed scope) and a hook-precedence regression.
pnpm test src/shared/program-status/ src/main/agent-hooks/ src/renderer/src/components/terminal-pane/agent-completion*passes (171 files).pnpm tcandcheck:code-quality:changedare clean.pty-connection-command-finished-late-done.test.tshas 2 timeouts locally, identical on main.Risk and trade-offs vs main
Low to medium. The change only applies when an OSC 7501 root has finished and a child is still
working/waiting. With no such child, output is identical.waiting, for any OSC 7501 app. During a live turn nothing changes.done, its verdict wins over the program's child roster. A child the hook roster never saw (for example a worker restored after a Pi restart) still reads done, as on main.terminal-derived-agent-facts.ts, the lease timer now settles any child-held row that no report has refreshed withinAGENT_STATUS_STALE_AFTER_MSminus one renewal interval (between 20 and 30 minutes, before the row would decay). It settles to the lead's owndone, drops the unverified children, and keepsturnCompletedAt, so nothing is announced a second time. A later child report reopens the row from real evidence. pi-subagents also reconciles dead runners itself every 5s (async-job-tracker.js:22).Fixes #33657