Skip to content

fix(agent-hooks): preserve Antigravity ownership across nested hooks - #37955

Merged
AmoabaKelvin merged 4 commits into
mainfrom
fix-antigravity-nested-pane-owner
Nov 3, 2026
Merged

AmoabaKelvin merged 4 commits into
mainfrom
fix-antigravity-nested-pane-owner

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​320 $\color{#cf222e}{\Huge{\mathbf{−}}}$​47 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8

Carries over #37507 by @zhangxaochen.

ELI5

An Antigravity tab stays an Antigravity terminal when its background Grok task reports progress, including after Antigravity finishes a turn.

What Changed

Capture Antigravity's process before the managed hook shell and carry that proof through HTTP, startup replay and host relays. The existing host owner admits the status consumed by both desktop and mobile. Its turn boundary can retry root admission when it becomes foreground.

Why

Antigravity lacked process-backed ownership, so nested hooks could replace its identity after a done or stale turn. Reusing the existing process lifecycle rules also permits genuine exit, suspension and foreground handoffs without permanent session-based vetoes.

Linked Issue

Fixes #37505

STA-13500

Visual Proof

The same real foreground process and hook HTTP sequence on main ab6f6a78807 and this branch, in hidden Electron at 1440×900. Main switches identity to Grok; the fix retains Antigravity. A Node fixture supplies process proof; no live agy executable is installed.

Main, after nested hooks Fixed, after nested hooks
Main changes identity to Grok Fixed retains Antigravity

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

On macOS, 277 focused tests pass across 24 files, with five platform skips. Failing-before/passing-after regressions cover done/stale ownership and foreground recovery. Suites cover HTTP/spool capture, relay root/exit/suspension and desktop consumers; 59 additional mobile identity/chat eligibility tests passed. The installed POSIX command was executed against a real process and HTTP receiver. Hidden Electron checks on both main and the fix assert rendered identity and terminal continuity through real HTTP ingestion, using disposable profiles and homes.

Local Linux, Windows, SSH/WSL and live Antigravity sessions were not exercised. Exact-head CI passed: PR checks passed and Mobile verify on cca29c419c0371628d31dfe06a9d7c24e2172530. All twelve unit shards and both packaging jobs passed. The local excessive-selection limitation below remains unchanged.

The required ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2 ran after the final rebase. All 28 non-unit checks passed, including node/web/CLI typechecks. Its broad related unit stage was canceled after 1207.5 seconds under the documented excessive-selection fallback; the full gate did not pass. Every selected input has named focused coverage.

Exact commands, selected inputs and scoped fallback evidence

HEAD cca29c419c0371628d31dfe06a9d7c24e2172530, base ab6f6a78807f985b9b7b993679e96fb4952f74c3. No tracked edit or rebase followed the required invocation.

ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2 selected 29 checks. All 28 non-unit checks passed, including full node, web and CLI typechecks. The broad related --run unit stage was canceled with SIGTERM after 1207.5 seconds because selection fanned out excessively. The gate returned 1 after 1208.3 seconds. This is an incomplete gate, not a pass. No pass cache was fabricated or base changed. landing-check-changed.log preserves its buffered output.

The coordinator explicitly approved the user-provided AGENTS.md fallback. Only this worktree's verified unit wrapper PID 25235 was signaled. Its Vitest PID 25429, worker children, and gate PID 25049 all exited; process group 25039 was empty afterward. No other session was signaled.

Every selected input

Paths in this table are relative to src/.

Selected input Named focused coverage
main/agent-hooks/hook-process-capture.ts hook-process-capture.test.ts; actual installed command in main/antigravity/posix-hook-invocation.test.ts
main/agent-hooks/hook-stdin-contract.ts spool.test.ts, managed-hook-stdin-lifecycle.test.ts, hook-script-outside-orca.test.ts, posix-hook-json-stdin-reader.test.ts
main/agent-hooks/runtime-home-hook-command.ts hook-process-capture.test.ts, installer-utils.test.ts, managed-hook-stdin-lifecycle.test.ts, main/claude/post-compact-hook-command.test.ts
main/agent-hooks/server-antigravity-status-admission.test.ts Same file, current HEAD
main/agent-hooks/server-hook-root-provenance.test.ts Same file, current HEAD
main/agent-hooks/server-idle-process-owner.test.ts Same file, current HEAD
main/agent-hooks/spool.test.ts Same file, current HEAD, all ten tests passed
main/antigravity/hook-script.ts posix-hook-invocation.test.ts, hook-service.test.ts, shared stdin lifecycle and outside-Orca tests
main/antigravity/hook-service.ts hook-service.test.ts, posix-hook-invocation.test.ts, main/agent-hooks/remote-hook-service-installers.test.ts
main/antigravity/posix-hook-invocation.test.ts Same file, current HEAD
shared/agent-hook-spool.ts agent-hook-spool-read.test.ts, agent-hook-spool-drain.test.ts, main/agent-hooks/spool.test.ts, installed POSIX startup spool test
shared/agent-process-presence.ts Idle owner, Antigravity status/session admission, hook session binding, relay owner tests; agent-process-presence-probe.test.ts, agent-hook-owner-presence.test.ts
shared/hook-root-attempts.ts Real ingestion retry regression in main/agent-hooks/server-hook-root-provenance.test.ts; server and relay root acquisition/replay suites
wsl-guest/agent-hook-envelope-build.ts agent-hook-server.test.ts, agent-hook-integration.test.ts, relay-idle-process-owner.test.ts, relay-hook-root-acquisition.test.ts, hook session binding

Evidence and exact commands

  • landing-rebase-tests.log: 277 passed, five platform skips across 24 named files on current HEAD. The exact command is recorded below.
  • landing-dependents.txt: regenerated with bash /Users/kelvinamoaba/.agents/skills/orca-issue/scripts/test-dependents.sh --base origin/main. All listed tests are covered by the prior direct-dependent run or the current 24-file run. Compared with the prior inventory, only spool.test.ts moved into the changed-test set; it passed in the current run. No missing named suite was found.
  • implementation-dependent-tests.log: exact 30-file command at its first line, 306 passed and 28 skipped. Its sole failure was the obsolete spool source-fragment assertion, removed in the final patch and covered by the current passing spool run. All four rebased patches compare equal under git range-diff; none of these direct-dependent test files changed in the nine main commits used for the rebase.
  • implementation-mobile.log: cd mobile && ORCA_BACKGROUND_LAUNCH=1 pnpm test src/session/mobile-terminal-tab-agent.test.ts src/session/native-chat/mobile-native-chat-eligibility.test.ts --maxWorkers=2, 59 passed. These files and the ownership patch are unchanged through the rebase. No mobile ownership implementation was added.
  • landing-main-render.log / landing-fixed-render.log: the ignored harness passed separately on exact main and fixed source, with real process/root reads and HTTP ingestion, 1440×900 rendered identity assertions and hidden-window assertions. Build commands and provenance are in rendered-proof-instructions.md.

Current-HEAD focused command:

ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/agent-hooks/server-idle-process-owner.test.ts src/main/agent-hooks/server-antigravity-status-admission.test.ts src/main/agent-hooks/server-antigravity-resume-identity.test.ts src/main/agent-hooks/server-hermes-resume-identity.test.ts src/main/agent-hooks/server-hook-session-binding.test.ts src/main/agent-hooks/server-hook-root-provenance.test.ts src/main/agent-hooks/server-hook-root-replay.test.ts src/main/agent-hooks/server-nested-agent-model.test.ts src/main/agent-hooks/server-grok-background-status.test.ts src/main/antigravity/posix-hook-invocation.test.ts src/main/antigravity/hook-service.test.ts src/main/agent-hooks/installer-utils.test.ts src/main/agent-hooks/remote-hook-service-installers.test.ts src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts src/main/agent-hooks/hook-script-outside-orca.test.ts src/wsl-guest/relay-idle-process-owner.test.ts src/wsl-guest/relay-hook-root-acquisition.test.ts src/wsl-guest/agent-hook-server.test.ts src/wsl-guest/agent-hook-integration.test.ts src/main/runtime/runtime-mobile-agent-status-builder.test.ts src/renderer/src/store/slices/agent-status/agent-status-nested-resume.spec.ts src/renderer/src/store/slices/agent-status-pane-owner-reclaim.test.ts src/shared/agent-hook-spool-read.test.ts src/shared/agent-hook-spool-drain.test.ts src/main/agent-hooks/spool.test.ts --maxWorkers=2

Excluded evidence: completion of the broad transitive related selection. No full-gate pass is claimed. Exact-head aggregate PR checks and Mobile verify remain mandatory before merge.

Prior direct-dependent command, with the obsolete spool assertion subsequently removed and its file passing on current HEAD:

ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/agent-hooks/hook-process-capture.test.ts src/main/agent-hooks/hook-script-outside-orca.test.ts src/main/agent-hooks/installer-utils.test.ts src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts src/main/agent-hooks/managed-hook-timeout.test.ts src/main/agent-hooks/posix-hook-json-stdin-reader.test.ts src/main/agent-hooks/remote-hook-service-installers.test.ts src/main/agent-hooks/server-hook-session-binding.test.ts src/main/agent-hooks/server-ingest-remote-codex-question.test.ts src/main/agent-hooks/server-ingest-remote-codex-transcript.test.ts src/main/agent-hooks/server-opencode-writer-observation.test.ts src/main/agent-hooks/server-startup-lifecycle.test.ts src/main/agent-hooks/server-tmux-wire.test.ts src/main/agent-hooks/spool.test.ts src/main/agent-hooks/windows-cmd-hook-command-unicode.test.ts src/main/antigravity/hook-service.test.ts src/main/antigravity/windows-hook-payload-delivery.test.ts src/main/claude/post-compact-hook-command.test.ts src/main/codex/hook-service-wsl-runtime.test.ts src/main/cursor/hook-service.test.ts src/main/grok/hook-service.test.ts src/main/ipc/agent-hooks.test.ts src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts src/main/runtime/structured-agent-cli-writers.test.ts src/shared/agent-hook-owner-presence.test.ts src/shared/agent-hook-spool-drain.test.ts src/shared/agent-hook-spool-read.test.ts src/shared/agent-process-presence-probe.test.ts src/shared/hook-process-root-evidence-reader.test.ts src/wsl-guest/agent-hook-opencode-tui-identity.test.ts --maxWorkers=2

Risk

Level: Medium

Process proof and relay serialization cross execution-host boundaries. Incorrect evidence could retain or retire the wrong owner. Existing root, exit and suspension admission remains shared; remote PIDs are never probed on desktop. Windows and older hook commands retain their unverified fallback, and older peers keep the existing wire fields. Revert the change to restore prior behavior; no saved-data migration is involved.

AI Disclosure

Review

Codex and Claude completed two consecutive clean review rounds. The rebased patches are unchanged according to git range-diff.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Desktop status listeners and the mobile status builder consume the same host-admitted agent/session pair. No mobile ownership logic is added. Folder and connection scoping use existing shared comparisons. Existing background-survivor lifecycle architecture remains outside this issue.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

zhangxaochen and others added 4 commits November 3, 2026 22:07
…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 #37505
…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
Keep ownership at execution-host admission and preserve existing handoffs.

Refs #37505
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

POSIX Antigravity hooks now capture and send process and tmux evidence. Spool handling preserves tmux pane data. Process identity and hook-presence handling now include Antigravity, and tests cover ownership when nested Grok hooks arrive.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to cca29

No confirmed issue prevents merging after normal checks. The reported aggregate checks remain to be completed.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% 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: 4 passed
Check name Status Explanation
Title check Passed The title "fix(agent-hooks): preserve Antigravity ownership across nested hooks" matches the main change. The changeset captures Antigravity process evidence before the hook shell, carries it through …
Linked Issues check Passed Linked issue #37505 is the only active direct target. Its requirement: an Antigravity pane must keep Antigravity as owner while a nested Grok hook runs, until Antigravity exits or foreground moves to …
Out of Scope Changes check Passed Every changed file connects to the Antigravity ownership objective of #37505:
- Process capture (hook-process-capture.ts, runtime-home-hook-command.ts, hook-service.ts, hook-script.ts): needed to obta…
Description check Passed The description follows the repository template and is substantially complete. It has an ELI5, What Changed, Why, a linked issue (Fixes #37505), Visual Proof with before/after images, detailed Testing…
Full details: Title check

Explanation

The title "fix(agent-hooks): preserve Antigravity ownership across nested hooks" matches the main change. The changeset captures Antigravity process evidence before the hook shell, carries it through HTTP, spool replay, and relays, and keeps Antigravity as pane owner while nested Grok hooks report progress. The title is specific, uses conventional commit form, and is under 72 characters. It does not name every file, which is expected.

Full details: Linked Issues check

Explanation

Linked issue #37505 is the only active direct target. Its requirement: an Antigravity pane must keep Antigravity as owner while a nested Grok hook runs, until Antigravity exits or foreground moves to another agent.

Evidence from the whole-PR diff (merge base ab6f6a7 to head cca29c4):

  • hook-process-capture.ts: HOOK_PARENT_CAPTURE (renamed from CLAUDE_HOOK_PARENT_CAPTURE) records ${PPID} before the managed shell runs.
  • hook-service.ts: POSIX Antigravity commands prefix the wrapped command with HOOK_PARENT_CAPTURE, so the captured PID is the Antigravity process.
  • shared/agent-process-presence.ts: readHookAgentProcess now accepts process identity from source 'antigravity' (previously only 'claude'). This supplies the process-backed liveness proof that the issue reports missing.
  • hook-script.ts and shared/agent-hook-spool.ts / hook-stdin-contract.ts: the Antigravity hook request carries agentProcess and tmuxPane through HTTP and spool replay.
  • shared/hook-root-attempts.ts: PreInvocation becomes a turn event, so root admission can be retried at the turn boundary.
  • wsl-guest/agent-hook-envelope-build.ts: agentPresence keeps existing presence fields.

The PR summary names new tests that assert the outcome: server-idle-process-owner.test.ts (parameterized Antigravity owner with nested Grok events, idle or stale-working) and server-antigravity-status-admission.test.ts (replay keeps Antigravity against a nested Grok event; Grok takes over only after process exit or suspension). The PR reports these as passing. I did not run them.

Limits of this assessment: the host admission logic that consumes agentProcess is not in the diff and was not read in full. Renderer and mobile selectors are not changed. The issue's renderer-side cause is addressed by the host admitting the Antigravity status that both consumers read. The PR states that desktop and mobile consume the same admitted agent/session pair. The result relies on that statement and on the cited tests.

Full details: Out of Scope Changes check

Explanation

Every changed file connects to the Antigravity ownership objective of #37505:

  • Process capture (hook-process-capture.ts, runtime-home-hook-command.ts, hook-service.ts, hook-script.ts): needed to obtain Antigravity process proof before the managed shell. The rename from CLAUDE_HOOK_PARENT_CAPTURE to HOOK_PARENT_CAPTURE is a reference update. The shell string is unchanged.
  • Presence and admission (agent-process-presence.ts, hook-root-attempts.ts, agent-hook-envelope-build.ts): needed to carry and admit process-backed ownership.
  • Spool and HTTP transport (hook-stdin-contract.ts, agent-hook-spool.ts): tmuxPane is added to the spool record and restored in the HTTP body. This carries existing hook evidence through startup replay. It supports pane-routing continuity for the same pane. It is not an unrelated feature.
  • Tests: the new Antigravity relay and admission tests support the objective. The spool.test.ts assertion removal is a test-only change. The PR states that the removed assertions are covered by posix-hook-invocation.test.ts and by the current passing spool run. The flaky-test baseline count change (test-timeout-needs-reason, 2 to 1) is a test-infrastructure bookkeeping change tied to posix-hook-invocation.test.ts.

No renderer, mobile, or unrelated feature file appears in the changed-file summary. Reviewers should check the spool.test.ts assertion removal and the tmuxPane transport addition during review. Neither is a concrete scope violation.

Full details: Description check

Explanation

The description follows the repository template and is substantially complete. It has an ELI5, What Changed, Why, a linked issue (Fixes #37505), Visual Proof with before/after images, detailed Testing notes, a Risk section with level Medium and a revert path, the Agent skill upstream boundary checkbox, and a Checklist. The main gaps are that the AI Disclosure section is empty and the Review section is brief. The Testing section also reports that the required full gate did not pass, which the author states openly. The author is a non-maintainer per the Linked Issue requirement, so the linked issue is present and satisfies that rule.

Full details: Docstring Coverage

Explanation

Docstring coverage is 28.57% 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 7 functions across 13 files. (1 skipped: 1 unsupported.)

Resolution

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

Finishing Touches
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
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: add7070b-a1ef-45f3-869d-fd7209df9bea
Commits

Reviewing files that changed from the base of the PR and between ad5657a and cca29c4.

Files selected for processing: 15
  • config/flaky-test-pattern-baseline.txt
  • src/main/agent-hooks/hook-process-capture.ts
  • src/main/agent-hooks/hook-stdin-contract.ts
  • src/main/agent-hooks/runtime-home-hook-command.ts
  • src/main/agent-hooks/server-antigravity-status-admission.test.ts
  • src/main/agent-hooks/server-hook-root-provenance.test.ts
  • src/main/agent-hooks/server-idle-process-owner.test.ts
  • src/main/agent-hooks/spool.test.ts
  • src/main/antigravity/hook-script.ts
  • src/main/antigravity/hook-service.ts
  • src/main/antigravity/posix-hook-invocation.test.ts
  • src/shared/agent-hook-spool.ts
  • src/shared/agent-process-presence.ts
  • src/shared/hook-root-attempts.ts
  • src/wsl-guest/agent-hook-envelope-build.ts
Files with no reviewable changes: 1
  • src/main/agent-hooks/spool.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 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.

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

2 participants