Skip to content

fix(agent-hooks): refresh existing Orca launchers when agent CLIs are unavailable - #13378

Merged
brennanb2025 merged 3 commits into
mainfrom
followup/hook-script-refresh-on-cli-missing
Aug 10, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
followup/hook-script-refresh-on-cli-missing

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #11568 / #11549. If an agent CLI falls off PATH (for example, after an npm-prefix or shim relocation), the presence gate skips install() with no removal, while the agent's user-wide config can keep invoking its existing launcher under ~/.orca/agent-hooks. That left the launcher frozen at its previous generated version; on Windows, it could preserve the pre-#11568 more.com leak indefinitely.

This adds a reconcile pass before presence detection: every already-existing shared launcher/statusline script is rewritten to the current template. Creation remains presence-gated, so an absent script or missing agent config is not created. Amp and Hermes remain excluded because they install provider-native plugin code through a different lifecycle rather than shared launchers.

The refresh path is asynchronous and sequential. It short-circuits identical content, publishes changed content with a same-directory temp file plus rename, preserves POSIX executable mode, and applies the existing Windows ACL recovery behavior without blocking Electron's main thread or fanning work across the thread pool.

User path

  1. A user installs an agent CLI and Orca writes both the agent's user-wide hook config and an Orca-managed launcher.
  2. The CLI later becomes temporarily undetectable to Orca because its PATH entry or shim moved.
  3. The agent config can still point at the existing launcher, but the CLI-presence gate correctly refuses to create or mutate agent-owned configuration.
  4. On Orca's next managed-hook reconciliation, this PR updates only that existing Orca launcher to the current safe template. If the launcher never existed, nothing is created.
  5. If the CLI is installed or detected again later, the normal presence-gated installer reconciles its configuration as before.

Decision rationale

The lifecycle boundary is deliberate: automatically maintain artifacts Orca already owns; require positive CLI detection before creating integrations or mutating agent-owned configuration.

  • An existing file under ~/.orca/agent-hooks proves Orca previously created that launcher, and the agent's user-wide config may still invoke it while the CLI is temporarily missing from Orca's PATH.
  • CLI detection has legitimate false negatives across GUI/login-shell PATH differences, package-manager prefix changes, shims, and temporary relocations. Deleting on cli_not_found could therefore break a still-referenced hook target.
  • Explicit reinstall/setup was rejected because Orca has no user-managed hook-version workflow, and the affected CLI is undetectable by definition. Requiring user action would leave old launchers—and the [Bug]: Codex managed hook leaves persistent cmd.exe windows outside Orca on Windows #11549 Windows process leak—deployed indefinitely.
  • Full unconditional reinstall was also rejected: it would undo fix(agent-hooks): skip unavailable agent homes #11442's safety boundary by creating agent homes or mutating agent configuration without evidence that the agent is installed.
  • Comparable terminal-agent integrations converge on the same ownership principle: generated product-owned artifacts need a self-healing update path, while first-time creation and agent-owned configuration remain explicit or presence-gated. Existing-only automatic repair and outdated-install detection are common ways to avoid stranding stale hooks without broad mutation.

This makes the refresh pass the narrowest repair that reaches the affected population: it updates only existing Orca-owned launchers, creates nothing for never-configured agents, and leaves agent configuration untouched until the CLI is positively detected.

Screenshots

No product UI changes. Exact-head Windows Electron validation and screenshots: #13378 (comment)

Testing

  • Same-model clean review loop at 0646b42075: 53 files, 703 passed, 27 skipped
  • Focused exact-head refresh/Windows suite: 4 files, 21 passed
  • Unit and end-to-end coverage for existing-script refresh, missing-script/config preservation, identical-content no-op, ACL/mode behavior, atomic publication, concurrent refreshes, and stale pre-fix(agent-hooks): exit Windows hooks when Orca env is missing #11568 Windows launchers
  • Main-thread regression coverage proves no synchronous HOME filesystem calls and keeps the event loop responsive while a refresh read is stalled
  • Bidirectional coverage gate fails if a shared launcher is added without a refresher or a refresher has no installed launcher
  • Node and CLI typechecks; native, type-aware, and standard lint; reliability gates; git diff --check
  • CI: Node 18 managed hooks, Node 24/26 test matrices, Git/wire compatibility, static analysis, and macOS/Linux/Windows packaging

AI Review Report

Reviewed adversarially from the user-visible failure back through presence detection and installer history. Before #11442, managed-hook reconciliation invoked installers unconditionally, which refreshed launchers; #11442 correctly added CLI-presence gating but thereby froze an existing launcher when a CLI became undetectable. #11568 fixed the leaking Windows template and explicitly left existing-launcher refresh as this follow-up.

