Skip to content

fix(agent-hooks): preserve Antigravity pane ownership across nested subagents - #37507

Closed
zhangxaochen wants to merge 2 commits into
stablyai:mainfrom
zhangxaochen:zhangxaochen/antigravity-nested-subagent-owner
Closed

zhangxaochen wants to merge 2 commits into
stablyai:mainfrom
zhangxaochen:zhangxaochen/antigravity-nested-subagent-owner

Conversation

@zhangxaochen

@zhangxaochen zhangxaochen commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Capture ORCA_HOOK_AGENT_PID (PPID) and agentProcess in the POSIX antigravity-hook.sh script and admit antigravity in readHookAgentProcess so idle Antigravity process owners reject nested guest CLI hooks at the server/relay layer.
  • Include paneOwner ({ agent, session }) on AgentStatusEntry and mobile runtime status projections whenever a session-bound pane owner (agentPresence.session) is active.
  • Suppress nested guest CLI hooks (such as a background grok subagent spawned from agy) in isInheritedFromActivePane and buildAgentStatusLiveEntry when paneOwner or live foreground process evidence still belongs to the parent pane owner (even after the parent turn completes or exceeds the 5-minute active-turn window), unless foreground process evidence shows the pane returned to the shell or switched to another process-read agent.
  • Resolve effectiveAgentStatusOwnerType(entry) (entry.paneOwner?.agent ?? entry.agentType) across desktop tab-bar/pane selectors, session-resume records, AI vault title candidates, and mobile tab/native-chat eligibility so an Antigravity terminal tab never flips its icon to Grok or switches from Agy Terminal View into Grok Chat View.

Fixes #37505

Test Plan

  • Added unit tests in src/main/agent-hooks/server-idle-process-owner.test.ts verifying idle antigravity process owners reject nested grok hooks.
  • Added unit tests in src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts verifying nested grok hooks are suppressed when antigravity is the paneOwner after turn completion and allowed once foreground returns to shell.
  • Added unit tests in src/renderer/src/components/tab-bar/tab-agent-types-by-tab-id.test.ts, src/renderer/src/components/terminal-pane/terminal-tab-agent-type-index.test.ts, mobile/src/session/native-chat/mobile-native-chat-eligibility.test.ts, and mobile/src/session/mobile-terminal-tab-agent.test.ts.

…ubagents

- Capture ORCA_HOOK_AGENT_PID/PPID and agentProcess in POSIX antigravity-hook.sh and admit antigravity in readHookAgentProcess so idle Antigravity process owners block nested CLI hooks
- Propagate paneOwner ({ agent, session }) on AgentStatusEntry and mobile status projections when a session-bound root owner is active
- Suppress nested guest CLI hooks (e.g. background grok subagent) in renderer status routing and live entry builder while paneOwner or foreground process remains on the parent owner
- Resolve effectiveAgentStatusOwnerType (paneOwner.agent ?? agentType) in desktop/mobile tab selectors and native-chat eligibility so an Antigravity terminal never flips to Grok Chat View

Fixes stablyai#37505
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The changes add pane-owner agent and session identity to agent status and carry it through runtime projections and renderer state. Renderer and mobile consumers prefer the pane owner when resolving an agent. Nested guest provider sessions are excluded from Native Chat resolution in the covered cases, while resume and title-request paths can derive session metadata from the owner session. Antigravity hooks also capture and send process identity. Tests cover owner retention and consumer resolution.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to fd96e

