Repository navigation
fix(pi): keep in-process subagent sessions from taking over the lead pane - #33595
Conversation
…pane Pi caches the extension factory per cwd, so pi-subagents children load Orca's status and titlebar extensions in the same process and share module state with the lead. A child's session_start overwrote the lead's session metadata (every later lead post carried the child id, so resume targeted the child), consumed the lead's completion generation (the lead's agent_end was never posted), and disposed the lead's titlebar registration (spinner froze). The Pi status gate now keeps the first session's SessionManager as the pane owner and only hands ownership to a lead runtime replacement (session_start reason new/resume/fork). The titlebar takes over only on a non-startup session_start when another registration already owns it. Fixes #31526 Co-authored-by: Yash Kakade <[email protected]> Co-authored-by: Brennan Benson <[email protected]>
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 1

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:
3813a0f3-5f56-4b11-bc29-526b4824d7d9
Files selected for processing: 5-
src/main/pi/agent-status-handler-source.tssrc/main/pi/omp-session-status-owner-source.tssrc/main/pi/omp-session-status-owner.test.tssrc/main/pi/titlebar-extension-lifetime-source.tssrc/main/pi/titlebar-extension-source.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
-
| ' if (!current) return true', | ||
| ' // Child transcripts cannot become the pane resume root, even when their callbacks arrive first.', | ||
| ' if (current.parent) return false', | ||
| ' if (omp && current.parent) return false', |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
sed -n '1,110p' src/main/pi/omp-session-status-owner-source.ts sed -n '125,180p' src/main/pi/agent-status-handler-source.ts
Repository: stablyai/orca
Length of output: 5290
Script executed:
set -o pipefail printf '%s\n' '--- status post definitions and uses ---' rg -n -F --glob '*.ts' -e 'function post' -e 'const post' -e 'post(' -e 'providerSession' -e 'session_start' src/main/pi src/main | head -240 printf '%s\n' '--- ownership tests and provenance references ---' sed -n '1,270p' src/main/pi/omp-session-status-owner.test.ts printf '%s\n' '--- generated status handler surrounding post setup ---' rg -n -F --glob '*.ts' -e 'resetPostQueue' -e 'post = ' -e 'post:' -e 'postStatus' src/main/pi
Repository: stablyai/orca
Length of output: 37068
Script executed:
set -o pipefail printf '%s\n' '--- post implementation ---' sed -n '150,285p' src/main/pi/agent-status-extension-source.ts printf '%s\n' '--- post transport and endpoint references ---' rg -n -F --glob '*.ts' -e 'hook_event_name' -e 'agent-status' -e 'agentStatus' -e 'status callback' -e 'session_file' src/main src/relay | head -260 printf '%s\n' '--- provenance and fork references ---' rg -n -F --glob '*.ts' -e 'parentSession' -e 'reason: "fork"' -e "reason: 'fork'" -e '--fork' src/main/pi src | head -220
Repository: stablyai/orca
Length of output: 41514
Allow OMP --fork lead sessions to publish status.
An OMP --fork lead has parentSession, so current.parent rejects its session_start and later callbacks before they call post. This drops the lead's in-memory pane status updates. Use task-child or launch provenance to distinguish task sessions from --fork leads; parentSession alone is not sufficient.
ELI5
In a Pi terminal pane, when Pi starts a helper (subagent) through
@tintinweb/pi-subagents, the helper took over the pane. The tab's resume target switched to the helper's conversation. The lead's turn never showed as finished. The title spinner froze. Now only the lead session reports for the pane./new,/resume,/forkand/reloadstill move it.Root cause
createAgentSessionwith its ownDefaultResourceLoaderand thensession.bindExtensions(...)(@tintinweb/[email protected]src/agent-runner.ts:1060-1124). The child'ssession_startuses the defaultreason: "startup"(pi-monopackages/coding-agent/src/core/agent-session.ts:509).packages/coding-agent/src/core/extensions/loader.ts:562-592, since v0.79.9). So the child runs Orca's status and titlebar extensions with the same module state as the lead.ownsSessionStatusreturnedtruefor every non-OMP callback. The child'ssession_startoverwrote the sharedsessionMetadata, so the lead's own later posts carried the child'ssession_id/session_file. The child'sagent_start/agent_endalso advanced the sharedlifecycleStategeneration, so the lead'sagent_endwas dropped as already posted.session_startreasonnew/resume/fork(pi-monopackages/coding-agent/src/core/agent-session-runtime.ts:218,251,305,326,345,397).#33572 (owner reclaims by session id) does not cover this. The lead's own hooks were already posting the child's id, and a new Pi lead posts no id until its first message is saved.
What changed
omp-session-status-owner-source.ts: forkind === 'pi', the existing process-global pane-owner map now also applies to the Pi runtime.session_startwith reasonnew/resume/fork, or when the session id matches.false.titlebar-extension-lifetime-source.ts: a registration takes the title over at itssession_startunless another registration already owns it and the reason isstartup, which is how a subagent starts.session_startwith no reason, so it keeps main's takeover behavior.How verified
Real Pi CLI in a PTY. Isolated HOME/
PI_CODING_AGENT_DIR, a fake OpenAI-compatible model server, a fake Orca hook receiver, and generated extensions from each tree. Pi@earendil-works/pi-coding-agent1.4.0 and 1.3.0, plus@tintinweb/pi-subagents0.22.0.Before (origin/main, Pi 1.4.0 and 1.3.0, foreground helper):
A background helper on main gave the same result: child posts, and the lead's wake-up turn posted with the child id.
After (this branch):
<lead>and ends withagent_end session_id=<lead>. The helper's transcript exists on disk but is never reported.<lead>./newmoves the pane to the new session./resumeback to the original lead works./forkmoves to the fork, and a helper spawned from the fork is ignored./reloadkeeps the lead./reloadand/new.Tests:
omp-session-status-owner.test.tsandtitlebar-extension-source.test.ts. Both fail on main and pass here.pnpm test src/main/pi: 486 passed.pnpm tc: clean.check:code-quality:changed: clean.Risk
session_start, it would win the first-start claim. No known flow does this.Fixes #31526
Supersedes #31739 and #32261 (smaller fix for the same Pi takeover). Credit to @ykakade and @brennanb2025 via Co-authored-by.
Note: OMP task children never emit a session start, so they no longer cancel the lead's title spinner when they load; they stay active alongside it without owning the title.