Skip to content

fix(agent-hooks): make agent hooks status report the SSH hosts that run the agents - #8848

Closed
xianjianlf2 wants to merge 17 commits into
stablyai:mainfrom
xianjianlf2:fix/ssh-agent-hooks-status-host-aware-8711
Closed

xianjianlf2 wants to merge 17 commits into
stablyai:mainfrom
xianjianlf2:fix/ssh-agent-hooks-status-host-aware-8711

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When an agent runs over SSH, hook status should describe that remote computer. An old successful check must not make a reconnecting host look healthy before its new check finishes.

What Changed

  • Preserve per-agent remote hook installation outcomes and expose active SSH hosts through the runtime agentHooks.status method and orca agent hooks status.
  • Include hosts whose report is not ready, mark a new check as unavailable, and report an empty supported-agent detection as skipped.
  • Tie background report ownership to the current SSH multiplexer and provider generation. A check may finish after reconnect returns; results from superseded connections are still discarded.
  • Retain the older-runtime method_not_found fallback with explicit remote unavailability. Other reachable-runtime errors are not converted into a successful local-only result.

Why

Local hook installation cannot establish the state of remote hooks. Reconnect also releases its attempt token before background installation necessarily finishes, which previously dropped valid late results and could leave stale status visible.

Linked Issue

Fixes #8711 (the diagnostic portion; remote installation itself already exists).

Visual Proof

N/A — CLI diagnostics and runtime state plumbing; no rendered UI change. No live SSH or Windows proof is claimed.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

On macOS with ORCA_BACKGROUND_LAUNCH=1 (also verified on the required Node 24 runtime):

  • pnpm test src/main/ssh/ssh-relay-session.test.ts src/main/ssh/ssh-relay-session-agent-hook-report.test.ts src/main/ssh/ssh-relay-session-managed-hooks.test.ts src/main/ipc/ssh.test.ts src/main/runtime/rpc/methods/agent-hooks.test.ts src/cli/handlers/agent-hooks.test.ts: 138 tests passed across 10 files, including the adjacent CLI load-boundary, isolated Codex-home, managed-hook-runtime, and relay-installer suites.
  • New regressions cover empty detection and a pending reconnect check that finishes after reconnect returns; both failed before the fix. Existing overlapping-reconnect coverage verifies old connections cannot overwrite new reports.
  • pnpm tc:node, pnpm tc:cli, formatting, changed-code quality checks, and git diff --check passed.
  • Merged current upstream main and retained its profile-state storage and remote-selection checks. After adapting old test fixtures to the current type-assertion rules, reran the two affected suites: 47 passed.
  • Full build/full suite and physical SSH/Linux/Windows execution were not run in this update.

AI Disclosure

Originally developed with Claude Code; this follow-up used OpenAI Codex for diagnosis, code, regression tests, and self-review.

Review

Reviewed report ownership across reconnect/disconnect, disabled and unsupported hosts, empty detection, and mixed-version fallback. The follow-up reuses the existing unavailable state without adding required wire fields or changing hook installation permissions. Host state remains owned by its execution host; the guards add constant-time identity checks.

Agent skill upstream boundary

  • Not applicable; no agent-skill installation code or upstream skill material changed.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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
  • Full lint, typecheck, test, and build pass; focused local checks are listed above, broader coverage is left to CI

Author

X: @mark86202384100

October 8 upstream refresh

Merged current upstream main and regenerated the RPC parameter catalog. The hook visibility regression now lives in a separate IPC test file to stay within the existing file-size limit. The initial 102 tests across 7 suites pass; after the test split, both affected IPC suites were rerun successfully. Full type checking, the follow-up node type check, formatting, and focused lint pass. Validation used ORCA_BACKGROUND_LAUNCH=1; live SSH validation was not repeated. This refresh was AI-assisted.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds structured remote agent hook installation reports to SSH relay sessions, covering installed, partial, skipped, and error states. Exposes local and remote hook statuses through a new runtime RPC method. Updates the CLI status command to display remote host reports and distinguish runtime-backed results from offline fallback results. Adds tests covering SSH installation outcomes, RPC responses, and CLI runtime availability paths.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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
Linked Issues check ✅ Passed The description links the pull request to issue #8711 and clearly explains which diagnostic portion of that issue this change addresses.
Out of Scope Changes check ✅ Passed The changes remain within scope. They report remote hook installation status and errors without adding new remote installation locations or implementing the separate CODEX_HOME materialization proposa…
Title check ✅ Passed The title clearly and concisely describes the main change: reporting SSH hosts that run agents in agent hooks status.
Description check ✅ Passed The description includes all required sections, explains the user-visible behavior and rationale, links issue #8711, documents testing and limitations, and completes the checklist with focused validat…
  • Fix all pre-merge checks with AI

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 67a64825-0e56-4c8a-af0d-f2d05af7b4df

📥 Commits

Reviewing files that changed from the base of the PR and between 9e2c63e and 842dc964e345185b5db20c45b2b79ec0dad965fa.

