Repository navigation
fix(agent-status): keep Pi's background subagent rows on paired clients after the reply ends - #44375
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
…n the lead's done lands after its hook Pi ends its reply (OSC 7501 root done) while async subagents still run, and the Pi extension withholds agent_end until they finish. The session-tab projection read that idle activity as a newer turn end whenever the last hook post landed first, and published a title-only Done with no subagents, so paired clients lost the children. An idle lead no longer retires a row whose own live children hold the turn open. Fixes #39120
c9476fa to
95722f0
Compare
ELI5
When Pi starts background subagents and then finishes its own reply, the host still knows the work is running. A paired desktop or phone could still show the parent as Done with no child rows. Now the paired client shows the parent as working, with its child rows, until the children finish.
What Changed
Before: on a paired client, a Pi pane that ended its reply while async subagents (plain
asyncruns or workflow children) were still running showed a green Done with no child rows. On the host,orca worktree psshowed the pane working with every child listed.The cause is in the host's session-tab projection, the status paired clients receive. When Pi ends its reply it writes its OSC 7501 root record as
done, so the PTY's activity becomes idle. Orca's Pi status extension holdsagent_endback while children run, so the hook row staysworkingand lists the subagents. The projection (workingHookOwnsIdleTitleInterval) kept a working row under an idle title only if the row was observed after the title went idle. Pi's last hook post and its 7501donearrive within a millisecond of each other. When the hook landed first (1 ms earlier in the reporter's Linux host data), the projection decided the idle title had ended the turn. It then published a title-onlydonethat carries nosubagents.After: an idle lead no longer retires a fresh, non-restored working row whose own subagent roster still has live work. It uses the same lead/child fold the hook server already applies (
foldMainAgentWithRowChildWork), and the generation fence the Codex exception next to it uses. Shell titles (the agent exited), restored rows and stale rows (30 min) still demote as before. Both routes are covered: the headless-serve builder (resolveRuntimeHookLiveAgentRow) and the renderer-published tab (renewRuntimeMobileAgentStatusFromPtyTitle). Both call this one predicate.Why
The reporter's first theory, a missing
subagent:child-statussubscription in the roster source, was ruled out by their own live trace: the host's hook store had every child. I checked the client side too. Pi sends no OSC 9999, so a paired renderer never takes ownership of the row and only mirrors what the host sends. The loss is entirely in the host projection, and only that route compares a hook row against the title.Alternatives considered:
workingwhile child records live (the reporter's first suggestion). That changes the PTY's idle fact for every consumer: mailbox delivery, tui-idle waits, idle notifications. The lead really is at rest. It would also only cover children that pi-subagents reports over 7501, not the other producers in Orca's roster.mainAgent: done). That post would land at the same moment as the 7501doneand hit the same race.Folding the row's own roster at the one place that compares hook against title fixes every producer and both routes. The client still shows only what the host says.
Closed PR #39564 was about native chat background workers and was replaced by #42448. It does not touch this terminal path, so nothing was reused from it.
Linked Issue
Fixes #39120
Visual Proof
N/A for a screen recording: the bug depends on which of two reports reaches the host first. Locally on macOS the hook landed after the PTY's done, so the client looked right even before the fix. Payload evidence instead:
session.tabsagentStatus for the pane:{ state: 'done', prompt: '', ... }(nosubagents), on both the headless and the published route{ state: 'working', subagents: [child-a, child-b], ... }orca servewith real Pi + pi-subagents (async workers, fake local model).session.tabs.listandworktree.psagreed throughout: working with both children while they ran, thendonewith no children once they finished.Testing
Reproduced first with a real Pi 1.5.2 + pi-subagents 0.89.0 run in a headless
orca servebuilt from this branch. I captured the exact OSC 7501 sequence (state=working:app=pi, twoapp=pi-subagentschild records,state=done:app=pi) and the Pi hook row (working+subagents, nomainAgent).Added a regression test on the real
OrcaRuntimeServicesession-tab projection (headless and renderer-published routes). Both fail on main with the title-onlydoneand pass with the fix.After the fix, ran a live end-to-end check on the same serve: rows stayed working with children while they ran, then settled to done.
Ran the dependent test files (session-tab projection, terminal waits, process listing, hook-server presence/interrupt tests): 17 files, 85 tests, all pass.
pnpm tc:nodepasses;pnpm check:changedpasses all 27 checks on the rebased head.Platform: macOS host. Linux behaves the same; this path has no platform branches.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The riskiest part is a working row being held under an idle title when its roster is stale. For example, a child that died without reporting would keep the row working on paired clients. That matches what the host's hook store and
orca worktree psalready show, and it still ends at the 30-minute stale window, a shell title, a restore or a PTY generation reset. No wire, schema or persistence change, so older clients and hosts are unaffected. A plain revert backs it out.Performance: the check runs on the session-tab projection, the status-sync hot path. It is evaluated only after the cheaper conditions have already failed: a working row, an idle PTY, no shell title, and an observed-at check that came out false. It then walks the row's existing subagent array once. No new polling, timers, RPCs or extra publishes. The published payload is the host's own row, the same one sent today whenever the hook wins the race.
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Mobile and paired desktop clients both read this projection, so both get the fix. SSH and local panes go through the same projection. Folder workspaces are unaffected.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)