Skip to content

fix(orcad): install agent status hooks when a managed host starts - #27319

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/orcad-hooks-on-connect
Oct 11, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/orcad-hooks-on-connect

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​197 $\color{#cf222e}{\Huge{\mathbf{−}}}$​110 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​87
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​209 $\color{#cf222e}{\Huge{\mathbf{−}}}$​107 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​102

ELI5

Orca learns what an AI agent (Claude, Codex, …) is doing through small "hook" scripts the agent calls. On a remote machine, something has to install those hooks. The old SSH helper process did it every time you connected. The newer remote server (orcad) only did it when you changed the hook setting, so a brand-new remote machine never got hooks and its agents never showed a status. Now orcad installs them when it starts, the same way the desktop app does on its own machine.

What Changed

  • Before: on a managed SSH host (the orcad path), the agent hook scripts and agent settings entries were written only when that host's "agent status hooks" setting or its disabled-agent list changed. A freshly managed host had none, so agent status never updated. The old relay path had hidden this because the relay installed hooks on every connect. refactor(ssh): connect fails for hosts orcad can't serve; remove the relay client path #27214/refactor(relay): delete the SSH relay server, its build assets and tests #27215 remove the relay, so this would have broken status for every SSH user.
  • After: when orcad starts (which a connect does on a fresh host), it runs the same startup reconcile the desktop runs on launch:
    • starts the Codex hook reconcile against ~/.codex, after shell PATH hydration
    • installs or refreshes the managed hooks for every agent CLI found on the host (installManagedAgentHooks)
    • refreshes already-installed OpenCode status plugins
    • first, reads GROK_HOME / KIRO_HOME from the user's login shell if orcad's own environment lacks them. orcad starts from a plain sh -c over SSH, so it would otherwise miss a home set only in ~/.profile, and install Grok/Kiro hooks where those agents never look. The relay did this same lookup. The probe moved out of the relay-only managed-hook-runtime.ts into src/main/agent-hooks/agent-home-login-shell.ts, which survives the relay deletion and now runs through @orca/process-host.
  • Mechanism: the desktop's startup install block moved into reconcileStartupManagedAgentHooks (src/main/agent-hooks/managed-agent-hook-startup.ts). Desktop startup and orcad (src/main/orcad/orcad-managed-agent-hooks.ts) now both call it. orcad's existing hook-setting listener moved into the same orcad module, which also owns the stop flag that cuts an in-flight install short on shutdown.

Why

  • Uses the host's own hook server and installers. Per the agent-status rule, the hook server on the execution host owns status. orcad already runs that server and hands its pane env to agents, so the right installers are the local ones orcad already used when settings changed. The relay's remote installer belongs to the relay's own hook server, so it isn't used here.
  • Respects settings. Hooks off means no install. Like the desktop, startup never removes hooks, because hook files are shared by every Orca profile on the host. Per-agent disables still apply.
  • Cheap and idempotent. Hook installs only run for CLIs actually present, and the shared writers skip a write when the content on disk already matches. This is the same code the desktop runs on every launch.
  • Windows and WSL. orcad on a Windows host or inside a WSL distro runs the native installers, which already handle Windows paths and launchers. The relay used to skip Windows remotes entirely, so Windows hosts now get managed hooks too.
  • Alternative considered: reinstalling on every client connect. Startup covers the reported gap, because a fresh host starts orcad on connect. Hook files persist across orcad restarts, so running at connect time too would add work without changing the result.
  • No relay dependency. The change touches only orcad, desktop startup and shared agent-hook code. It cherry-picks cleanly onto refactor(relay): delete the SSH relay server, its build assets and tests #27215's head (stacked on refactor(ssh): connect fails for hosts orcad can't serve; remove the relay client path #27214), where the focused tests pass and tsc -p config/tsconfig.node.json is clean.

Linked Issue

Blocker found in review of #27214 / #27215.

Visual Proof

N/A: no UI change. The effect is that agent status works on a freshly managed SSH host.

Testing

  • New acceptance tests in src/main/orcad/orcad-push-startup.test.ts:

    • booting orcad starts the Codex reconcile on the real ~/.codex and installs managed hooks with the profile settings. This fails on main (expected "vi.fn()" to be called once, but got 0 times).
    • with agentStatusHooksEnabled: false, nothing is installed and Codex's reconcile reports disabled.
    • agent-home-login-shell.test.ts: the moved probe cases, plus profile-only homes being adopted while existing ones are kept.
  • Existing desktop startup wiring test (codex-hook-startup-wiring.test.ts) still passes.

  • pnpm tc, pnpm lint, oxlint, pnpm run check:code-quality:changed, and pnpm run build:orcad (no Electron imports in the bundle) all pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

P0/P1 review by an independent reviewer. It found one P1, now fixed: Grok/Kiro homes that are set only in login profiles were missed. Own review: no further P0/P1. Agent settings are per host (the settings host scope), so orcad's own profile is the right authority for the hooks-off switch.

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

  • Security: no new inputs.
  • SSH: this is the SSH fix.
  • Windows/Linux/macOS: uses the native installers.
  • Mobile: unaffected.
  • Compatibility: no wire change.
  • Performance: one background install at orcad start, which skips writes when nothing changed.

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)
  • 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)

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f874f5cf-c927-48bb-908b-161a23bb4725