📒 Files selected for processing (9)
  • src/cli/handlers/agent-hooks.test.ts
  • src/cli/handlers/agent-hooks.ts
  • src/main/ipc/ssh.ts
  • src/main/runtime/rpc/methods/agent-hooks.test.ts
  • src/main/runtime/rpc/methods/agent-hooks.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/ssh/ssh-relay-session-agent-hook-report.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/shared/agent-hook-types.ts

Comment thread src/cli/handlers/agent-hooks.ts Resolved
Comment thread src/main/ssh/ssh-relay-session.ts Resolved
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Addressed both review points in the latest push:

  • agent hooks status no longer swallows an RPC failure from a reachable runtime — only an unreachable runtime falls back to the local-only report; RPC failures now surface with a nonzero exit (test added).
  • registerProviders' existing shouldContinue token is threaded into the remote hook install, and the report is committed only while that reconnect attempt still owns the session, so a late-resolving aborted attempt can't overwrite a newer attempt's report.

@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@brennanb2025
brennanb2025 force-pushed the fix/ssh-agent-hooks-status-host-aware-8711 branch from 0180edd to 63a23b3 Compare July 21, 2026 00:37
@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for the contribution — I rebased this onto current main and adapted the implementation to the newer relay-local hook installer, so SSH setup still uses one control-channel round trip while returning the detailed per-agent results needed for truthful host-aware status. I also kept reachable-runtime failures from falling back to a misleading local green, made offline text explicitly say SSH status is unavailable, and fenced late reconnect results so they cannot overwrite the current session report. Focused coverage now includes success/partial/error/skip paths, RPC and CLI behavior, and overlapping reconnects; the targeted suite (57 tests), node/CLI typechecks, touched-file lint, max-lines ratchet, and relay builds all pass.

@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/cli/handlers/agent-hooks.test.ts (1)

224-225: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating output assertions for consistency.

This test only checks console.log for the error message, whereas the similar test above (lines 175-179) checks both console.error and console.log. For consistency and robustness against potential changes in reportCliError, consider using the same combined check here.

♻️ Proposed refactor
     expect(process.exitCode).toBe(1)
-    expect(vi.mocked(console.log).mock.calls.flat().join('\n')).toContain('status transport failed')
+    const printed = [
+      ...vi.mocked(console.error).mock.calls.flat(),
+      ...vi.mocked(console.log).mock.calls.flat()
+    ].join('\n')
+    expect(printed).toContain('status transport failed')

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b5d38b75-fc45-44bf-bcb1-39c1b9c3c8c1

📥 Commits

Reviewing files that changed from the base of the PR and between 0180edd212932618489ffab048ef921779030417 and 63a23b3974961ce7cc53f42c8400a042b9d85cfb.

📒 Files selected for processing (2)
  • src/cli/handlers/agent-hooks.test.ts
  • src/cli/handlers/agent-hooks.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/handlers/agent-hooks.ts

@xianjianlf2
xianjianlf2 force-pushed the fix/ssh-agent-hooks-status-host-aware-8711 branch from 63a23b3 to 2f96e6c Compare July 22, 2026 07:45
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Rebased this onto current origin/main and resolved the relay-session conflict by keeping both the newer pending PTY reattach state and this PR's remote agent-hook install report state.

Local validation:

  • source ~/.nvm/nvm.sh && nvm use 24 && pnpm install --frozen-lockfile
  • pnpm exec vitest run --config config/vitest.config.ts src/cli/handlers/agent-hooks.test.ts src/main/runtime/rpc/methods/agent-hooks.test.ts src/main/ssh/ssh-relay-session-agent-hook-report.test.ts src/main/ssh/ssh-relay-session.test.ts src/main/ssh/ssh-relay-session-agent-hooks.integration.test.ts src/main/ssh/ssh-relay-session-incarnation.test.ts src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts src/relay/managed-hook-installer.test.ts (8 files / 68 tests)
  • pnpm typecheck:node
  • pnpm typecheck:cli

@xianjianlf2
xianjianlf2 force-pushed the fix/ssh-agent-hooks-status-host-aware-8711 branch from 2f96e6c to 96f7a54 Compare July 27, 2026 04:46
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Rebased this onto current origin/main again and added JSDoc around the new remote hook status API surfaces so the docstring coverage warning has something concrete to measure:

  • CLI remote report formatting/runtime status fetch
  • runtime RPC method registration
  • SSH IPC report collection
  • relay session report getter/installer/recency guard
  • relay installer registration and shared result/report types

Validation after the rebase:

  • pnpm exec oxlint on touched files
  • focused vitest suite: 8 files / 68 tests
  • pnpm typecheck:node
  • pnpm typecheck:cli

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Also picked up the remaining low-priority test nit: the runtime transport failure assertion now checks combined stderr/stdout output, matching the nearby test style.

Validation:

  • pnpm exec vitest run --config config/vitest.config.ts src/cli/handlers/agent-hooks.test.ts — 1 file / 8 tests
  • touched-file pnpm exec oxlint

@xianjianlf2

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

xianjianlf2 and others added 6 commits August 31, 2026 11:58
…un the agents