Alternatives considered and rejected: deleting on cli_not_found turns a false-negative PATH probe into a broken hook target; treating launcher existence as CLI presence would resume mutating agent configuration without proof the CLI is installed; versioned filenames require config rewrites. SSH/relay installers are separate and unchanged, and the local path does not assume a git worktree, so SSH/WSL and folder-workspace behavior are unaffected.

Security Audit

Refresh touches only files that already exist under Orca's fixed ~/.orca/agent-hooks namespace and uses the same trusted in-repo generators as installation. It creates no launcher directories, missing scripts, or agent configuration. Best-effort failures are logged per agent and preserve a complete old script rather than publishing partial content.

Notes

  • Windows is the motivating population, but using each service's existing platform-specific generator keeps refresh behavior platform-uniform.
  • Amp and Hermes provider-native plugins may have a similar staleness class, but their refresh belongs to their own install lifecycle and is deliberately outside this PR.
  • The only theoretical residual is an external deletion in the tiny existence-check-to-rename window. Orca has no product path that deletes these launcher files, and Node does not expose a portable atomic replace-if-present primitive that also preserves complete-file publication.

…s no longer detected

A CLI that falls off PATH (moved npm prefix, relocated shim) keeps its user-wide
config invoking Orca's launcher script under ~/.orca/agent-hooks, but the
presence gate skips install() with no removal — freezing the script at whatever
Orca generated last. Anyone in that state kept the pre-#11568 more.com-leaking
.cmd forever, because no launcher script is ever deleted and Windows startup
deliberately skips shell PATH hydration.

Reconcile before gating: every existing shared launcher/statusline script is
rewritten to the current template on each install pass. Creating scripts stays
behind the presence gate — an existing file is proof of a prior install; a
missing one means the gate did its job. Amp and Hermes are deliberately absent:
they write provider-native plugin code with its own install lifecycle, not
shared launchers.

- refreshManagedScriptIfPresent() in installer-utils (no-op unless the file exists)
- refreshManagedScripts() on the 11 launcher-writing services (openclaude via
  the shared Claude class)
- reconcile pass in installManagedAgentHooks before presence detection,
  filtered by the agents option, best-effort per agent
- coverage gate: a launcher written to ~/.orca/agent-hooks without a matching
  refresher entry fails the suite, in both directions
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Managed hook services can now refresh existing generated scripts without creating missing files. The refresh utility supports permissions, atomic replacement, Windows write retries, and asynchronous filesystem access. A registry connects supported agents to refresh callbacks. Installation runs selected refreshers before installer selection and CLI detection, logs refresh failures, and continues installation. Tests cover provider coverage, ordering, selection, missing files, platform behavior, permissions, and event-loop responsiveness.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% 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 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.
Description check ✅ Passed The description includes all required sections and clearly documents the change, testing, review, security audit, and platform-specific notes.
Title check ✅ Passed The title clearly summarizes the main change: refreshing existing Orca launchers when agent CLIs are unavailable.
✨ Finishing Touches 💡 1
📝 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 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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f161b0bb-6d35-43e9-87be-8bf6cd14b1b1

📥 Commits

Reviewing files that changed from the base of the PR and between 68b6e9f and dd7f3f9.

📒 Files selected for processing (16)
  • src/main/agent-hooks/installer-utils.ts
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/agent-hooks/managed-agent-hook-registry.ts
  • src/main/agent-hooks/managed-hook-script-refresh.test.ts
  • src/main/antigravity/hook-service.ts
  • src/main/claude/hook-service.ts
  • src/main/codex/hook-service.ts
  • src/main/command-code/hook-service.ts
  • src/main/copilot/hook-service.ts
  • src/main/cursor/hook-service.ts
  • src/main/devin/hook-service.ts
  • src/main/droid/hook-service.ts
  • src/main/gemini/hook-service.ts
  • src/main/grok/hook-service.ts
  • src/main/kimi/hook-service.ts

Comment thread src/main/agent-hooks/installer-utils.ts Resolved
@OrcaWin

OrcaWin commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Windows Electron QA — PASS @ dd7f3f9ae0b9d4ffe4331b295d5916d5c18bef2b

Host: Windows NT 10.0.26200 · Electron dev via CDP 9333 · isolated ORCA_DEV_USER_DATA_PATH + temp USERPROFILE

Identity

  • git rev-parse HEAD = dd7f3f9ae0b9d4ffe4331b295d5916d5c18bef2b (exact match)
  • window.api.app.getIdentity() → Orca: OrcaWin/pr-13378-grok-electron-qa · devWorktreeName=pr-13378-grok-electron-qa · isDev=true

