Skip to content

fix(agent-hooks): fail closed without detected agent allowlist - #11676

Merged
brennanb2025 merged 3 commits into
stablyai:mainfrom
bbingz:fix/skip-hooks-without-cli
Aug 13, 2026
Merged

brennanb2025 merged 3 commits into
stablyai:mainfrom
bbingz:fix/skip-hooks-without-cli

Conversation

@bbingz

@bbingz bbingz commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

This hardens the remaining hole after #11442 so a relay/SSH/WSL install path cannot recreate config homes for uninstalled agents.

Closes #11641

Test plan

  • vitest run focused suites:
    • remote-hook-service-installers.test.ts
    • managed-hook-local-filesystem.test.ts
    • managed-agent-hook-controls.test.ts
    • managed-hook-installer.test.ts (relay)
  • Independent Grok review: APPROVED
  • CI green

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a security hole where an omitted or empty agents allowlist in installRemoteManagedAgentHooks previously meant "install for every agent" (fail-open), allowing relay/SSH/WSL install paths to recreate config homes for uninstalled CLIs. It now fails closed: both installRemoteManagedAgentHooks and installManagedHooks short-circuit and return empty results when no agents are provided.

  • remote-managed-hook-installers.ts: Replaces the null-means-all-agents sentinel with an early return [] when options?.agents is omitted or empty; simultaneously exports REMOTE_MANAGED_HOOK_INSTALLER_AGENTS for use in full-install tests.
  • managed-hook-runtime.ts: Adds a symmetric early-exit before any home/host probes when the agents array is empty, providing a second layer of defense.
  • Test files: Updated existing full-install tests to pass the new explicit allowlist constant, and adds a new regression test asserting no filesystem mutations occur when agents are omitted/empty.

Confidence Score: 5/5

The change is a well-contained fail-closed fix with layered guards and direct regression coverage; safe to merge.

The null-means-all-agents hole is closed at two independent layers (runtime and installer), both new guards are exercised by updated or new tests, and the relay layer already normalised missing agents to [] before this PR. All updated tests now pass an explicit allowlist rather than relying on the old implicit default, so the API contract is clearly documented in the test suite.

Files Needing Attention: No files require special attention. The runtime short-circuit in managed-hook-runtime.ts is only indirectly exercised through relay tests that mock the function, but the guard is a single-line length check on an already-validated array.

Important Files Changed

Filename Overview
src/main/agent-hooks/remote-managed-hook-installers.ts Core fix: replaces null-sentinel install-all pattern with explicit empty-set early return; exports REMOTE_MANAGED_HOOK_INSTALLER_AGENTS for test parity.
src/main/agent-hooks/managed-hook-runtime.ts Adds early-exit guard before home/host probes when agents list is empty; passes resolved agents array through to avoid re-reading options downstream.
src/main/agent-hooks/remote-hook-service-installers.test.ts Adds regression test for omitted/empty allowlist; updates the full-install and abort tests to use the explicit REMOTE_MANAGED_HOOK_INSTALLER_AGENTS constant.
src/main/agent-hooks/managed-hook-local-filesystem.test.ts Updates cold/warm install and corrupt-config tests to pass explicit agents allowlist, aligning with the new fail-closed API contract.
src/main/agent-hooks/wsl-hook-relay-manager.test.ts Updates WSL integration test to pass the explicit agents allowlist constant when exercising a full install against the real WSL guest home.

Sequence Diagram

sequenceDiagram
    participant SSH as ssh-relay-session
    participant Relay as managed-hook-installer (relay)
    participant Runtime as installManagedHooks (runtime)
    participant Installer as installRemoteManagedAgentHooks

    SSH->>SSH: detectedManagedHookAgents()
    alt "agents.length === 0"
        SSH-->>SSH: return (no relay request)
    else agents present
        SSH->>Relay: "AGENT_HOOK_INSTALL_MANAGED_HOOKS_METHOD {agents}"
        Relay->>Relay: readAgents(params) → [] if omitted
        Relay->>Runtime: "installManagedHooks({agents})"
        alt "agents.length === 0 [NEW guard]"
            Runtime-->>Relay: "{installers:0, errors:0}"
        else agents present
            Runtime->>Runtime: resolveRelayGrokHome / readManagedHookHostIdentity
            Runtime->>Installer: "installRemoteManagedAgentHooks(fs, home, {agents})"
            alt "allowedAgents.size === 0 [NEW guard]"
                Installer-->>Runtime: []
            else agents present
                loop for each agent in REMOTE_MANAGED_HOOK_INSTALLERS
                    alt agent in allowedAgents
                        Installer->>Installer: install(sftp, remoteHome, options)
                    end
                end
                Installer-->>Runtime: AgentHookInstallStatus[]
            end
            Runtime-->>Relay: "{installers, errors}"
        end
        Relay-->>SSH: "{installers, errors}"
    end