Codex hooks on an SSH worktree live on the remote host, but `orca agent
hooks status` only inspected the local managed install and reported
`codex: installed` even when the remote install had failed — the exact
configuration where status hooks go dead (stablyai#8711).

- Record each relay session's remote managed-hook install outcome
  (installed/partial/skipped/error plus per-agent statuses) instead of
  discarding the results after a console.warn.
- Expose the reports through a new `agentHooks.status` runtime RPC.
- `orca agent hooks status` now asks the running runtime and prints a
  per-SSH-host section; when the runtime is unreachable (so no SSH agents
  can be running either) it falls back to the local-only report.

Fixes stablyai#8711

Co-Authored-By: Claude Fable 5 <[email protected]>
…port writes by reconnect ownership

Review feedback:
- A reachable runtime whose agentHooks.status RPC fails was silently
  converted into a local-only report — which can read `installed` while
  SSH host state is unknown, the exact misleading green this command
  exists to prevent. Only an unreachable runtime falls back to
  local-only now; RPC failures surface with a nonzero exit.
- Thread registerProviders' shouldContinue into the remote hook install
  so an aborted reconnect that resolves late cannot overwrite a newer
  attempt's install report with stale data.

Co-Authored-By: Claude Fable 5 <[email protected]>
@xianjianlf2
xianjianlf2 force-pushed the fix/ssh-agent-hooks-status-host-aware-8711 branch from ab682ac to 25f51ca Compare August 31, 2026 04:04
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Rebased all five existing commits onto the latest main and resolved the intervening agent-hook/runtime refactors.

The updated branch preserves current-main behavior for:

  • positively detected/enabled remote-agent allowlists;
  • non-blocking SSH provider registration;
  • WSL Codex hook preparation; and
  • current SSH AI Vault/session APIs.

It layers the host-aware reporting on top: the relay returns per-agent install statuses, each active SSH session records its current report with reconnect ownership protection, the runtime exposes local + remote reports, and the CLI distinguishes offline/unavailable SSH state from a clean remote result.

Validation:

  • oxlint passed for all 15 changed TypeScript files
  • git diff --check passed
  • 4 focused suites passed: 36 tests total (CLI, runtime RPC, managed-hook runtime, relay installer)
  • the two SSH relay-session suites are blocked locally during Electron module collection by this workspace's incomplete dependency install; they do not reach test execution. CI will run them against a clean install.

Current head: 25f51ca54.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds host-aware managed-hook diagnostics by retaining per-session SSH installation reports and exposing them through a runtime RPC to the CLI.

  • Extends the relay installation result with remote home and per-agent statuses.
  • Records installed, partial, skipped, and error outcomes on SSH relay sessions.
  • Adds agentHooks.status and runtime-aware CLI text and JSON output.
  • Preserves local-only reporting when the runtime is unavailable.

Confidence Score: 4/5

The active-host omission should be fixed before merging because it can leave the status command green while an SSH host remains unchecked or pending.

The new collector drops active sessions with null reports, and reachable installation paths can retain null long enough—or indefinitely after empty agent detection—for the CLI to omit the host whose status it is intended to diagnose.

Files Needing Attention: src/main/ipc/ssh.ts and src/main/ssh/ssh-relay-session.ts

Important Files Changed

Filename Overview
src/main/ipc/ssh.ts Adds active-session report collection, but silently excludes active hosts whose report is not yet available.
src/main/ssh/ssh-relay-session.ts Records detailed installation outcomes with reconnect ownership fencing, while some reachable branches still leave the report null.
src/cli/handlers/agent-hooks.ts Adds runtime-backed host-aware output and correctly surfaces reachable-runtime RPC failures.
src/main/runtime/rpc/methods/agent-hooks.ts Adds a straightforward RPC returning local and collected active SSH installation reports.
src/main/agent-hooks/managed-hook-runtime.ts Extends the managed-hook result contract with the resolved home and detailed installer statuses.
src/shared/agent-hook-relay.ts Defines the expanded relay result shape consumed by the SSH session.
src/shared/agent-hook-types.ts Defines remote host report states but does not include a pending or unknown state.

Sequence Diagram

sequenceDiagram
  participant CLI as agent hooks status
  participant Runtime as Runtime RPC
  participant Main as SSH session registry
  participant Session as SshRelaySession
  participant Relay as Remote relay
  CLI->>Runtime: agentHooks.status
  Runtime->>Main: list active SSH reports
  Main->>Session: getAgentHookInstallReport()
  Session-->>Main: report or null
  Main-->>Runtime: local and remote reports
  Runtime-->>CLI: host-aware status
  Session->>Relay: installManagedHooks
  Relay-->>Session: per-agent statuses
  Session->>Session: record latest report
Loading

Reviews (1): Last reviewed commit: "fix(agent-hooks): align status RPC with ..." | Re-trigger Greptile

Comment thread src/main/ipc/ssh.ts Resolved
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thank you for this thorough work, @xianjianlf2! The legacy SSH relay it built on (relay sessions and the relay hook installer) has been removed; SSH hosts now run Orca's managed remote server, which installs hooks when it starts (#27319). The diagnostic idea still applies, so I've carried it over to #27399 with credit to you.

@OrcaWin OrcaWin closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

4 participants