Startup behavior (stale managed launcher + CLI absent)

Seeded only pre-#11568 leaking claude-hook.cmd (if "%ORCA_AGENT_HOOK_PORT%"=="" goto :orca_agent_hook_drain_stdin + more.com). Claude CLI stripped from process PATH (presence miss without breaking launch).

Check Result
Existing stale launcher rewritten to safe template PASS — SHA CCA2C36E… → 17957A96…; now has if "%ORCA_AGENT_HOOK_PORT%"=="" exit /b 0 (no empty-port goto leak)
Absent managed script not created PASS — no claude-statusline.cmd
Missing agent config not created PASS — no .claude/settings.json; empty .claude/ dir only (0 files, not a hook install)
Renderer console 0 errors (4 dev-only warnings: CSP/React Grab/tooltip)

Note: droid-hook.cmd / grok-hook.cmd were created because those CLIs remained on PATH (control agents). Claude path stayed presence-gated.

UI exercised

Empty-home surface + Settings → Agents (Agent status hooks ON).

Screenshots

(uploaded to refs/uploads/pr-13378-windows-qa-screenshots, not in PR diff)

win empty home

settings agents

Cleanup

Temp profile/home, CDP/renderer processes from this run will be torn down after comment. PR worktree preserved.

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

Run ID: 95ceaa62-ccce-44e4-8875-ba6cf3622719

📥 Commits

Reviewing files that changed from the base of the PR and between dd7f3f9 and ba6958d.

📒 Files selected for processing (18)
  • config/tsconfig.cli.json
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/agent-hooks/managed-agent-hook-registry.ts
  • src/main/agent-hooks/managed-hook-script-refresh-main-thread.test.ts
  • src/main/agent-hooks/managed-hook-script-refresh.test.ts
  • src/main/agent-hooks/managed-hook-script-refresh.ts
  • src/main/antigravity/hook-service.ts
  • src/main/claude/hook-service.ts
  • src/main/codex/hook-service.ts
  • src/main/command-code/hook-service.ts
  • src/main/copilot/hook-service.ts
  • src/main/cursor/hook-service.ts
  • src/main/devin/hook-service.ts
  • src/main/droid/hook-service.ts
  • src/main/gemini/hook-service.ts
  • src/main/grok/hook-service.ts
  • src/main/kimi/hook-service.ts
🚧 Files skipped from review as they are similar to previous changes (13)
  • src/main/antigravity/hook-service.ts
  • src/main/droid/hook-service.ts
  • src/main/command-code/hook-service.ts
  • src/main/codex/hook-service.ts
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts
  • src/main/agent-hooks/managed-agent-hook-registry.ts
  • src/main/cursor/hook-service.ts
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/devin/hook-service.ts
  • src/main/grok/hook-service.ts
  • src/main/kimi/hook-service.ts
  • src/main/gemini/hook-service.ts
  • src/main/claude/hook-service.ts

@OrcaWin

OrcaWin commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Windows Electron QA — PASS @ 0646b42075

Host: Windows NT 10.0.26200 · Electron dev via CDP 9341 · isolated ORCA_DEV_USER_DATA_PATH + temp USERPROFILE
Head: 0646b420759b0108d442f71b42c531f56f5f13b0 (git rev-parse HEAD exact match) · async main-thread managed-hook refresh

Identity (CDP)

  • window.api.app.getIdentity() → Orca: 0646b42075 · devWorktreeName=pr-13378-async-windows-qa · devRepoRoot=.../pr-13378-async-windows-qa · isDev=true

Startup behavior (stale managed launcher + CLI absent)

Seeded only pre-#11568 leaking cursor-hook.cmd (if "%ORCA_AGENT_HOOK_PORT%"=="" goto :orca_agent_hook_drain_stdin + more.com). Cursor CLI absent from PATH.

Check Result
Existing stale launcher rewritten to safe template PASS — SHA CCA2C36E… → D2C3CAC0…; now has if "%ORCA_AGENT_HOOK_PORT%"=="" exit /b 0 (no empty-port goto leak)
Absent managed statusline not created PASS — no cursor-statusline.cmd
Missing agent config not created PASS — no ~/.cursor
Other absent launchers not created PASS — no gemini/antigravity/devin/kimi/command-code launchers
Renderer console 0 errors (4 dev-only warnings: CSP/React Grab/tooltip)
[agent-hooks] Failed to refresh 0 in main/daemon/stdout/stderr

