Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughAdds Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to Remote managed-hook installation now resolves redirected Codex homes, but supported shell-wrapper configurations and certain reported paths can still lead to hooks being installed in the wrong location or not installed for the active Codex home. These correctness issues should be resolved before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
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: bac2160d-439f-4cc7-b217-187728e4e3e0
📒 Files selected for processing (4)
src/main/agent-hooks/codex-app-server-home-probe.test.tssrc/main/agent-hooks/codex-app-server-home-probe.tssrc/main/agent-hooks/managed-hook-runtime.test.tssrc/main/agent-hooks/managed-hook-runtime.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
|
|
||
| function onData(chunk: Buffer): void { | ||
| bytesRead += chunk.length | ||
| pending += chunk.toString('utf8') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -eu
file="src/main/agent-hooks/codex-app-server-home-probe.ts"
ast-grep outline "$file" --view expanded
printf '\n--- relevant source ---\n'
sed -n '1,190p' "$file"
printf '\n--- related tests and call sites ---\n'
rg -n --glob '!node_modules' 'probeCodexHomeViaAppServer|codex-app-server-home-probe|setEncoding|StringDecoder' src test tests 2>/dev/null || trueRepository: stablyai/orca
Length of output: 24079
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings
Length of output: 38291
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- probe tests ---'
sed -n '1,180p' src/main/agent-hooks/codex-app-server-home-probe.test.ts
printf '%s\n' '--- probe callers and codexHome validation ---'
rg -n -C 5 'probeCodexHomeViaAppServer|codexHome|CODEX_HOME' src/main/agent-hooks src/main/codex src/shared/child-process
printf '%s\n' '--- spawnProcess binding ---'
rg -n -C 8 'export .*spawnProcess|function spawnProcess|const spawnProcess' src/shared/child-processRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- probe tests ---'
sed -n '1,170p' src/main/agent-hooks/codex-app-server-home-probe.test.ts
printf '%s\n' '--- direct probe references ---'
rg -n -C 12 'probeCodexHomeViaAppServer' src/main/agent-hooks
printf '%s\n' '--- exact process binding ---'
sed -n '1,180p' src/shared/child-process/run-process.tsRepository: stablyai/orca
Length of output: 23952
🏁 Script executed:
#!/bin/bash
set -eu
sed -n '92,145p' src/main/agent-hooks/managed-hook-runtime.ts
sed -n '1,95p' src/main/agent-hooks/managed-hook-runtime.ts
rg -n -C 8 'resolveRelayCodexHome|install.*Hook|codexHome' src/main/agent-hooks/managed-hook-runtime.ts src/main/agent-hooks/managed-agent-hook-controls.ts src/cli/handlers/agent-hooks.tsRepository: stablyai/orca
Length of output: 16597
Preserve UTF-8 sequences across stdout chunks.
spawnProcess leaves child.stdout in Buffer mode. chunk.toString('utf8') can replace a multibyte character split across chunks. normalizePosixAgentHome accepts the replacement character and passes the corrupted path to hook installation. Use child.stdout.setEncoding('utf8') or StringDecoder. Add a test that splits a non-ASCII path across two writes.
| ? '/bin/sh' | ||
| : candidate | ||
| const shellName = basename(shell) | ||
| return { shell, flag: shellName === 'sh' || shellName === 'dash' ? '-c' : '-lc' } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- target file ---'
sed -n '1,150p' src/main/agent-hooks/managed-hook-runtime.ts
printf '%s\n' '--- relevant symbols and tests ---'
rg -n --glob '!node_modules' --glob '!dist' 'shellName|managed-hook-runtime|Codex|profile|PATH|wrapper|find.*codex|codex' src test tests .github 2>/dev/null | head -240Repository: stablyai/orca
Length of output: 34308
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings
Length of output: 33267
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- probe implementation ---'
sed -n '1,260p' src/main/agent-hooks/codex-app-server-home-probe.ts
printf '%s\n' '--- direct callers and tests ---'
rg -n -C 8 'probeCodexHomeViaAppServer|loginShellFlag|resolveRelayCodexHome|loginShellInvocation' src/main/agent-hooksRepository: stablyai/orca
Length of output: 27190
Start sh and dash as login shells.
loginShellInvocation() returns -c for these shells, and probeCodexHomeViaAppServer() passes that flag directly to the shell. The probe therefore does not load .profile; it can miss a Codex wrapper added there and fall back to ~/.codex. Pass -l and -c as separate arguments, and test a wrapper available only through .profile.
🧰 Tools
🪛 ast-grep (0.45.3)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
| loginShellFlag: flag, | ||
| ...(signal ? { signal } : {}) | ||
| }) | ||
| return (reported === null ? null : normalizePosixAgentHome(reported.trim())) ?? fallback |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Validate the reported path before trimming it.
normalizePosixAgentHome rejects surrounding whitespace. Calling reported.trim() first converts a malformed value such as " /tmp/codex " into an accepted path instead of using the fallback.
Pass reported directly and add leading- and trailing-whitespace cases.
Proposed fix
- return (reported === null ? null : normalizePosixAgentHome(reported.trim())) ?? fallback
+ return (reported === null ? null : normalizePosixAgentHome(reported)) ?? fallback📝 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.
| return (reported === null ? null : normalizePosixAgentHome(reported.trim())) ?? fallback | |
| return (reported === null ? null : normalizePosixAgentHome(reported)) ?? fallback |
🧰 Tools
🪛 ast-grep (0.45.3)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
There was a problem hiding this comment.
Important
The feature is sound and the fallback is always ~/.codex (today's behavior), so the worst case is a silent no-op rather than breakage. Two robustness gaps in the hand-rolled probe are worth fixing before merge (inline).
Reviewed changes
codex-app-server-home-probe.ts(new) — spawnscodex app-serverthrough the login shell, writes aninitializerequest over a held-open pipe, and parses the reply line-by-line forcodexHome.managed-hook-runtime.ts— generalizes the Grok home helpers (defaultAgentHome,normalizePosixAgentHome,loginShellInvocation) and addsresolveRelayCodexHome, gated on a detectedcodexagent and threaded into the remote installer ascodexHomeDir.- Tests — a pipe-driven probe suite plus
resolveRelayCodexHomeand end-to-end install cases asserting hooks land in the reported home and~/.codexis untouched.
ℹ️ Hand-rolled app-server lifecycle vs. the hardened session runner
The repo already has a hardened codex app-server stdio lifecycle (runCodexAppServerSession in src/main/codex/codex-app-server-session.ts) that performs this exact initialize handshake, reads the result, classifies old CLIs, pairs the CLI with its node runtime (#10932), and reaps the process tree. This probe re-implements spawn/parse/reap by hand, and the two will drift on the same codex contract. The login-shell requirement (to resolve the wrapper) may genuinely justify a separate path, but it is worth confirming the relay bundle cannot import the existing runner before settling on a parallel lifecycle.
Technical details
# Reconcile the probe with the existing app-server lifecycle
## Affected sites
- src/main/agent-hooks/codex-app-server-home-probe.ts — hand-rolled spawn + line parse + kill
- src/main/codex/codex-app-server-session.ts — existing initialize → reap lifecycle
## Divergences the existing runner handles and the probe does not
- `withCliRuntimeOnPath` node pairing (#10932), so a version-manager-installed CLI resolves its node
- `stderrIndicatesMissingAppServer` capability classification (old CLI → unsupported, cacheable)
- stdin-EOF + grace + `killCodexAppServerProcessTree` reap instead of a bare `child.kill()`
## Open questions for the human
- Can the relay bundle import `runCodexAppServerSession`, or is the standalone `managed-hook-runtime.js` boundary the reason for the parallel implementation?ℹ️ Nitpicks
codexHomeDirinsrc/main/agent-hooks/remote-managed-hook-installers.ts:19is now also set for PATH-wrapper redirects, not only WSL runtime homes — the field's doc comment ("for example WSL's managed runtime home") no longer captures that the wrapper case routes through the same redirected branch (prepended hook ordering, script under<codexHome>/.orca/).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| child.stdin.off('error', onFailure) | ||
| // Why: the handshake is all we wanted; a long-lived app-server here would | ||
| // outlive the install and hold the user's Codex state files open. | ||
| child.kill() |
There was a problem hiding this comment.
child.kill() sends a bare SIGTERM with no descendant reap, no SIGKILL escalation, and no exit wait. On POSIX, npm/package-manager codex launchers insert a shim child (see the comment in killCodexAppServerProcessTree), so killing only the shim leaves the real app-server alive and holding state files open — the exact lingering-process risk this block warns about two lines up. End stdin and/or reuse killCodexAppServerProcessTree with a grace timer.
Technical details
# Reap the probe child the way the rest of the codebase does
## Affected sites
- src/main/agent-hooks/codex-app-server-home-probe.ts:96 — `child.kill()` in `settle()`
- src/main/codex/codex-app-server-process-tree-kill.ts:60 — POSIX path reaps shim descendants with `pkill -KILL -P` then `child.kill('SIGKILL')`
## Required outcome
- A probe child that does not exit on SIGTERM (or a codex shim that spawns the real app-server as a child) must not outlive the install, or it will hold the user's Codex state files open.
## Suggested approach (optional)
- After `settle()`, end stdin and wait a short grace, then escalate via `killCodexAppServerProcessTree(child)` — or call that helper directly instead of `child.kill()`.| child.on('error', onFailure) | ||
| child.on('close', onClose) | ||
| child.stdin.on('error', onFailure) | ||
| child.stdout.on('data', onData) |
There was a problem hiding this comment.
child.stdout has no 'error' listener. An unhandled 'error' on a child stream is an uncaught exception that takes the relay process down — the repo's own runProcess attaches a no-op listener to all three child streams for exactly this reason (src/shared/child-process/run-process.ts:122-124). child and child.stdin are covered here; child.stdout is not. Add child.stdout.on('error', onFailure) alongside line 133 and remove it in settle().
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the redirect-layout fix is correct and closes the concern from the prior review. The two probe-hardening findings on
codex-app-server-home-probe.tsremain open (that file is unchanged).
Reviewed changes
resolveRelayCodexHome→resolveRelayRedirectedCodexHome— now returnsnullfor the ordinary~/.codexinstead of the path, andinstallManagedHooksonly forwardscodexHomeDirwhen a real redirect is detected. Unwrapped hosts therefore keep the incumbent~/.orca/agent-hookslayout rather than adopting the WSL-shaped redirected contract (script relocation, command wrapper, hook ordering).- Tests — new cases assert an unwrapped host keeps its incumbent layout (script under
~/.orca, none under~/.codex/.orca) and a redirected host moves the script underCODEX_HOME, plus thenull-for-default-home and non-answer expectations.
The equality check (codexHome === defaultAgentHome(home, '.codex')) is a sound way to detect "not actually redirected": both sides are trailing-slash-normalized, and any mismatch simply falls through to the redirected contract, which is still a correct install target.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in this delta — dropping Orca's injected
CODEX_HOME/ORCA_CODEX_HOMEfrom the probe environment is the right call and correctly pinsHOME. The two probe-hardening findings oncodex-app-server-home-probe.tsremain open (unchanged since the first review).
Reviewed changes
buildCodexProbeEnvironment(new) — clonesprocess.env, pinsHOMEto the installer-resolved home, and deletesCODEX_HOME/ORCA_CODEX_HOMEso the app-server cannot echo back the value Orca injected for its own managed accounts.resolveRelayRedirectedCodexHomenow passes this env to the probe.- Tests — cover the env-dropping, the
HOMEpin, and an end-to-end case asserting the fakecodexfalls back to$HOME/.codexrather than Orca's injected home.
The one nuance worth noting (not blocking): a login shell (-lc) could re-export a CODEX_HOME set in the user's profile, which is exactly the intended behavior — so the dropped values only guard the inherited (Orca-injected) case, not a user-level override. That matches the comment and is correct.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ds them A `codex` launcher wrapper earlier on `PATH` can `export CODEX_HOME=...` and `exec` the real binary. The value then exists only inside the Codex process: the parent PTY's login shell reports nothing, so the relay installer fell back to `~/.codex` while Codex read `~/.codex-openai`. Orca got no authoritative lifecycle events, and a Codex pane's status dropped to terminal heuristics and vanished after a completed turn because no `Stop` hook ever arrived. The installer now asks Codex itself. `codex app-server`'s `initialize` reply carries `codexHome`, which is the wrapper-aware answer because it comes from the process the wrapper configured. The probe runs through the same login shell an agent PTY would, since that is what resolves the wrapper, and reads stdout a line at a time so a profile banner ahead of the JSON cannot corrupt the reply — `codex app-server` also exits without answering once stdin reaches EOF, so the request pipe stays open until the reply lands. Only a positively detected Codex pays for the probe. No Codex on PATH, a CLI too old for the handshake, a timeout, an abort, or a non-POSIX answer all fall back to `~/.codex`, which is the incumbent behaviour. Fixes #19598
…eally moved `installRemote` treats an explicit `codexHomeDir` as a redirected runtime home: it moves the hook script under that home, switches the command wrapper to the readable form and prepends rather than appends the managed hook group. Passing it `~/.codex` for every host applied that WSL-shaped contract to plain SSH hosts too, relocating the script from `~/.orca/agent-hooks/codex-hook.sh` to `~/.codex/.orca/agent-hooks/codex-hook.sh` for users who have no wrapper at all. `resolveRelayRedirectedCodexHome` now answers `null` for the ordinary home, and the installer only receives `codexHomeDir` when Codex really did name somewhere else. Verified against the Linux SSH host: an unwrapped host reproduces the `origin/main` layout exactly, and a wrapped one installs under the reported home.
Orca exports CODEX_HOME/ORCA_CODEX_HOME for its managed Codex accounts. The probe inherited them, so it reported Orca's own account home as if the host user had redirected there — which broke the Node 18 managed-hook smoke and would have installed hooks into the managed account home on any client that runs the relay in-process. The child now gets the installer's HOME pinned and both variables stripped; a redirect the user's profile or launcher sets is unaffected, since the login shell re-exports it.
f8cde6e to
b8bfd89
Compare
|
Status note after the SSH relay removal: |
|
Closing: this branch is stale against the current remote hook installer, and the right behaviour for wrapper-forced CODEX_HOME (#19598) is still an open design question (support with ownership tracking vs document vs detect-and-warn). Tracking there. |

Note
Superseded-pending — do not merge unless #19701 stalls.
#19701 fixes the same issue on a better structure: it reuses the shared
runCodexAppServerSessionhelper instead of standing up a second probe. Itscommand resolution didn't reach the reporter's wrapper, so I pushed that delta
to its branch as
98162669648and verified it on the host. Once #19701 isgreen with that in place, close this one unmerged. Kept open only as a
fallback if that branch goes quiet.
Fixes #19598
ELI5
Codex keeps its settings in a folder. Normally that's
~/.codex, but some peoplehave a little
codexlauncher script that quietly points Codex at a differentfolder — say
~/.codex-openai— and then starts the real Codex.Orca puts its "tell me when the agent starts and stops" hooks into that folder.
It was always putting them in
~/.codex, because the launcher only sets the newlocation inside Codex, where nobody outside can see it. So Codex read one
folder, Orca wrote the other, and Orca never heard a thing: the Codex pane's
status fell back to guessing from terminal output and then vanished after a turn
finished, because no "Stop" hook ever arrived.
Now Orca just asks Codex where its folder is, and puts the hooks there.
What changed
codex app-server'sinitializereply carriescodexHome. That is theauthoritative answer, because it comes from the same process the launcher
configured. The relay-side installer asks for it once, through the same login
shell an agent PTY would use — that's what puts the wrapper on
PATHin thefirst place.
Two things the real host taught this implementation:
codex app-serverexits without answering once stdin reaches EOF, so therequest pipe has to stay open until the reply arrives. Writing the request and
closing (what
runProcess({ input })does) yields exit 0 and empty stdout.a line at a time and non-matching lines are skipped.
resolveRelayRedirectedCodexHomeanswersnullfor the ordinary~/.codex,not the path. That matters:
installRemotetreats an explicitcodexHomeDirasa redirected runtime home and moves the hook script under it, switches the
command wrapper and reorders the hook groups. Handing it
~/.codexwould applythat WSL-shaped contract to every unwrapped SSH host too. Unwrapped hosts keep
the exact layout they have today — verified byte-for-byte against
origin/mainon a real host (below).
Only a positively detected Codex pays for the probe. No Codex on
PATH, a CLItoo old for the handshake, a timeout, an abort, or a non-POSIX answer all read as
"not redirected".
Proof, on a real macOS client → Linux SSH host
Host
openclaw(Ubuntu 24.04, codex-cli 0.153.0), with the issue's exact wrapperfirst on
PATH:The login shell cannot see it, but Codex can:
Running the shipped relay artifact (
out/relay/linux-x64/managed-hook-runtime.js)built from each ref, on that host, against a throwaway
$HOME:Wrapper present
origin/main@ 2bf298d.codex/hooks.json$HOME/.orca/agent-hooks/codex-hook.sh.codex-openai/hooks.json$HOME/.codex-openai/.orca/agent-hooks/codex-hook.shNo wrapper — no change, which is the point
origin/main@ 2bf298d.codex/hooks.json$HOME/.orca/agent-hooks/codex-hook.sh.codex/hooks.json$HOME/.orca/agent-hooks/codex-hook.shWindows host
awinover SSH: no/bin/sh, so the probe fails instantly andreports "not redirected" — unchanged from today. Windows SSH remotes never reach
the managed-hook installer anyway (
installManagedHooksOnRemotereturns earlyfor them).
Side effect worth knowing
Starting
codex app-servermakes Codex run its own first-run initialisation, soa host that has never launched Codex gains its usual
~/.codexstate files(sqlite, bundled system skills) at hook-install time instead of at first launch.
The installer already created that directory to write
hooks.jsonand the trustentries, and the probe only runs for a positively detected Codex, so this is
earlier — not new.
Tests
codex-app-server-home-probe.test.tsdrives a real child over pipes with a fakecodexonPATH: reply, banner-then-reply, notification-then-reply, non-zeroexit, never-replies (deadline), missing binary, abort.
managed-hook-runtime.test.tscovers the end-to-end cases — a wrappedcodexputs hooks and script under the reported home; an unwrapped one keeps the
incumbent
~/.orca/agent-hookslayout — plus validation and "don't probeundetected agents".
Mutation results (9/9 killed)
codexHomeDirto the installerinstalls into the home Codex reports…,moves the hook script under a redirected home…reports the CODEX_HOME the host's own Codex names~/.codexas a redirect (the regression this branch's second commit fixes)reports no redirect when Codex names the ordinary home,leaves an unwrapped host on its incumbent ~/.codex layoutdoes not probe for a host with no detected Codexinitializeanswers null when the CLI never replies, without hanginganswers null once the install is abortedTwo survivors were found and fixed rather than reported away:
not the latency, so the 12s default deadline satisfied it. It now asserts the
probe settles in under 5s with the deadline pushed to 60s.
~/.codexas a redirect was a real defect in the first commit, foundby the readiness checklist and confirmed on the host: every unwrapped SSH user
would have had their hook script relocated. Second commit fixes it, with the
host A/B above as proof.
Gates
pnpm tc,pnpm test src/main/agent-hooks src/main/codex src/shared/child-process/child-process-import-boundary.test.ts,oxlint,pnpm run check:code-quality:changed,pnpm format.Rebase record (2026-09-11)
Rebased onto
mainat5fa62feda7c264c6eda99ba4788ffebab9aae26c. No conflicts; all 3 commit(s) replayed as-is.f8cde6efe29d430a02bb6cc74948e9e6ad8d4487b8bfd89ebbbb90e94d2b9c77f53ed5562c2d2693