Skip to content

fix(pi): suppress subagent agent_end so nested sessions don't fire false notifications - #8545

Merged
AmethystLiang merged 4 commits into
stablyai:mainfrom
itisbryan:fix/pi-subagent-notifications
Jul 16, 2026
Merged

AmethystLiang merged 4 commits into
stablyai:mainfrom
itisbryan:fix/pi-subagent-notifications

Conversation

@itisbryan

@itisbryan itisbryan commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pi/OMP run subagents as nested child processes that inherit the lead pane's env (including ORCA_PANE_KEY), each loading its own copy of the orca-agent-status.ts extension. A child's agent_end was attributed to the lead pane, firing a false "agent finished" notification on every subagent completion. This gates status reporting to the top-level Pi process per pane, keyed on process nesting so top-level runs — interactive and non-interactive pi -p — still notify, while nested subagents stay silent.

Changes

  • Nesting-based reporting gate (agent-status-handler-source.ts) — the first Pi process to load the extension reads ORCA_PI_STATUS_OWNED, finds it unset, reports normally, and sets it. Any Pi it spawns inherits the marker and suppresses all its lifecycle posts. Chosen over a hasUI/mode check specifically so a top-level non-interactive pi -p run (which is hasUI=false) still reports its own completion.
  • Single source of truth — the guard lives in the shared handler source both Pi and OMP compose from (getPiAgentStatusExtensionSource), so it applies to both agents and to local + SSH/remote panes with no duplication.

Testing

  • pnpm test — 29,114 passed, 42 skipped, 0 failed (full suite). Scoped agent-status-extension-source.test.ts: 14 passed (11 existing + 3 new).
  • pnpm typecheck — clean (node, cli, web tc configs). oxlint clean on changed files. pnpm build — exit 0 (desktop + native).
  • New tests: a nested subagent (ORCA_PI_STATUS_OWNED=1) posts nothing; a top-level run (interactive or non-interactive) posts agent_end and claims the env marker.
  • Root cause confirmed by live process trace: subagents are separate child processes (ppid = lead pid) in headless mode, sharing the lead's pane key, each firing agent_end; the lead never fired agent_end while still working.

Screenshots

No visual change — this affects OS-notification timing only.

Security Audit

No input handling, command execution, path handling, auth, secrets, dependency, or IPC changes. The diff reads and sets one internal process env marker (ORCA_PI_STATUS_OWNED) and branches on it; no new external input is trusted and no new surface is introduced.

AI code-review summary

  • Cross-platform (macOS/Linux/Windows): no platform-specific code; a pure env-marker read/write in the renderer-injected extension. Env inheritance to child processes is uniform across platforms.
  • SSH / remote / local: transport-agnostic — the same extension source ships to native, WSL, and SSH agent dirs; nesting semantics are identical.
  • Agent / integration compatibility: scoped to Pi and OMP (shared handler source); no other agent's hook path is touched.
  • Performance: negligible — one env read + one assignment at extension load; per-event cost is a single boolean check.
  • Security: no input handling, command execution, path, auth, or secret surface; adds one internal env marker.

Notes

…lse notifications

Pi/OMP run subagents as nested child processes that inherit the lead
pane's env (including ORCA_PANE_KEY), each loading its own copy of the
orca-agent-status.ts extension. A child's agent_end was attributed to the
lead pane, firing a false "agent finished" notification on every subagent
completion.

Gate status reporting to the top-level Pi process per pane via an
ORCA_PI_STATUS_OWNED env marker: the first process claims the pane and
sets the marker; any Pi it spawns inherits it and stays silent. Keyed on
process nesting (not hasUI) so a top-level non-interactive `pi -p` run
still reports its own completion.
@itisbryan
itisbryan force-pushed the fix/pi-subagent-notifications branch from aef8508 to 8d9b5ef Compare July 13, 2026 10:32
@itisbryan
itisbryan marked this pull request as ready for review July 13, 2026 10:32
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 61a4131b-7fdd-4bdc-9b90-003d8a1b3efe

