orca icon indicating copy to clipboard operation
orca copied to clipboard

Only install agent hooks for installed CLIs

Open brennanb2025 opened this issue 5 months ago • 2 comments

Summary

This changes managed agent hook auto-install so Orca only mutates hook config for an agent when the matching CLI is positively present on that host, or when a configured command override resolves. Disabling hooks still removes Orca-managed hook entries even if the CLI is gone.

This does not add a manual force-install path, and config status reads remain authoritative rather than reporting a skipped install attempt as current config state.

Design Approach

The implementation adds shared managed-hook target descriptors derived from the TUI agent config, then uses a main-process manifest to derive installers, removers, status readers, and remote support. Local installs use a bounded PATH/override presence detector; SSH installs ask the relay to detect remote CLI presence before opening SFTP. Codex source-control launch prep also routes through the same single-agent presence gate so it cannot bypass startup/settings gating.

Design Review

Design review completed clean. The chosen shape is the standard pattern for this class of problem: gate the managed-config write on positive CLI presence, but keep cleanup ungated so stale Orca-managed entries stay removable even after a CLI is uninstalled. Direct config mutation (rather than a launch-time wrapper) is required because Orca's status hooks must already be present for agents launched outside Orca's own spawn path. Presence-gating the write is a deliberate improvement over prior-art managers that mutate agent config unconditionally.

Implementation

Implemented local, Settings, runtime RPC, offline CLI, Codex launch-prep, SSH, and relay presence-gated install paths. Remote hook install is best-effort after provider registration so SSH becomes usable even if relay PATH probing is slow or unavailable. One deviation from the initial design is intentional: SSH provider registration no longer waits for remote hook install because the relay login-shell PATH probe can be slow; tests verify provider registration continues and hook install remains best-effort.

Completeness Verification

Completeness verification first found the offline CLI async regression, which is fixed and covered. A later final review found Codex launch prep could still install hooks directly; that is fixed by routing through installManagedAgentHooks(..., { agents: ['codex'] }). Final targeted verification reported no blockers.

Headline Status

Implemented. Startup, Settings, runtime settings updates, offline CLI, Codex model/commit-message launch prep, and SSH remote setup now avoid installing managed hooks without positive CLI presence. Cleanup remains ungated.

App Consistency

Compared desktop startup, Settings toggle, CLI orca agent hooks on/off/status, runtime paired-client settings update, Codex source-control generation/model discovery, web fallback/status shape, and SSH startup. The PR fixes the previous mismatch where startup/settings/SSH installed all hook configs regardless of installed CLIs, and preserves config-authoritative status reads plus ungated removal.

Risks And Non-Goals

Remaining gaps: no real Windows runner evidence yet; Windows behavior is covered deterministically for PATHEXT and path parsing. Live SSH Linux behavior was validated with Docker. No visible UI behavior changed, so no screenshot evidence is included.

Tradeoffs

  • Pre-probe vs. self-probing remote hooks (SSH): we probe remote CLI presence (a bounded relay login-shell PATH lookup) before writing any remote hook config, so absent CLIs never get config written on the remote — consistent with the local goal. The cost is one bounded relay round-trip plus the deferral/cancellation machinery. The alternative — write config unconditionally with a self-probing hook command that no-ops when the CLI is missing — would delete that machinery but reintroduce unconditional remote config writes. We chose "don't write config for CLIs that aren't there" over minimal machinery.
  • SSH startup responsiveness vs. first-prompt status: remote hook install is best-effort and runs after provider registration instead of blocking it, so SSH terminals/filesystem/git come online quickly even when the PATH probe is slow or unavailable. The cost is that a remote agent pane spawned in the very first moment may miss status on its first prompt until the background install lands. We chose responsiveness.
  • Launch-prep: promotion always runs, config write stays gated. On a launch where the CLI is genuinely present but the main-process probe can't see it (a cached shell-PATH-hydration failure, or a relative command override that resolves only in the pane's shell), the managed hook config may not be (re)written that launch — but #7896 approval promotion always runs, so in-Orca /hooks approvals can never be silently swept by stale-trust cleanup. We accept a possible missed config refresh over risking approval loss.
  • File-presence probe, not a CLI spawn: detection is a PATH + executable-bit check (PATHEXT-aware on Windows), which is fast and side-effect-free but can't see CLIs reachable only via shell aliases/functions or a relative-path override. Those resolve to unknown, which never installs and never falsely removes — detection fails safe.
  • Cleanup stays ungated: disabling hooks always removes Orca-managed entries even when the CLI is gone, so removal may touch a config file for an absent CLI — necessary to clean up stale entries a since-uninstalled CLI left behind.

