Skip to content

fix(pi): keep in-process subagent sessions from taking over the lead pane - #33595

Merged
nwparker merged 1 commit into
mainfrom
nwparker/agint-pi-helper-pane-ownership
Oct 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/agint-pi-helper-pane-ownership

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

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, /fork and /reload still move it.

Root cause

  • pi-subagents runs children in-process. It calls createAgentSession with its own DefaultResourceLoader and then session.bindExtensions(...) (@tintinweb/[email protected] src/agent-runner.ts:1060-1124). The child's session_start uses the default reason: "startup" (pi-mono packages/coding-agent/src/core/agent-session.ts:509).
  • Pi caches extension factories per cwd (pi-mono 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.
  • Status: on main, Pi's ownsSessionStatus returned true for every non-OMP callback. The child's session_start overwrote the shared sessionMetadata, so the lead's own later posts carried the child's session_id/session_file. The child's agent_start/agent_end also advanced the shared lifecycleState generation, so the lead's agent_end was dropped as already posted.
  • Title: the titlebar factory disposed the current pane owner whenever it ran. The child's registration therefore killed the lead's spinner.
  • Only the lead runtime replaces its SessionManager, and it always does so with session_start reason new/resume/fork (pi-mono packages/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: for kind === 'pi', the existing process-global pane-owner map now also applies to the Pi runtime.
    • The first session's SessionManager owns the pane.
    • Ownership moves only on a session_start with reason new/resume/fork, or when the session id matches.
    • Every other callback from a different SessionManager is ignored before it can touch metadata.
    • OMP behavior is unchanged. The removed path-nesting branch was unreachable because every branch returned false.
  • titlebar-extension-lifetime-source.ts: a registration takes the title over at its session_start unless another registration already owns it and the reason is startup, which is how a subagent starts.
    • The first registration still claims the title at load.
    • OMP sends session_start with 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-agent 1.4.0 and 1.3.0, plus @tintinweb/pi-subagents 0.22.0.

Before (origin/main, Pi 1.4.0 and 1.3.0, foreground helper):

agent_start   session_id=<lead>
tool_call     session_id=<lead>
session_start session_id=-          <- child
agent_start   session_id=<child>
message_end   session_id=<child>    "child done"
tool_execution_end session_id=<child>   <- lead's own event
message_end   session_id=<child>    "lead done"  <- lead's own reply
(no agent_end; later lead turns keep posting <child>)
title: spinner froze mid-turn and never animated again

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):

  • The foreground helper turn posts only <lead> and ends with agent_end session_id=<lead>. The helper's transcript exists on disk but is never reported.
  • The background helper is never reported. The lead's wake-up turn posts <lead>.
  • /new moves the pane to the new session. /resume back to the original lead works. /fork moves to the fork, and a helper spawned from the fork is ignored.
  • /reload keeps the lead.
  • The title spinner keeps animating through and after the helper turn, /reload and /new.

Tests:

  • New regressions in omp-session-status-owner.test.ts and titlebar-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

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.

…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]>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Status ownership checks now account for Pi agent kind, OMP sessions, and parent sessions. Titlebar ownership now handles startup and other session-start reasons differently. Tests cover child-session callbacks, title publication, reloads, and new sessions.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 2877c

Starting OMP with --fork leaves the lead session without pane status updates. Fix that ownership check before merging unless this regression is explicitly accepted.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue #31526 requires two coding outcomes: only the lead session controls pane status and title/resume state, and child transcripts are grouped under the lead or excluded from the top-level history. T… Implement and test history handling for Pi child transcripts. Use each child transcript's parentSession to group it under the lead, or exclude it from the top-level Agent Session History list.
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing in-process Pi subagent sessions from taking over the lead pane.
Out of Scope Changes check Passed The changed production files implement the ownership and titlebar behavior described by issue #31526. The changed tests cover those behaviors. The supplied evidence shows no unrelated change.
Description check Passed The description is complete and relevant. It explains the user-visible problem, root cause, implementation changes, rationale, linked issue, verification steps, test results, and known risks. It does …
Full details: Description check

Explanation

The description is complete and relevant. It explains the user-visible problem, root cause, implementation changes, rationale, linked issue, verification steps, test results, and known risks. It does not include several template sections, such as Visual Proof, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist, but the missing sections are non-critical because the description provides equivalent testing and impact information.

Full details: Linked Issues check

Explanation

Issue #31526 requires two coding outcomes: only the lead session controls pane status and title/resume state, and child transcripts are grouped under the lead or excluded from the top-level history. The reviewed source adds Pi SessionManager ownership checks and preserves the lead titlebar across startup child sessions. The added tests cover child callbacks, lead completion, session replacement, and spinner lifetime. However, the PR description states that helper-transcript history grouping is unchanged, and the supplied change summary shows no history implementation or history test. The history requirement remains unmet.

Resolution

Implement and test history handling for Pi child transcripts. Use each child transcript's parentSession to group it under the lead, or exclude it from the top-level Agent Session History list.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between 55d12e1 and 2877c35.

Files selected for processing: 5
  • src/main/pi/agent-status-handler-source.ts
  • src/main/pi/omp-session-status-owner-source.ts
  • src/main/pi/omp-session-status-owner.test.ts
  • src/main/pi/titlebar-extension-lifetime-source.ts
  • src/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',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Quick win

🔎 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pi child sessions take over a terminal pane's providerSession and appear as orphaned Agent Session History entries

1 participant