📥 Commits

Reviewing files that changed from the base of the PR and between 6f0b466 and 1a574e4.

📒 Files selected for processing (2)
  • src/main/pi/agent-status-extension-source.test.ts
  • src/main/pi/agent-status-handler-source.ts

📝 Walkthrough

Walkthrough

Pi status handlers now suppress lifecycle, tool, and assistant message reporting from nested subagents using the ORCA_PI_STATUS_OWNED environment marker. Top-level processes claim ownership and continue posting status events. Tests control the mocked process identity and environment, and cover nested silence, top-level agent_end delivery, ownership marking, and reporting after reload.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: suppressing false subagent notifications in Pi sessions.
Description check ✅ Passed The description covers the required sections and includes testing, screenshots, security, notes, and cross-platform review details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

🧹 Nitpick comments (1)
src/main/pi/agent-status-extension-source.test.ts (1)

186-199: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Tests pass but coverage is narrow.

The two new tests verify agent_end suppression and top-level delivery, which is the core of this PR. However, the message_end handler now adds assistant-role filtering (line 84 in the handler source) and all other events (before_agent_start, tool_execution_start, tool_call, tool_execution_end) share the same reportsToPane() guard — none of these are directly tested for nested suppression. Consider adding a test that fires a non-assistant message_end or a tool_call in a nested harness to confirm silence, which would protect against regressions if the guard is ever refactored per-event.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6e919e67-2213-4e16-976d-dfe0213d3097

📥 Commits

Reviewing files that changed from the base of the PR and between 0b65d72 and 8d9b5ef.

📒 Files selected for processing (2)
  • src/main/pi/agent-status-extension-source.test.ts
  • src/main/pi/agent-status-handler-source.ts

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@itisbryan Thanks for the update! Expanding the test to cover all guarded events (before_agent_start, tool_call, tool_execution_start/_end, message_end) instead of just agent_end is a solid improvement — it locks in the invariant so a future per-event refactor won't silently reintroduce the leak. Appreciate adding the Screenshots and Security Audit sections too.

ᕦ(ò_óˇ)ᕤ

@AmethystLiang

Copy link
Copy Markdown
Contributor

reviewing

…the lead

The subagent-suppression gate marked the pane owner with a boolean
ORCA_PI_STATUS_OWNED='1'. Pi re-invokes an extension's default export on
every in-process reload (/reload, live edit, settings reload), so the lead
process re-ran the factory, read the '1' it had set on first load, and
treated itself as a nested subagent — silencing all its own status
(working, tools, done, notifications) for the rest of the session.

Record the owning process's pid instead. A same-process reload matches its
own pid and keeps reporting; a spawned subagent inherits the lead's pid,
sees it differs from its own, and stays silent. Startup was unaffected
(bindExtensions runs the factory once), which is why the single-run trace
missed it.

Add a reload regression test that re-invokes the factory in the same
process and asserts the lead still reports; it fails against the boolean
marker.

Co-authored-by: Orca <[email protected]>
@AmethystLiang

Copy link
Copy Markdown
Contributor

Pushed a follow-up commit (6f0b466) that fixes a self-silencing bug in the gate, verified against pi's source.

The bug: the boolean marker silences the lead on extension reload

Pi re-invokes an extension's default export every time extensions (re)load in the same process — loadExtension calls await factory(api) on each load (packages/coding-agent/src/core/extensions/loader.ts:450), and AgentSession.reload() re-runs the resource loader (agent-session.ts:2550). Reload is first-class and user-triggered: /reload, live extension editing, settings reload.

Because the gate marks the pane owner with a boolean ORCA_PI_STATUS_OWNED='1', the lead process:

  1. First load → marker unset → reports, sets '1'.
  2. Any later reload → factory re-runs in the same process → reads the '1' it set itself → isNestedAgent = true → the lead silences all its own status (working, tools, done, notifications) for the rest of the session.