📥 Commits

Reviewing files that changed from the base of the PR and between 94a44a8 and 71fba3b.


You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

Managed-hook installation now uses shared login-shell resolvers for Grok and Kiro home paths. The main process delegates startup reconciliation to a shared function. Orcad startup uses a controller for Codex hooks, managed-hook reconciliation, OpenCode plugin refresh, status-setting updates, and cleanup. Startup tests cover these integrations and disabled status hooks.





Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 94a44

Managed hooks may be installed in the wrong agent home, or may be missing on an immediate first launch. Reconciliation may also briefly run after shutdown begins. These are narrow edge cases, so the change is mergeable with follow-up.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 9 files. 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.
Title check Passed The title is concise, specific, and accurately describes the primary change: installing agent status hooks when a managed orcad host starts.
Description check Passed The description is detailed and follows the repository template. It explains the user impact, implementation, rationale, testing, compatibility considerations, and checklist status. The linked issue s…



✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR




🛠️ Fix failing CI checks 💡
  • 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

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: Advanced
  • Run ID: b0484db9-ccd1-4473-954e-54266770e8a3
📥 Commits

Reviewing files that changed from the base of the PR and between eaf5dbe and 490fee1075e29fe7ae8cd0a67d0e40ac3bfb8e80.

📒 Files selected for processing (5)
  • src/main/agent-hooks/managed-agent-hook-startup.ts
  • src/main/orcad/orcad-entry.ts
  • src/main/orcad/orcad-managed-agent-hooks.ts
  • src/main/orcad/orcad-push-startup.test.ts
  • src/main/startup/main-process-ready-runtime.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