PATH-present agents (claude/codex/droid/grok) correctly installed under the isolated home only.

UI exercised

Empty-home surface + Settings → Agents (heading Agents, Default Agent, Agent status hooks ON, Windows runtime).

Screenshots

(uploaded to refs/uploads/pr-13378-async-head-screenshots, not in PR diff; gh image unavailable without browser session token)

win empty home

settings agents

Cleanup

QA Electron/CDP/renderer processes and temp profile will be torn down after this comment. Worktree preserved at exact head for coordinator inspection.

Third-party upload audit (prior stopped attempt)

Prior temp orca-pr13378-qa-66c6194a had no image-urls.json and no catbox/0x0 URLs — no third-party upload occurred.

@brennanb2025 brennanb2025 changed the title fix(agent-hooks): refresh existing shared hook scripts when the CLI is no longer detected fix(agent-hooks): refresh existing Orca launchers when agent CLIs are unavailable Aug 10, 2026
@OrcaWin

OrcaWin commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Windows Electron QA — PASS @ 0646b42075

Host: Microsoft Windows NT 10.0.26200.0 · Electron dev via CDP 9335 · isolated ORCA_DEV_USER_DATA_PATH + temp USERPROFILE
Head: 0646b420759b0108d442f71b42c531f56f5f13b0 (git rev-parse HEAD exact match to origin/followup/hook-script-refresh-on-cli-missing) · async managed-hook refresh

Identity (CDP)

  • window.api.app.getIdentity() → Orca: OrcaWin/pr-13378-grok-electron-qa-2 · devWorktreeName=pr-13378-grok-electron-qa-2 · devRepoRoot=.../pr-13378-grok-electron-qa-2 · isDev=true

Startup behavior (stale managed launcher + CLI absent)

Seeded only pre-#11568 leaking cursor-hook.cmd (if "%ORCA_AGENT_HOOK_PORT%"=="" goto :orca_agent_hook_drain_stdin + more.com). Cursor CLI absent from PATH.

Check Result
Existing stale launcher rewritten to safe template PASS — SHA 508BF34C… → D2C3CAC0…; now has if "%ORCA_AGENT_HOOK_PORT%"=="" exit /b 0 (no empty-port goto leak)
Absent managed statusline not created PASS — no cursor-statusline.cmd
Missing agent config not created PASS — no ~/.cursor
Other absent launchers not created PASS — no gemini/antigravity/devin/kimi/command-code launchers
Renderer console (post-reload) 0 errors (4 dev-only warnings: CSP/React Grab/tooltip)
[agent-hooks] Failed to refresh 0 in main stdout/stderr + daemon.log

PATH-present agents (claude/codex/droid/grok) correctly installed under the isolated home only.

UI exercised

Empty-home surface + Settings → Agents (heading Agents, Default Agent, Agent status hooks ON, Windows runtime).

Screenshots

Empty home Settings → Agents
Windows empty home Windows Settings Agents

Cleanup

QA Electron/CDP/renderer processes and temp profile torn down after this comment. Worktree preserved at exact head for coordinator inspection. No source changes; no merge.

@brennanb2025
brennanb2025 merged commit 2ee43bf into main Aug 10, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… unavailable (stablyai#13378)

* fix(agent-hooks): refresh existing shared hook scripts when the CLI is no longer detected

A CLI that falls off PATH (moved npm prefix, relocated shim) keeps its user-wide
config invoking Orca's launcher script under ~/.orca/agent-hooks, but the
presence gate skips install() with no removal — freezing the script at whatever
Orca generated last. Anyone in that state kept the pre-stablyai#11568 more.com-leaking
.cmd forever, because no launcher script is ever deleted and Windows startup
deliberately skips shell PATH hydration.

Reconcile before gating: every existing shared launcher/statusline script is
rewritten to the current template on each install pass. Creating scripts stays
behind the presence gate — an existing file is proof of a prior install; a
missing one means the gate did its job. Amp and Hermes are deliberately absent:
they write provider-native plugin code with its own install lifecycle, not
shared launchers.

- refreshManagedScriptIfPresent() in installer-utils (no-op unless the file exists)
- refreshManagedScripts() on the 11 launcher-writing services (openclaude via
  the shared Claude class)
- reconcile pass in installManagedAgentHooks before presence detection,
  filtered by the agents option, best-effort per agent
- coverage gate: a launcher written to ~/.orca/agent-hooks without a matching
  refresher entry fails the suite, in both directions

* perf(agent-hooks): refresh launchers off the main thread

* test(agent-hooks): keep refresh mode assertion POSIX-only
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.

2 participants