A boolean can't distinguish "a child process inherited my env" from "I re-ran in the same process." Startup only invokes the factory once (bindExtensions doesn't re-load modules), which is why a single-run trace doesn't surface it.

The fix: key the owner on pid, not a boolean

const ownerPid = process.env.ORCA_PI_STATUS_OWNED
const selfPid = String(process.pid)
const isNestedAgent = !!ownerPid && ownerPid !== selfPid
if (!ownerPid) process.env.ORCA_PI_STATUS_OWNED = selfPid

A same-process reload matches its own pid → keeps reporting. A spawned subagent inherits the lead's pid, sees it differs → stays silent. Set-only-when-unset keeps the original lead pid stable down the subagent tree.

Added a reload regression test that re-invokes the factory twice in one process and asserts the lead still reports — it fails against the old boolean marker.

What I verified in pi's source (the approach itself is sound)

  • Subagents are child processes spawned with no env override (examples/extensions/subagent/index.ts:335), so they inherit the live process.env mutation — the marker propagates.
  • Print/json subagents do bind agent-dir extensions (print-mode.ts:73), so the false-notification bug is real.
  • The lead emits tool_execution_start/_end around the subagent tool (agent-loop.ts:447), so the pane correctly stays working during a subagent run — blanket suppression leaves no idle gap.
  • Orca launches pi single-process; the --mode rpc embedding path isn't Orca's, so "lead loads first" holds.

Verification

oxlint clean · all 3 typecheck configs (node/cli/web) exit 0 · 273 tests pass across src/main/pi/ + agent-hooks/server.test.ts (incl. the new reload regression test).

Out of scope (not a bug): pi subagents still don't surface as payload.subagents[] child rows the way Claude's do — that needs subagent-identity plumbing pi doesn't expose via env, and is a separate follow-up.

@AmethystLiang

Copy link
Copy Markdown
Contributor

Completed a deep review of the latest branch and pushed 1a574e43f.

One additional issue surfaced: nested processes still registered every status handler and depended on each handler carrying its own guard. That made the fix fragile—any future hook added without the guard could reintroduce false lead-pane notifications. The follow-up moves the ownership check to the extension factory boundary, so nested Pi/OMP processes register zero status hooks. The PID owner marker still preserves same-process /reload behavior and stays stable through child/grandchild process trees.

Coverage now explicitly exercises Pi and OMP descendants, a grandchild process, non-interactive top-level pi -p, and in-process reload.

Validation on 1a574e43f:

  • Full unit suite: 2,754 files / 29,116 tests passed; 42 skipped; 0 failed
  • Related Pi + agent-hook suite: 273 passed
  • All node/CLI/web typechecks passed
  • Full lint, reliability, max-lines, and localization gates passed (only pre-existing unrelated warnings)
  • Electron/Vite production build passed
  • Formatting and git diff --check passed

The fork workflow was created and I approved its Actions run so PR CI can execute: https://github.com/stablyai/orca/actions/runs/29463984466.

@AmethystLiang AmethystLiang 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.

Reviewed the latest head (1a574e43f) after the factory-level ownership hardening and full local validation. I found no remaining correctness, cross-platform, SSH, transport, or test-coverage blockers. Approved.

@AmethystLiang
AmethystLiang merged commit 5b5d37f into stablyai:main Jul 16, 2026
1 check passed
@euclodius

euclodius commented Jul 17, 2026 •

Copy link
Copy Markdown

The PR's documented in-process limitation is now reproducible with OMP 17.0.2: task workers are child AgentSession instances in the same PID, and the hidden 'yield' completion can trigger a false top-level notification. This is tracked with reproduction details in #9181. The PID ownership gate appears to need session-level origin for current OMP.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lse notifications (stablyai#8545)

* fix(pi): suppress subagent agent_end so nested sessions don't fire false notifications