if (resolveStartupManagedHookAction(host.getSettings()) !== 'install') {
return
}
void installManagedAgentHooks(host.getSettings(), {

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,100p' src/main/agent-hooks/managed-agent-hook-startup.ts
sed -n '210,245p' src/main/orcad/orcad-entry.ts
sed -n '355,405p' src/main/orcad/orcad-entry.ts
rg -n 'ServeReadinessPublisher|installManagedAgentHooks|reconcileStartupManagedAgentHooks' src/main/orcad src/main/agent-hooks

Repository: stablyai/orca

Length of output: 8343


🏁 Script executed:

set -u
printf '%s\n' '--- startup caller ---'
sed -n '1,180p' src/main/orcad/orcad-managed-agent-hooks.ts
printf '%s\n' '--- launch-related references ---'
rg -n -F --glob '*.ts' -- 'launchManaged' src/main || test "$?" -eq 1
rg -n -F --glob '*.ts' -- 'startManaged' src/main || test "$?" -eq 1
rg -n -F --glob '*.ts' -- 'createManaged' src/main || test "$?" -eq 1
printf '%s\n' '--- agent process / session entry references ---'
rg -n -i --glob '*.ts' 'managed.?agent|agent.?launch|launch.*agent|agent.*launch|create.*session|start.*session' src/main | head -240
printf '%s\n' '--- readiness and startup consumers ---'
rg -n -i --glob '*.ts' 'serve.?readiness|readiness|ready' src/main/orcad src/main/server src/main | head -260

Repository: stablyai/orca

Length of output: 42239


🏁 Script executed:

set -u
printf '%s\n' '--- Orcad startup ordering ---'
nl -ba src/main/orcad/orcad-entry.ts | sed -n '330,400p'
printf '%s\n' '--- readiness contract ---'
nl -ba src/main/orcad/orcad-serve-readiness.ts | sed -n '1,80p'
nl -ba src/main/server/serve-readiness.ts | sed -n '1,180p'
printf '%s\n' '--- managed installer entry ---'
nl -ba src/main/agent-hooks/managed-agent-hook-controls.ts | sed -n '120,285p'
printf '%s\n' '--- agent-launch RPC files ---'
rg --files src/main/runtime/rpc/methods src/main/agent-launch | sort
rg -n -i --glob '*.ts' 'agent.?launch|launch.?agent|startupAgent|createManagedWorktree' src/main/runtime/rpc src/main/agent-launch

Repository: stablyai/orca

Length of output: 41983


🏁 Script executed:

set -u
printf '%s\n' '--- agent.launch method ---'
nl -ba src/main/runtime/rpc/methods/agent-launch.ts | sed -n '1,280p'
printf '%s\n' '--- shared launch executor ---'
nl -ba src/main/agent-launch/agent-launch-executor.ts | sed -n '1,280p'
printf '%s\n' '--- RPC method registration ---'
rg -n -F --glob '*.ts' -- 'AGENT_LAUNCH_METHODS' src/main/runtime src/main | head -80
rg -n -F --glob '*.ts' -- 'agent.launch' src/main/runtime/rpc | head -100

Repository: stablyai/orca

Length of output: 41781


Await startup hook installation before publishing Orcad readiness.

reconcileStartupManagedAgentHooks starts installation without exposing its promise. Orcad publishes readiness after the RPC transport starts, and agent.launch has no hook-installation gate. The first agent can therefore start before installation completes and miss status reporting. This does not prevent the agent from launching.

Return the installation promise and await it in the Orcad startup path before publishing readiness, or gate the first launch on the same promise. Keep this boundary in Orcad startup, not in the shared agent-launch executor.

@OrcaWin
OrcaWin force-pushed the OrcaWin/orcad-hooks-on-connect branch from 490fee1 to 94a44a8 Compare October 10, 2026 22:42

@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: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8d867a05-67d0-4d6f-b0ff-3374d7b05f92
📥 Commits

Reviewing files that changed from the base of the PR and between 490fee1075e29fe7ae8cd0a67d0e40ac3bfb8e80 and 94a44a8.

📒 Files selected for processing (7)
  • config/process-host-direct-import-baseline.txt
  • src/main/agent-hooks/agent-home-login-shell.test.ts
  • src/main/agent-hooks/agent-home-login-shell.ts
  • src/main/agent-hooks/managed-hook-runtime.test.ts
  • src/main/agent-hooks/managed-hook-runtime.ts
  • src/main/orcad/orcad-managed-agent-hooks.ts
  • src/main/orcad/orcad-push-startup.test.ts
💤 Files with no reviewable changes (1)
  • config/process-host-direct-import-baseline.txt

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

try {
const shell = resolveLoginShell()
const shellName = basename(shell)
const mode = shellName === 'sh' || shellName === 'dash' ? '-c' : '-lc'

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Run the sh and dash probes as login shells.

When .profile exports GROK_HOME or KIRO_HOME, -c does not read that export. The probe falls back to the default home, so startup can install hooks where the agent does not look. Use a login-shell invocation that these shells support, and update the shell-mode test.

if (result.timedOut || result.code !== 0) {
return null
}
return normalizeAgentHome(result.stdout.split(/\r?\n/, 1)[0] ?? '')

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Separate profile output from the probed home.

When a login profile prints a banner or warning to stdout, the first line is not the value printed by printenv. This parser then selects the wrong path or falls back, even when the profile sets a valid agent home. Mark the probe output and parse the marked value.

Comment on lines +42 to +48
void adoptLoginShellAgentHomes().then(() =>
reconcileStartupManagedAgentHooks({
getSettings,
isQuitting: () => stopping,
shouldHydrateShellPath
})
)

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
fd agent-home-login-shell.ts --exec sed -n 1,110p {}

Repository: stablyai/orca

Length of output: 3485


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- target module ---'
nl -ba src/main/orcad/orcad-managed-agent-hooks.ts | sed -n '1,180p'
printf '%s\n' '--- reconciliation definition and references ---'
rg -n -F -- 'reconcileStartupManagedAgentHooks' src/main
printf '%s\n' '--- startup reconciliation module ---'
nl -ba src/main/agent-hooks/managed-agent-hook-startup.ts | sed -n '1,240p'
printf '%s\n' '--- stop and cleanup references ---'
rg -n -F -- 'startOrcadManagedAgentHooks' src/main
rg -n -F -- 'registerCleanup' src/main/orcad src/main | head -80

Repository: stablyai/orca

Length of output: 12705


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- managed hook controls ---'
nl -ba src/main/agent-hooks/managed-agent-hook-controls.ts | sed -n '1,300p'
printf '%s\n' '--- installer references and definition ---'
rg -n -F -- 'function installManagedAgentHooks' src/main
rg -n -F -- 'export async function installManagedAgentHooks' src/main
printf '%s\n' '--- lifecycle cleanup implementation ---'
nl -ba src/main/orcad/orcad-lifecycle.ts | sed -n '1,180p'
printf '%s\n' '--- runtime stop implementation ---'
nl -ba src/main/orcad/orcad-entry.ts | sed -n '130,245p'

Repository: stablyai/orca

Length of output: 25778


🏁 Script executed:

set -o pipefail
nl -ba src/main/agent-hooks/local-agent-cli-presence.ts | sed -n '1,280p'

Repository: stablyai/orca

Length of output: 8777


Skip startup reconciliation after shutdown begins.

adoptLoginShellAgentHomes() can resolve after cleanup. Its continuation then calls reconcileStartupManagedAgentHooks() without checking stopping. CLI presence detection hydrates the shell PATH before the per-agent shutdown check. This can start shell PATH hydration after cleanup.

The login-shell probe catches its own errors and is called without an abort signal, so the unhandled-rejection claim does not apply.

Suggested fix
--- "a/src/main/orcad/orcad-managed-agent-hooks.ts"
+++ "b/src/main/orcad/orcad-managed-agent-hooks.ts"
@@ -39,13 +39,16 @@
     // Why null: orcad launches Codex on ~/.codex; Orca-managed account homes are a desktop flow.
     resolveLaunchHome: () => null
   })
-  void adoptLoginShellAgentHomes().then(() =>
-    reconcileStartupManagedAgentHooks({
-      getSettings,
-      isQuitting: () => stopping,
-      shouldHydrateShellPath
-    })
-  )
+  void adoptLoginShellAgentHomes().then(() => {
+    if (stopping) {
+      return
+    }
+    reconcileStartupManagedAgentHooks({
+      getSettings,
+      isQuitting: () => stopping,
+      shouldHydrateShellPath
+    })
+  })
   try {
     refreshInstalledOpenCodeStatusPlugins(getSettings())
   } catch (error) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void adoptLoginShellAgentHomes().then(() =>
reconcileStartupManagedAgentHooks({
getSettings,
isQuitting: () => stopping,
shouldHydrateShellPath
})
)
void adoptLoginShellAgentHomes().then(() => {
if (stopping) {
return
}
reconcileStartupManagedAgentHooks({
getSettings,
isQuitting: () => stopping,
shouldHydrateShellPath
})
})

@OrcaWin
OrcaWin force-pushed the OrcaWin/orcad-hooks-on-connect branch from 94a44a8 to 71fba3b Compare October 10, 2026 23:50
@OrcaWin
OrcaWin merged commit b4d8e37 into main Oct 11, 2026
46 checks passed
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.

1 participant