Performance

Perf audit passed. Local detection scans deduped PATH entries against deduped executable candidates; Codex launch prep uses a single-agent filtered detector; SSH adds one bounded relay request and avoids SFTP when no remote CLI is found. No polling, timers, listener leaks, per-pane/session fanout, or telemetry cardinality growth were introduced.

Code Review Loop

The review loop found and fixed: offline CLI override propagation, runtime settings.update awaiting hook application, startup race handling when hooks are disabled during async detection, CLI typecheck coverage for new hook modules, relay login-shell timeout coverage, and the Codex direct-install sibling path. Final targeted review returned clean.

Product Validation

Brennan's PR process validation result: land after fixing full lint. The full lint blocker was an unrelated exhaustive-switch default arm in SourceControlActionRepoOverrideNote.tsx; it was removed and pnpm run lint now passes.

Live SSH validation was run against a Docker Linux SSH target through Electron. The remote had a fake codex CLI and no other agent CLIs; backing remote state showed only Codex hook config was installed, and absent agent config dirs remained absent. Offline CLI smoke with a temp user data path and no agent CLIs returned 14/14 skipped statuses with cli_not_found, then persisted hooks disabled on agent hooks off.

Checks

  • pnpm run typecheck
  • pnpm run lint
  • pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/managed-agent-hook-manifest.test.ts src/main/agent-hooks/local-agent-cli-presence.test.ts src/main/agent-hooks/managed-agent-hook-controls.test.ts src/main/agent-hooks/install-telemetry.test.ts src/main/agent-hooks/remote-managed-hook-installers.test.ts src/main/ssh/ssh-relay-session.test.ts src/relay/agent-hook-cli-presence.test.ts src/relay/agent-hook-cli-presence-timeout.test.ts src/cli/handlers/agent-hooks.test.ts src/main/runtime/rpc/methods/client-ui.test.ts src/main/runtime/orca-runtime.test.ts src/main/text-generation/commit-message-agent-environment.test.ts
  • pnpm run check:reliability-gates
  • pnpm build:relay
  • git diff --check
  • Real offline CLI smoke with temp ORCA_USER_DATA_PATH
  • Live Electron + Docker SSH validation

Post-PR Stabilization

Completed. I ran the required quiet wait, checked PR review comments, issue comments, reviews, and checks, then waited again while the pending verify check finished. Required checks pass: verify, native-smoke (ubuntu-22.04), native-smoke (windows-latest), and track-community-pr; matrix packaging jobs were skipped by workflow conditions.

CodeRabbit later posted five inline comments; all are replied to and resolved. Three were fixed in 08cf8433d: agents omitted from the remote presence map now report remote_presence_unavailable instead of cli_not_found; installManagedHooksOnRemote re-checks cancellation after the SFTP open await before mutating remote config; and relative (non-absolute, non-home) command overrides report unknown presence instead of being probed against the main process CWD. Each fix has a regression test. Two were declined with rationale: the offline CLI cannot reuse the main-process telemetry recorder because the telemetry client imports electron, and the manifest invariant assertion stays CI-enforced because the manifest is static and a runtime throw would conflict with fail-open startup.

Follow-up Review Fixes