Loading

Reviews (1): Last reviewed commit: "fix(agent-hooks): fail closed without de..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 805a71f9-01bc-44b1-8081-7c88b5ed56cd

📥 Commits

Reviewing files that changed from the base of the PR and between 150cc6f and f9152fa.

📒 Files selected for processing (6)
  • src/main/agent-hooks/managed-hook-local-filesystem.test.ts
  • src/main/agent-hooks/managed-hook-runtime.test.ts
  • src/main/agent-hooks/managed-hook-runtime.ts
  • src/main/agent-hooks/remote-hook-service-installers.test.ts
  • src/main/agent-hooks/remote-managed-hook-installers.ts
  • src/main/agent-hooks/wsl-hook-relay-manager.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/agent-hooks/wsl-hook-relay-manager.test.ts
  • src/main/agent-hooks/managed-hook-local-filesystem.test.ts
  • src/main/agent-hooks/remote-hook-service-installers.test.ts
  • src/main/agent-hooks/remote-managed-hook-installers.ts
  • src/main/agent-hooks/managed-hook-runtime.test.ts

📝 Walkthrough

Walkthrough

Managed hook installation now fails closed when the agent allowlist is omitted or empty. The runtime passes a normalized agent array to remote installation. The remote installer avoids filesystem and configuration mutations without an allowlist. Local filesystem, remote installer, cancellation, and WSL tests now pass the shared managed-agent list explicitly. Tests also verify fail-closed behavior, abort handling, and allowlisted Claude installation.

Mergeability Score: ⚪ Minimal · up to f9152

The change prevents hook installation when no agents are explicitly allowlisted while preserving intentional full-install paths through explicit configuration; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, rationale, linked issue, and tests, but omits several required template sections and checklist details. Complete the required template sections, including ELI5, What Changed, Why, Visual Proof with N/A if applicable, Review, Checklist, and AI Disclosure when required.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fail-closed behavior when no agent allowlist is detected.
Linked Issues check ✅ Passed The changes address issue #11641 by preventing hook installation and configuration-directory creation when no agents are allowlisted.
Out of Scope Changes check ✅ Passed The source and test changes directly support the allowlist fail-closed behavior and regression coverage described in issue #11641.

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.

@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@brennanb2025

Copy link
Copy Markdown
Contributor

Verification — land-as-is (0 blockers), reviewed at dc758247e0 for #11641.

Independent code review (two reviewers) + a perf audit + a live SSH-relay reproduction rig all agree the change is correct and strictly narrowing.

Live rig — disposable Linux SSH host, isolated HOME, controlled login-shell PATH. Drove the exact desktop→relay RPCs (preflight.detectAgents → agent_hook.installManagedHooks) against relay bundles built from both main and this head, each byte-verified against its source:

case main this PR
empty allowlist (agents: []) installers:0, but spawns a login-shell GROK_HOME probe + creates the ~/.orca lock dir installers:0 — no probe, no ~/.orca
omitted allowlist (old-desktop skew) installers:0 (+ probe / ~/.orca) installers:0
present (agents:['claude']) writes .claude/settings.json byte-identical file
reinstall on reconnect idempotent idempotent
malformed agent id rejected (invalid_managed_hook_agents) rejected

No config write differs on any path — the change only ever narrows installation. On the empty/omitted path it additionally drops a login-shell subprocess (8s timeout ceiling) and a lock mkdir per session/reconnect. Windows remotes bail before any RPC; WSL reaches the same guarded leaf.

Gates at dc758247e0: the new fail-closed test is non-vacuous (revert the leaf → red; restore → green); 43/43 across the four touched agent-hooks suites; typecheck clean; oxlint incl. the type-aware code-quality gate clean.

One non-blocking nit (both reviewers): the runtime-level early return in managed-hook-runtime.ts that skips the probe/lock isn't pinned by a unit test — its side-effect elimination is rig-verified, and the config-mutation property is covered by the leaf test, so reverting only that hunk stays green. Optional coverage hardening; tracked for a follow-up alongside the pre-existing remote "unknown vs. empty" observability gap. Nothing requested here.

This is a verification note, not an approval or merge — the only remaining item is the maintainer-gated CI workflow run.

@bbingz

