Repository navigation
fix(orcad): install agent status hooks when a managed host starts - #27319
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to 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 |
|
There was a problem hiding this comment.
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.tssrc/main/orcad/orcad-entry.tssrc/main/orcad/orcad-managed-agent-hooks.tssrc/main/orcad/orcad-push-startup.test.tssrc/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(), { |
There was a problem hiding this comment.
🎯 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-hooksRepository: 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 -260Repository: 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-launchRepository: 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 -100Repository: 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.
490fee1 to
94a44a8
Compare
There was a problem hiding this comment.
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.txtsrc/main/agent-hooks/agent-home-login-shell.test.tssrc/main/agent-hooks/agent-home-login-shell.tssrc/main/agent-hooks/managed-hook-runtime.test.tssrc/main/agent-hooks/managed-hook-runtime.tssrc/main/orcad/orcad-managed-agent-hooks.tssrc/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' |
There was a problem hiding this comment.
🎯 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] ?? '') |
There was a problem hiding this comment.
🎯 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.
| void adoptLoginShellAgentHomes().then(() => | ||
| reconcileStartupManagedAgentHooks({ | ||
| getSettings, | ||
| isQuitting: () => stopping, | ||
| shouldHydrateShellPath | ||
| }) | ||
| ) |
There was a problem hiding this comment.
🩺 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 -80Repository: 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.
| void adoptLoginShellAgentHomes().then(() => | |
| reconcileStartupManagedAgentHooks({ | |
| getSettings, | |
| isQuitting: () => stopping, | |
| shouldHydrateShellPath | |
| }) | |
| ) | |
| void adoptLoginShellAgentHomes().then(() => { | |
| if (stopping) { | |
| return | |
| } | |
| reconcileStartupManagedAgentHooks({ | |
| getSettings, | |
| isQuitting: () => stopping, | |
| shouldHydrateShellPath | |
| }) | |
| }) |
94a44a8 to
71fba3b
Compare
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
~/.codex, after shell PATH hydrationinstallManagedAgentHooks)GROK_HOME/KIRO_HOMEfrom the user's login shell if orcad's own environment lacks them. orcad starts from a plainsh -cover 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-onlymanaged-hook-runtime.tsintosrc/main/agent-hooks/agent-home-login-shell.ts, which survives the relay deletion and now runs through@orca/process-host.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
tsc -p config/tsconfig.node.jsonis 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:~/.codexand installs managed hooks with the profile settings. This fails on main (expected "vi.fn()" to be called once, but got 0 times).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, andpnpm 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
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)