Pi/OMP run subagents as nested child processes that inherit the lead
pane's env (including ORCA_PANE_KEY), each loading its own copy of the
orca-agent-status.ts extension. A child's agent_end was attributed to the
lead pane, firing a false "agent finished" notification on every subagent
completion.

Gate status reporting to the top-level Pi process per pane via an
ORCA_PI_STATUS_OWNED env marker: the first process claims the pane and
sets the marker; any Pi it spawns inherits it and stays silent. Keyed on
process nesting (not hasUI) so a top-level non-interactive `pi -p` run
still reports its own completion.

* test(pi): assert nested-subagent silence for every guarded event, not just agent_end

* fix(pi): key status owner on pid so extension reload doesn't silence the lead

The subagent-suppression gate marked the pane owner with a boolean
ORCA_PI_STATUS_OWNED='1'. Pi re-invokes an extension's default export on
every in-process reload (/reload, live edit, settings reload), so the lead
process re-ran the factory, read the '1' it had set on first load, and
treated itself as a nested subagent — silencing all its own status
(working, tools, done, notifications) for the rest of the session.

Record the owning process's pid instead. A same-process reload matches its
own pid and keeps reporting; a spawned subagent inherits the lead's pid,
sees it differs from its own, and stays silent. Startup was unaffected
(bindExtensions runs the factory once), which is why the single-run trace
missed it.

Add a reload regression test that re-invokes the factory in the same
process and asserts the lead still reports; it fails against the boolean
marker.

Co-authored-by: Orca <[email protected]>

* fix(pi): gate nested status hooks at registration

---------

Co-authored-by: Jinjing <[email protected]>
Co-authored-by: Orca <[email protected]>
nplez1 added a commit to nplez1/orca that referenced this pull request Nov 28, 2026
…the PID alone (#480)

An inherited ORCA_PI_STATUS_OWNED naming a live PID muted the whole descendant
tree, so a session that inherited the marker but reports for another pane sent
nothing at all — no session_start, no turn events, no scheduled_work — while
Orca showed the pane idle. Env only reaches descendants, so the bare PID could
not separate the pane's own nested subagent (which must stay silent, stablyai#8545) from
a different pane's reporter.

A claim now records the claimant's ORCA_PANE_KEY beside its PID, and an inherited
marker recorded for another pane is no claim on this one; a claim with no pane
record of its own deletes the stale one, so a new owner never pairs with an old
pane. Both lanes use the shared predicate, so the status and titlebar lanes
cannot drift (#229). The three _PANE companion keys are stripped at every pane
boundary beside the keys they belong to.

The stand-down is no longer silent: it is recorded on globalThis keyed by lane,
and warned once per process when stderr is a TTY or ORCA_PI_STATUS_DEBUG is set.
A piped subagent nobody asked to debug stays quiet.
lab-agent-np Bot added a commit to nplez1/orca that referenced this pull request Nov 28, 2026
…the PID alone (#480) (#500)

An inherited ORCA_PI_STATUS_OWNED naming a live PID muted the whole descendant
tree, so a session that inherited the marker but reports for another pane sent
nothing at all — no session_start, no turn events, no scheduled_work — while
Orca showed the pane idle. Env only reaches descendants, so the bare PID could
not separate the pane's own nested subagent (which must stay silent, stablyai#8545) from
a different pane's reporter.

A claim now records the claimant's ORCA_PANE_KEY beside its PID, and an inherited
marker recorded for another pane is no claim on this one; a claim with no pane
record of its own deletes the stale one, so a new owner never pairs with an old
pane. Both lanes use the shared predicate, so the status and titlebar lanes
cannot drift (#229). The three _PANE companion keys are stripped at every pane
boundary beside the keys they belong to.

The stand-down is no longer silent: it is recorded on globalThis keyed by lane,
and warned once per process when stderr is a TTY or ORCA_PI_STATUS_DEBUG is set.
A piped subagent nobody asked to debug stays quiet.

Co-authored-by: Nathan Plesnicher <[email protected]>
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.

4 participants