The reviewed ownership and session paths show no remaining actionable merge risk beyond normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the implementation and lists tests, but it does not follow the required template. It omits or replaces major sections including ELI5, What Changed, Why, Visual Proof, Risk, No… Rewrite the description using the required headings. Add a plain-language ELI5 summary, separate What Changed and Why sections, complete Linked Issue and Visual Proof with N/A plus a reason if applicable, document Testing and platforms, sta…
Docstring Coverage Warning Docstring coverage is 35.48% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… 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 primary change: preserving Antigravity pane ownership across nested subagents.
Linked Issues check Passed Issue [#37505] requires Antigravity pane ownership to survive nested CLI hooks until the pane returns to the shell or switches to another foreground agent. The changes capture ORCA_HOOK_AGENT_PID an…
Out of Scope Changes check Passed The changed files support issue [#37505]. They preserve pane-owner data, reject or accept nested hooks based on foreground evidence, retain resume identity, and prevent incorrect desktop or mobile age…
Full details: Linked Issues check

Explanation

Issue [#37505] requires Antigravity pane ownership to survive nested CLI hooks until the pane returns to the shell or switches to another foreground agent. The changes capture ORCA_HOOK_AGENT_PID and agentProcess, admit antigravity as a hook process, carry paneOwner through IPC, runtime, renderer, resume, and mobile projections, suppress conflicting nested status updates, and use effectiveAgentStatusOwnerType in desktop and mobile selectors. The tests cover idle process ownership, post-completion nested Grok hooks, foreground release, tab identity, terminal identity, and mobile Native Chat eligibility.

Full details: Out of Scope Changes check

Explanation

The changed files support issue [#37505]. They preserve pane-owner data, reject or accept nested hooks based on foreground evidence, retain resume identity, and prevent incorrect desktop or mobile agent projections. The added tests validate these behaviors. The runtime array-handling change is an implementation refactor with unchanged grouping and ordering. No unrelated change is demonstrated.

Full details: Description check

Explanation

The description explains the implementation and lists tests, but it does not follow the required template. It omits or replaces major sections including ELI5, What Changed, Why, Visual Proof, Risk, Notes, and the required checklist details.

Resolution

Rewrite the description using the required headings. Add a plain-language ELI5 summary, separate What Changed and Why sections, complete Linked Issue and Visual Proof with N/A plus a reason if applicable, document Testing and platforms, state the risk and rollback plan, complete AI Disclosure and repository checklist sections, and address cross-platform, SSH, mobile, compatibility, security, and performance considerations.

Full details: Docstring Coverage

Explanation

Docstring coverage is 35.48% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 31 functions across 30 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/scala/security/scala-jwt-hardcoded-secret-scala.yml

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent 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: 7c683aa2-3054-4512-83e1-1a94023f6811
Commits

Reviewing files that changed from the base of the PR and between 9615db3 and fd96e02.

Files selected for processing: 5
  • mobile/src/session/native-chat/mobile-native-chat-eligibility.test.ts
  • mobile/src/session/native-chat/mobile-native-chat-eligibility.ts
  • src/main/antigravity/hook-service.ts
  • src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts
  • src/renderer/src/store/slices/agent-status/agent-status-live-entry-main-agent.ts

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

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

Follow-up Comments

Nitpick Assert the effective owner in the replacement test.

121-125: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the effective owner in the replacement test.

The fixture passes a conflicting Antigravity paneOwner to the direct Grok setAgentStatus call. Because effectiveAgentStatusOwnerType gives paneOwner.agent precedence, the current assertions can pass while the effective owner remains Antigravity.

Suggested test assertion
+import { effectiveAgentStatusOwnerType } from '../../../../shared/agent-status-types'
+
 // ...
-    expect(store.getState().agentStatusByPaneKey[PANE_KEY]).toMatchObject({
+    const entry = store.getState().agentStatusByPaneKey[PANE_KEY]
+    expect(entry).toMatchObject({
       agentType: 'grok',
       state: 'working',
       prompt: 'Direct Grok session'
     })
+    expect(effectiveAgentStatusOwnerType(entry)).toBe('grok')

Open the source location

Comment thread src/main/antigravity/hook-script.ts Resolved
Comment on lines +101 to +108
resolvePaneOwner: (resolvedAgentType) =>
incomingPaneOwner ??
(sameTerminal &&
!foregroundLeftExistingOwner &&
existing?.paneOwner &&
existing.paneOwner.agent === resolvedAgentType
? existing.paneOwner
: undefined)

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:

set -o pipefail
printf '%s\n' '--- changed file ---'
nl -ba src/renderer/src/store/slices/agent-status/agent-status-live-entry-main-agent.ts | sed -n '1,230p'
printf '%s\n' '--- focused references and tests ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'resolvePaneOwner' -e 'foregroundLeftExistingOwner' -e 'paneOwner' src/renderer/src/store/slices/agent-status src/main/agent-hooks src/renderer/src | head -240
printf '%s\n' '--- relevant test files ---'
rg --files src/renderer/src/store/slices/agent-status | rg 'agent-status-live-entry-main-agent.*test|test.*agent-status-live-entry-main-agent'

Repository: stablyai/orca

Length of output: 19489


Script executed:

set -o pipefail
printf '%s\n' '--- live entry builder ---'
nl -ba src/renderer/src/store/slices/agent-status/agent-status-live-entry-builder.ts | sed -n '70,275p'
printf '%s\n' '--- routing ---'
nl -ba src/renderer/src/hooks/ipc-events/agent-status-routing.ts | sed -n '130,205p'
printf '%s\n' '--- server status identity ---'
nl -ba src/main/agent-hooks/server/server-status-identity.ts | sed -n '1,125p'
printf '%s\n' '--- pane-owner reclaim tests ---'
nl -ba src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts | sed -n '1,155p'
printf '%s\n' '--- server hook binding tests and implementation references ---'
nl -ba src/main/agent-hooks/server-hook-session-binding.test.ts | sed -n '90,245p'
rg -n -F --glob '*.ts' -e 'agentPresence' -e 'setAgentPresence' -e 'clearAgentPresence' -e 'routingRevoked' src/main/agent-hooks/server src/main/agent-hooks | head -240

Repository: stablyai/orca

Length of output: 37219


Script executed:

set -o pipefail
printf '%s\n' '--- server status update ---'
nl -ba src/main/agent-hooks/server/server-status-update.ts | sed -n '1,310p'
printf '%s\n' '--- server agent presence ---'
nl -ba src/main/agent-hooks/server/server-agent-presence.ts | sed -n '1,180p'
printf '%s\n' '--- server binding tests around presence transitions ---'
nl -ba src/main/agent-hooks/server-hook-session-binding.test.ts | sed -n '245,445p'
printf '%s\n' '--- antigravity admission tests ---'
nl -ba src/main/agent-hooks/server-antigravity-status-admission.test.ts | sed -n '1,145p'

Repository: stablyai/orca

Length of output: 35783


Script executed:

set -o pipefail
printf '%s\n' '--- presence transition definitions ---'
rg -n -F --glob '*.ts' -e 'function previewHookPresence' -e 'previewHookPresence' -e 'retainHookRootContext' src shared
printf '%s\n' '--- presence transition source ---'
nl -ba src/shared/agent-hook-presence-transition.ts | sed -n '1,300p'
printf '%s\n' '--- root-context retention source ---'
nl -ba src/shared/agent-hook-listener/pane-provider-session.ts | sed -n '1,260p'
printf '%s\n' '--- hook normalization agentPresence assignments ---'
rg -n -F --glob '*.ts' -e 'agentPresence:' -e 'sessionOwner' src/main/agent-hooks src/shared/agent-hook-listener | head -260

Repository: stablyai/orca

Length of output: 21211


Drop a stale incoming paneOwner after foreground ownership moves.

When foregroundLeftExistingOwner is true, the incoming status is accepted, but resolvePaneOwner still returns an incoming owner before checking resolvedAgentType. A direct Grok status can retain the departed Antigravity owner.

Suggested fix
--- "a/src/renderer/src/store/slices/agent-status/agent-status-live-entry-main-agent.ts"
+++ "b/src/renderer/src/store/slices/agent-status/agent-status-live-entry-main-agent.ts"
@@ -98,9 +98,13 @@
     )
   return {
     suppressedByPaneOwner,
     resolvePaneOwner: (resolvedAgentType) =>
-      incomingPaneOwner ??
+      (foregroundLeftExistingOwner &&
+      incomingPaneOwner?.agent === existingOwnerAgent &&
+      incomingPaneOwner.agent !== resolvedAgentType
+        ? undefined
+        : incomingPaneOwner) ??
       (sameTerminal &&
       !foregroundLeftExistingOwner &&
       existing?.paneOwner &&
       existing.paneOwner.agent === resolvedAgentType
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
resolvePaneOwner: (resolvedAgentType) =>
incomingPaneOwner ??
(sameTerminal &&
!foregroundLeftExistingOwner &&
existing?.paneOwner &&
existing.paneOwner.agent === resolvedAgentType
? existing.paneOwner
: undefined)
resolvePaneOwner: (resolvedAgentType) =>
(foregroundLeftExistingOwner &&
incomingPaneOwner?.agent === existingOwnerAgent &&
incomingPaneOwner.agent !== resolvedAgentType
? undefined
: incomingPaneOwner) ??
(sameTerminal &&
!foregroundLeftExistingOwner &&
existing?.paneOwner &&
existing.paneOwner.agent === resolvedAgentType
? existing.paneOwner
: undefined)

Source: Learnings

…capture

- Capture ORCA_HOOK_AGENT_PID before launching the POSIX antigravity-hook.sh wrapper shell in getPosixManagedCommand
- Drop stale incoming paneOwner when foregroundLeftExistingOwner transitions to a new foreground agent
- Preserve paneOwner.session and matching remembered transcript metadata when a supported Native Chat owner has a nested guest status
@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Thanks @zhangxaochen. We carried your work into #37955, which is now merged, and retained your contributor credit. Closing this PR as superseded by that merged fix.

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.

fix(agent-hooks): preserve Antigravity pane ownership when spawning nested Grok subagents

2 participants