bbingz commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@brennanb2025 following up on your note that the only remaining item is the maintainer-gated CI workflow: could you hit "Approve and run workflows" on the PR Checks run for dc758247e0? The head is unchanged since your verification — deliberately so.

@brennanb2025

Copy link
Copy Markdown
Contributor

Electron + live-SSH validation — closes the one gap left open in my earlier verification. Still land-as-is at dc758247e0, 0 blockers.

My previous comment noted the Electron app-level check was unverified (the isolated dev profile had wedged during ssh.connect). That is now done end-to-end through the real app, and it passes.

Setup: Orca dev build launched from the PR head (identity verified over CDP: pr-11676-review @ dc758247e0), attached to a throwaway Linux SSH container as a real remote host, with a real git repo and a real Orca worktree created on it. Relay actually deployed and running on the remote — bundle 0.1.0+b8b28000b304, i.e. this head.

Negative case — no agent CLI installed on the remote (this is #11641). Run in Orca's own remote terminal on the SSH host:

=== PR 11676 / issue 11641: NO agent CLI installed on this host ===
detected agents: NONE

--- agent config dirs created in HOME by Orca connect: ---
(none) -- FAIL-CLOSED OK: 0 of 14 agent homes written

.bashrc  .cache  .npm  .orca  .orca-relay  .orca-remote  .profile  .ssh

Zero of the 14 agent config homes were created. .orca there contains only sessions/ from the terminal I opened — there is no .orca/agent-hooks and no install-lock, confirming the installer never ran rather than running and writing nothing.

Positive case — exactly one agent detected. With only claude on the login-shell PATH, reconnecting installed precisely that one and nothing else:

--- PR 11676: agent config dirs in remote HOME ---
PRESENT: .claude
--- only detected agent should appear above ---
/opt/agent-stubs/claude

~/.claude/settings.json got the real UserPromptSubmit/Stop hooks wired to ~/.orca/agent-hooks/claude-hook.sh, and the other 13 agents were untouched. So the change narrows installs without weakening the working path.

Revert-proofing: reverting only the leaf guard turns the new test red with expected [ { agent: 'claude', …(4) }, …(13) ] to deeply equal [] — it reproduces the exact 14-agent fan-out from the issue, so the test genuinely pins the fix.

Gates at this head: 41/41 tests in the touched files, typecheck exit 0, oxlint and oxfmt clean. CI is now fully green — 42 successful checks, e2e correctly skipped, mergeStateStatus: CLEAN.

I also re-traced the call sites to check the one regression that would matter — hooks that used to install and now silently don't. All three production callers (SSH, WSL, and the relay handler) already detect agents and pass an explicit allowlist, returning early on zero, so no live path changes behavior. The two side effects the runtime early-return now skips (the install lock and the Grok-home resolution) each have exactly one caller, this function, so nothing else depends on them.

Thanks for the clean, minimal fix and for holding the head steady — that made verification straightforward.

@bbingz

bbingz commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@brennanb2025 thank you for closing the Electron + live-SSH gap — the negative (0/14 homes) and single-agent positive cases are exactly the #11641 contract.

Holding the head at dc758247e0 with no further pushes so the green rollup stays intact. Land-as-is from my side whenever you or another maintainer is ready to merge.

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for this — it's a real hole, and the fix is the standard shape for it (coerce the missing allowlist to an empty set and filter), so I kept your approach as-is.

Heads up that I pushed one commit to your branch: test(agent-hooks): pin installManagedHooks fail-closed gate.

Your new regression test already pins the leaf guard, but the early return you added to installManagedHooks was invisible to the suite — deleting it left the agent-hooks and relay tests green, because the leaf guard makes the returned summary identical and the only difference is side effects. The added test runs installManagedHooks against a throwaway HOME with a recording login shell and asserts the directory stays empty, so a revert now fails with expected [ '.orca', 'login-shell', 'login-shell-runs' ] to deeply equal [ 'login-shell' ] — which names both of the side effects your guard skips.

For what it's worth, that skip is also a decent win on its own: the empty-allowlist path went from ~290 ms and a ~/.orca mkdir per call to ~0.1 ms with nothing written.

One thing we're tracking separately, not a blocker here — when remote agent detection is unavailable, the remote path returns {installers: 0, errors: 0} with no per-agent status, so an agent the user really does have installed silently gets no hooks. The local path already reports skipped with a skipReason; we'd like the remote path to match.

@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 (2)
src/main/agent-hooks/managed-hook-runtime.test.ts (2)

8-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the platform temporary directory.

Line 8 hardcodes /tmp for every non-Windows run. Use tmpdir() for all platforms. This avoids assuming a specific POSIX temporary root.

As per coding guidelines, use Node path utilities for file paths and do not assume / or \.

Proposed fix
-const tempRoot = process.platform === 'win32' ? tmpdir() : '/tmp'
+const tempRoot = tmpdir()

Source: Coding guidelines


52-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Run the fail-closed regression on Windows.

Line 52 skips the complete suite on Windows. The omitted and empty allowlist paths return before resolveRelayGrokHome, so those cases do not require the POSIX shell fixture. Run these cases outside the platform-gated suite, or add a Windows-compatible variant.

Based on the supplied runtime contract, the empty-list return occurs before home and host probes.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 114fec8a-714e-4649-aef5-f3244a3a82b1

📥 Commits

Reviewing files that changed from the base of the PR and between dc758247e07d15ab7b3393782b0903d4b87b1f3d and 8f3668ca729afbfec6c9f9d320a9910fd931ba9e.

📒 Files selected for processing (1)
  • src/main/agent-hooks/managed-hook-runtime.test.ts

@bbingz

bbingz commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@brennanb2025 thanks for keeping the approach and for the installManagedHooks side-effect pin — that early return was the part that actually mattered and would have been easy to lose.

Noted on the remote {installers:0,errors:0} / no-per-agent-status gap when detection is unavailable; happy to take a follow-up if you want the remote path to mirror local skipped + skipReason.

bbingz and others added 2 commits August 12, 2026 03:25
Omit/empty agents no longer means install every remote managed hook.
Closes the remaining hole after stablyai#11442 that recreated uninstalled
agent config homes via the relay/SSH/WSL install path (stablyai#11641).
The leaf guard already had a regression test, but the early return in
installManagedHooks was invisible to the suite: reverting it left every
agent-hooks and relay test green, because the leaf guard makes the summary
identical and the only delta is side effects (GROK_HOME login-shell probe,
host-identity read, ~/.orca mkdir + install lock).
@bbingz
bbingz force-pushed the fix/skip-hooks-without-cli branch from 8f3668c to 40cec3b Compare August 11, 2026 19:25
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025

Copy link
Copy Markdown
Contributor

Merged latest main in to clear the conflict — no rebase, no force-push, so your commits are untouched.

The only collision was managed-hook-runtime.test.ts: main had converted the resolveRelayGrokHome cases to a mocked node:child_process execFile (a CI flakiness fix), while this PR added its fail-closed cases to the same file. I kept both — main's execFile mock infra and its converted probe assertions, plus all of your installManagedHooks tests.

One wrinkle worth flagging: your install tests observe the probe through the real login-shell run log, and main's mock is a bare vi.fn(), so the probe would never have spawned. The mocked execFile also loses util.promisify.custom, which is why main's stubs call back with a { stdout, stderr } object. So the shared beforeEach now defaults the mock to the real execFile with the callback reshaped to match, and the parser cases stub over it as before.

No source logic changed — managed-hook-runtime.ts and remote-managed-hook-installers.ts are byte-identical to your last commit. Full src/main/agent-hooks suite is green (39 files, 604 passed / 4 skipped), and typecheck + oxlint are clean.

Thanks for the fix! 🙏

@brennanb2025

Copy link
Copy Markdown
Contributor

Apologies for the slow turnaround here 🙏 CI is running now and I'll merge once it's green.

Thanks for this — failing closed on the allowlist is the right default, and it matches how comparable tools gate this. We're picking up the rest of #11641 as a follow-up: making writes into agent config files we don't own fully non-destructive, and not creating config homes for agents that aren't installed. This PR is the right foundation for that.

Appreciate your patience!

@brennanb2025
brennanb2025 merged commit 204845f into stablyai:main Aug 13, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#11676)

* fix(agent-hooks): fail closed without detected agent allowlist

Omit/empty agents no longer means install every remote managed hook.
Closes the remaining hole after stablyai#11442 that recreated uninstalled
agent config homes via the relay/SSH/WSL install path (stablyai#11641).

* test(agent-hooks): pin installManagedHooks fail-closed gate

The leaf guard already had a regression test, but the early return in
installManagedHooks was invisible to the suite: reverting it left every
agent-hooks and relay test green, because the leaf guard makes the summary
identical and the only delta is side effects (GROK_HOME login-shell probe,
host-identity read, ~/.orca mkdir + install lock).

---------

Co-authored-by: Brennan Benson <[email protected]>
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]: Orca auto-creates hook config directories for every agent regardless of whether they are installed

3 participants