Skip to content

fix(agent-status): let a pane's owner reclaim it from a nested agent's hooks - #33572

Merged
nwparker merged 3 commits into
mainfrom
nwparker/agint-nested-agent-identity-guard
Oct 25, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/agint-nested-agent-identity-guard

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​127 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​127
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46

ELI5

If the agent in a pane starts another agent that keeps running in the background (a claude -p job, or a Pi-based runtime), the child gets the pane's Orca environment, so its hooks report as that pane. When the child posted while the pane's own agent was idle, Orca relabeled the pane to the child. The real bug came after that: the owner's own next hooks were treated as "nested" and dropped, so the pane stayed on the wrong agent until the child finished or its row went stale (up to 30 minutes). With this change the pane's owner takes the pane back on its next hook.

Root cause

What changed

  • transitionHookPresence now also records the provider session that claimed the pane (agentPresence.session). The relay forwards it, and main reads it back through readAgentProcessPresence.
  • resolveAgentStatusIdentity: a hook from the pane's recorded owner session (same agent and same session id, not ended, no conflicting process owner) is accepted over a fresh row from another agent. Matching the agent type alone is not enough, because a recorded owner can outlive the real one (the relay re-sends presence, and local exits can be missed); a nested codex exec or Pi child always has a new session id. If no session was recorded (older hosts/relays), main's existing behavior applies.
  • Main forwards the owner to the renderer as paneOwner: {agent, session} on agentStatus:set. The renderer's two copies of the guard (IPC applicator and live-entry builder) pass it through so they reach the same verdict as main. The applicator's guard moves into agent-status-routing.ts because the applicator is at the 300-line limit.
  • Older hosts or renderers that don't know the field keep today's behavior.

Reproduction (real CLIs, isolated HOME/CLAUDE_CONFIG_DIR/CODEX_HOME, fake Anthropic and OpenAI servers, no spend)