An adversarial re-review landed three fixes (commit 6b2eb9cd0):

  1. Codex launch-prep no longer drops #7896 approval promotion. Routing launch-prep through the presence gate meant that when the probe couldn't see codex (cached PATH-hydration failure, or a relative command override reporting unknown), install() — and with it the approval promotion — was skipped even though codex was actively launching; the disabled path still promoted, so the asymmetry was backwards. Launch-prep now always runs promotion and only presence-gates the managed-config write. Guarded by src/main/codex/codex-launch-hook-upkeep.test.ts.
  2. Removed a duplicated, now-dead installer loop. The refactor left an identical runManagedHookInstallers/errorStatus in both install-telemetry (electron-coupled, no remaining production callers) and the CLI-safe managed-agent-hook-controls. Deleted the dead copy, kept the single CLI-safe one, repointed the telemetry test at recordManagedHookInstallFailure directly, and added fail-open loop coverage where the loop actually lives.
  3. Honest Windows-remote presence. The relay now reports unknown (not a false missing) on a Windows relay host, and the unused unsupported_remote_platform skip reason was removed.

Checks re-run: pnpm run typecheck, targeted vitest (666 passing across the gate suite), pnpm run check:reliability-gates, pnpm run check:max-lines-ratchet, oxlint on changed files, git diff --check.

brennanb2025 avatar Jul 06 '26 02:07 brennanb2025

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

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: 7d678104-690e-4d1c-9315-8a4215fb250f

📥 Commits

Reviewing files that changed from the base of the PR and between 6b2eb9cd0b7c3c3a600d1ea945f4840ce3aef824 and 881c7884e9fa790be2f40bcb4108f162fda46721.

📒 Files selected for processing (5)
  • config/tsconfig.cli.json
  • src/cli/handlers/agent-hooks.test.ts
  • src/cli/handlers/agent-hooks.ts
  • src/main/codex/hook-service.ts
  • src/main/index.ts
✅ Files skipped from review due to trivial changes (1)
  • config/tsconfig.cli.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/main/codex/hook-service.ts
  • src/cli/handlers/agent-hooks.test.ts
  • src/cli/handlers/agent-hooks.ts
  • src/main/index.ts

📝 Walkthrough

Walkthrough

This change adds shared managed-agent target and executable-token utilities, local and relay-side CLI presence detection, and a manifest-driven hook installation pipeline. Local and remote installers now return structured per-agent statuses with skip reasons and error handling. CLI, IPC, runtime, startup, Codex launch, and SSH relay flows use asynchronous presence-gated installation. Tests cover PATH probing, overrides, timeout cleanup, manifest alignment, status reporting, cancellation, and remote installation behavior. Configuration updates register the new compilation inputs and reliability gate.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.57% 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 is concise and accurately summarizes the main change: gating agent hook installs on CLI presence.
Description check ✅ Passed The description is thorough and covers summary, implementation, testing, and review, but it does not follow the template’s Screenshots, Security Audit, and Notes sections.
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.
✨ Finishing Touches
📝 Generate docstrings
  • [ ] Create stacked PR
  • [ ] Commit on current branch

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[bot] avatar Jul 06 '26 02:07 coderabbitai[bot]

Possibly relevant WSL hook-transport edge case from #7565 / #7091.

This PR gates managed hook installation on positive CLI presence. That is useful, but a separate WSL failure mode now looks confirmed: a WSL-spawned agent can have the managed hook/extension installed and launched correctly, but still be unable to report status because the injected hook receiver endpoint points at Windows localhost.

Observed with OMP on Windows desktop app + WSL runtime:

  • OMP launched with Orca's managed --extension <orca-agent-status.ts>.
  • OMP process env included ORCA_AGENT_HOOK_PORT, ORCA_AGENT_HOOK_TOKEN, ORCA_PANE_KEY, ORCA_TERMINAL_HANDLE, and ORCA_AGENT_LAUNCH_TOKEN.
  • From inside WSL, curl http://127.0.0.1:$ORCA_AGENT_HOOK_PORT/hook/omp failed with connection refused / 000.
  • The same payload sent via Windows curl.exe returned 204.
  • After the successful Windows-side POST, the OMP agent appeared/updated in the sidebar.

So for WSL agent hooks, presence/install success is not enough; the injected endpoint must be reachable from the WSL process. If this PR touches hook launch/env validation, it would be worth adding WSL coverage for endpoint reachability from the actual spawned agent environment.

euclodius avatar Jul 06 '26 12:07 euclodius