Real claude 2.1.310 and codex 0.164.0 ran Orca's generated claude-hook.sh / codex-hook.sh (plus Codex hook trust) and posted to a real AgentHookServer:

  • Claude parent, Bash runs codex exec: the nested Codex posted SessionStart/UserPromptSubmit/Stop, and all of them were rejected. The pane stayed Claude. Already fixed on main (Keep idle Claude sessions selected during nested Codex work #29386 process owner).
  • Codex parent, shell runs claude -p: the nested Claude posted SessionStart/UserPromptSubmit/Stop/SessionEnd, and all of them were rejected. The pane stayed Codex. Already fixed on main (fix(agent-status): stop nested reviews from collapsing Claude children #29264).
  • Codex parent finishes its turn while a claude -p job runs in the background in the same pane, then Codex runs another turn:
  • Upstream: Codex hooks send session_id: sess.session_id() on every turn of a session (codex-rs/core/src/hook_runtime.rs:157 and other call sites). Pi and OpenCode report their session id, which stays the same across turns until /new. Known gap: a brand-new Pi session only reports its id after the first message (Pi creates the session file then), so a Pi owner recorded before that has no session and keeps main's behavior; resumed Pi sessions and OMP are covered.

Verification

  • New server tests (real HTTP hook path): the owner-reclaim test fails on main, and the stale-owner relay test (Codex, then Claude working, then a nested codex exec) failed on the previous head. Both pass now. New renderer store test covers the builder guard with and without paneOwnerAgent.
  • pnpm tc, check:code-quality:changed, and the agent-hooks/shared/renderer agent-status/sidebar/runtime suites (~45k tests) pass.
  • Not done: an Electron UI run.

Risk / trade-offs

  • Still unchanged (product decision): while an owner without process proof is idle or done, a different agent's hook can still take the pane. This is deliberate so that a new agent started in the same pane is accepted without exit evidence (see lets a new agent claim the pane with its model once the parent turn is done). The pane is now corrected on the owner's next hook instead of staying wrong.
  • If the owner starts a new session (/new, /clear) and a child then holds the row, the owner's hooks are dropped until the child finishes, same as on main.
  • Mixed versions: an older SSH relay still drops these hooks before forwarding.

Fixes #30589
Refs #13341 #22011

Credit: Emaj77 for the root-cause analysis in #30589. phillipLoacker, xxuxinn and pobbye-star for the nested codex exec hook traces in #13341. mmarabel (#22800), OrcaWin (#14012) and mrcha033 (#13385) for earlier nested-identity work that this supersedes.

…s hooks

A nested agent (e.g. a background `claude -p` or Pi runtime started by the
pane's agent) inherits ORCA_PANE_KEY. If it posts while the owner is idle it
is admitted, and its fresh row then made the owner's own next hooks look
inherited, so they were dropped until the child went done or stale (#30589).

The hook server already records the pane's owner in agentPresence and keeps
it through nested hooks; resolveAgentStatusIdentity now admits a hook from
that owner over a fresh row of another agent. Main forwards the owner to the
renderer as paneOwnerAgent so its guards agree; the IPC applicator's guard
moves into agent-status-routing to stay under the file-size limit.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Status identity resolution now receives provider session IDs and can preserve an incoming agent when its session matches the active pane owner. Status events carry pane-owner metadata when the agent has a session and has not ended. The renderer normalizes this metadata and uses terminal ownership and identity resolution to determine whether an incoming status is inherited. Tests cover pane-owner reclaim and nested-agent hooks.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 754fe

Long provider sessions may prevent the pane owner from reclaiming its status row; align the limits before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 14 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: a pane's owner can reclaim the pane from a nested agent's hooks. The change set matches it. It records owner session presence, forwards paneOwner through the relay and…
Description check Passed The description follows the repository template closely. It has ELI5, Root cause, What changed, Reproduction, Verification, and Risk/trade-offs sections, and it links issue #30589 with 'Fixes #30589'.…
Linked Issues check Passed Issue #30589 is the only active directly linked issue. The PR implements its stated owner-reclaim objective. transitionHookPresence records the provider session for the pane owner and preserves it a…
Out of Scope Changes check Passed The changes stay within the owner-reclaim scope for #30589. Presence-transition changes record the owner session. Identity changes compare the owner session. Main, IPC, and renderer changes transport …
Full details: Title check

Explanation

The title names the main change: a pane's owner can reclaim the pane from a nested agent's hooks. The change set matches it. It records owner session presence, forwards paneOwner through the relay and main process, and adds a session-matching guard in the renderer and shared identity logic. The title is specific, uses the conventional fix(scope) form, and is under 80 characters.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, Root cause, What changed, Reproduction, Verification, and Risk/trade-offs sections, and it links issue #30589 with 'Fixes #30589'. It explains the before and after behavior and the mechanism, and it gives reasons for the chosen approach. The template's Visual Proof section is not filled in. The PR is a server and state-logic change, so the UI-facing before/after is not a screenshot or video, and the author does not state N/A with a reason. The Testing checklist boxes are unchecked, and the AI Disclosure, Review, and Agent skill upstream boundary sections are left as template text. The Linked Issue section also uses 'Fixes #30589' without the template's bare 'Fixes #' placeholder, which is fine. These gaps are minor and non-critical, so the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #30589 is the only active directly linked issue. The PR implements its stated owner-reclaim objective. transitionHookPresence records the provider session for the pane owner and preserves it across nested hooks. resolveAgentStatusIdentity accepts a later hook only when the agent and session match, the owner is not ended, and no other process owns the pane. Main and renderer paths carry this owner data so both paths apply the same decision. The PR also adds server and renderer regression coverage, as reported in the PR summary. The issue's suggested fixes for first-hook admission and Pi-extension verification are not part of this owner-reclaim objective and remain documented limitations.

Full details: Out of Scope Changes check

Explanation

The changes stay within the owner-reclaim scope for #30589. Presence-transition changes record the owner session. Identity changes compare the owner session. Main, IPC, and renderer changes transport and apply the same owner decision. The tests cover nested-hook recovery and renderer propagation. No changed area targets an unrelated feature.

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: f5c01a22-de59-4064-8d21-4f2852ec81d9
Commits

Reviewing files that changed from the base of the PR and between c074ec5 and d144863.

Files selected for processing: 10
  • src/main/agent-hooks/server-nested-agent-roster.test.ts
  • src/main/startup/main-window-agent-status.ts
  • src/renderer/src/hooks/ipc-events/agent-status-event-applicator.ts
  • src/renderer/src/hooks/ipc-events/agent-status-routing.ts
  • src/renderer/src/hooks/ipc-events/normalize-agent-status-event.ts
  • src/renderer/src/store/slices/agent-status-contract.ts
  • src/renderer/src/store/slices/agent-status-live-entry-builder.ts
  • src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts
  • src/shared/agent-status-identity.ts
  • src/shared/agent-status-ipc-payload.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

A recorded owner type can outlive the owner (relay re-sends presence; local
exits can be missed), so a nested codex exec matching only the type could take
the row. Record the claiming provider session in agentPresence and allow the
reclaim only for that session; without a recorded session keep prior behavior.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Align the session length limits before storing… · agent-hook-presence-transition.ts:53-60

src/shared/agent-hook-presence-transition.ts:53-60
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Align the session length limits before storing agentPresence.session.

Provider session IDs allow up to 512 characters, but presence deserialization accepts only 256 characters. A valid 257–512-character session stored here is dropped at the relay/main boundary. The owner’s later hook then cannot match the recorded session and cannot reclaim the pane. Use one shared validation limit for both fields. (raw.githubusercontent.com)


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: ad0bad83-bd11-4a7b-b76a-b937106ec23c
Commits

Reviewing files that changed from the base of the PR and between 5c629c6 and 754fe12.

Files selected for processing: 2
  • src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts
  • src/shared/agent-hook-presence-transition.ts
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

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]: A nested Pi-compatible runtime that inherits ORCA_PANE_KEY can claim a Claude Code pane and then suppress the legitimate Claude hook

1 participant