Skip to content

fix(agent-hooks): install remote Codex hooks where Codex actually reads them - #19864

Closed
nwparker wants to merge 3 commits into
mainfrom
fix/remote-codex-home-hook-install
Closed

nwparker wants to merge 3 commits into
mainfrom
fix/remote-codex-home-hook-install

Conversation

@nwparker

@nwparker nwparker commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Note

Superseded-pending — do not merge unless #19701 stalls.

#19701 fixes the same issue on a better structure: it reuses the shared
runCodexAppServerSession helper instead of standing up a second probe. Its
command resolution didn't reach the reporter's wrapper, so I pushed that delta
to its branch as 98162669648 and verified it on the host. Once #19701 is
green with that in place, close this one unmerged. Kept open only as a
fallback if that branch goes quiet.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​300 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​298
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​225 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​209

Fixes #19598

ELI5

Codex keeps its settings in a folder. Normally that's ~/.codex, but some people
have a little codex launcher script that quietly points Codex at a different
folder — 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 new
location 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's initialize reply carries codexHome. That is the
authoritative 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 PATH in the
first place.

Two things the real host taught this implementation:

  • codex app-server exits without answering once stdin reaches EOF, so the
    request 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 login shell can print a profile banner before the JSON, so stdout is parsed
    a line at a time and non-matching lines are skipped.

resolveRelayRedirectedCodexHome answers null for the ordinary ~/.codex,
not the path. That matters: installRemote treats an explicit codexHomeDir as
a redirected runtime home and moves the hook script under it, switches the
command wrapper and reorders the hook groups. Handing it ~/.codex would apply
that WSL-shaped contract to every unwrapped SSH host too. Unwrapped hosts keep
the exact layout they have today — verified byte-for-byte against origin/main
on a real host (below).

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 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 wrapper
first on PATH:

#!/usr/bin/env bash
set -euo pipefail
export CODEX_HOME="$HOME/.codex-openai"
exec /usr/local/bin/codex "$@"

The login shell cannot see it, but Codex can:

login-shell CODEX_HOME: unset
initialize: {"id":1,"result":{"codexHome":"/home/neil/.codex-openai",...}}

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

build hooks.json script it references
origin/main @ 2bf298d .codex/hooks.json $HOME/.orca/agent-hooks/codex-hook.sh
this branch .codex-openai/hooks.json $HOME/.codex-openai/.orca/agent-hooks/codex-hook.sh

No wrapper — no change, which is the point

build hooks.json script it references
origin/main @ 2bf298d .codex/hooks.json $HOME/.orca/agent-hooks/codex-hook.sh
this branch .codex/hooks.json $HOME/.orca/agent-hooks/codex-hook.sh

Windows host awin over SSH: no /bin/sh, so the probe fails instantly and
reports "not redirected" — unchanged from today. Windows SSH remotes never reach
the managed-hook installer anyway (installManagedHooksOnRemote returns early
for them).

Side effect worth knowing

Starting codex app-server makes Codex run its own first-run initialisation, so
a host that has never launched Codex gains its usual ~/.codex state files
(sqlite, bundled system skills) at hook-install time instead of at first launch.
The installer already created that directory to write hooks.json and the trust
entries, and the probe only runs for a positively detected Codex, so this is
earlier — not new.

Tests

codex-app-server-home-probe.test.ts drives a real child over pipes with a fake
codex on PATH: reply, banner-then-reply, notification-then-reply, non-zero
exit, never-replies (deadline), missing binary, abort.
managed-hook-runtime.test.ts covers the end-to-end cases — a wrapped codex
puts hooks and script under the reported home; an unwrapped one keeps the
incumbent ~/.orca/agent-hooks layout — plus validation and "don't probe
undetected agents".

Mutation results (9/9 killed)

mutation killed by
don't pass codexHomeDir to the installer installs into the home Codex reports…, moves the hook script under a redirected home…
never redirect + reports the CODEX_HOME the host's own Codex names
treat ~/.codex as 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 layout
skip POSIX/control-char validation the 4 invalid-shape cases
probe for every host does not probe for a host with no detected Codex
never send initialize the 3 reply-reading cases
take the first stdout line verbatim the 3 reply-reading cases
remove the probe deadline answers null when the CLI never replies, without hanging
ignore the abort signal answers null once the install is aborted

Two survivors were found and fixed rather than reported away:

  • ignore the abort signal survived because the test asserted the value but
    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.
  • treat ~/.codex as a redirect was a real defect in the first commit, found
    by 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 main at 5fa62feda7c264c6eda99ba4788ffebab9aae26c. No conflicts; all 3 commit(s) replayed as-is.

SHA
old head f8cde6efe29d430a02bb6cc74948e9e6ad8d4487
new head b8bfd89ebbbb90e94d2b9c77f53ed5562c2d2693

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 59eac17b-d0d5-4d66-8f05-4f504c012009

📥 Commits

Reviewing files that changed from the base of the PR and between 584c066 and f8cde6e.

📒 Files selected for processing (3)
  • src/main/agent-hooks/codex-app-server-home-probe.test.ts
  • src/main/agent-hooks/codex-app-server-home-probe.ts
  • src/main/agent-hooks/managed-hook-runtime.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Adds probeCodexHomeViaAppServer, which launches the host codex command through a login shell and reads initialize.result.codexHome. The probe handles shell output, notifications, timeouts, aborts, process errors, and stdout limits. Managed hook installation now resolves and validates the reported Codex home, then passes it to the installer. Tests cover probe failures, redirected homes, fallback behavior, and hook placement.

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to f8cde

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 4 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 The changes satisfy issue #19598 by probing the Codex app server through the login shell, validating the reported codexHome, installing redirected hooks there, preserving the ordinary ~/.codex layout,…
Out of Scope Changes check ✅ Passed The production changes and tests are focused on remote managed Codex hook installation and its fallback behavior. No unrelated code changes are evident.
Title check ✅ Passed The title clearly and concisely describes the primary change: installing remote Codex hooks in the directory used by Codex.
Description check ✅ Passed The description is detailed and covers the problem, solution, rationale, linked issue, behavioral proof, testing, platform impact, fallback behavior, and scope. It omits some template headings and che…
  • Fix all pre-merge checks with AI
✨ 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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: bac2160d-439f-4cc7-b217-187728e4e3e0

📥 Commits

Reviewing files that changed from the base of the PR and between 2bf298d and 95dc6bf.

📒 Files selected for processing (4)
  • src/main/agent-hooks/codex-app-server-home-probe.test.ts
  • src/main/agent-hooks/codex-app-server-home-probe.ts
  • src/main/agent-hooks/managed-hook-runtime.test.ts
  • src/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')

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

🔎 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 || true

Repository: 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-process

Repository: 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.ts

Repository: 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.ts

Repository: 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' }

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

🔎 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 -240

Repository: 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-hooks

Repository: 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

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

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.

Suggested change
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)

@pullfrog pullfrog 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.

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) — spawns codex app-server through the login shell, writes an initialize request over a held-open pipe, and parses the reply line-by-line for codexHome.
  • managed-hook-runtime.ts — generalizes the Grok home helpers (defaultAgentHome, normalizePosixAgentHome, loginShellInvocation) and adds resolveRelayCodexHome, gated on a detected codex agent and threaded into the remote installer as codexHomeDir.
  • Tests — a pipe-driven probe suite plus resolveRelayCodexHome and end-to-end install cases asserting hooks land in the reported home and ~/.codex is 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

  • codexHomeDir in src/main/agent-hooks/remote-managed-hook-installers.ts:19 is 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/).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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()

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.

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)

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.

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().

@pullfrog pullfrog 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.

ℹ️ 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.ts remain open (that file is unchanged).

Reviewed changes

  • resolveRelayCodexHome → resolveRelayRedirectedCodexHome — now returns null for the ordinary ~/.codex instead of the path, and installManagedHooks only forwards codexHomeDir when a real redirect is detected. Unwrapped hosts therefore keep the incumbent ~/.orca/agent-hooks layout 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 under CODEX_HOME, plus the null-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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

ℹ️ No new issues in this delta — dropping Orca's injected CODEX_HOME/ORCA_CODEX_HOME from the probe environment is the right call and correctly pins HOME. The two probe-hardening findings on codex-app-server-home-probe.ts remain open (unchanged since the first review).

Reviewed changes

  • buildCodexProbeEnvironment (new) — clones process.env, pins HOME to the installer-resolved home, and deletes CODEX_HOME/ORCA_CODEX_HOME so the app-server cannot echo back the value Orca injected for its own managed accounts. resolveRelayRedirectedCodexHome now passes this env to the probe.
  • Tests — cover the env-dropping, the HOME pin, and an end-to-end case asserting the fake codex falls back to $HOME/.codex rather 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.

Pullfrog  | Fix it ➔ | View workflow run | Using 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.
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Status note after the SSH relay removal: managed-hook-runtime.ts is gone, and on SSH hosts hooks are now installed by Orca's managed remote server at startup (src/main/orcad/orcad-managed-agent-hooks.ts, #27319), which still always targets ~/.codex. So #19598 still applies, but this branch (and #19701) would need to move to that orcad startup path.

@nwparker

Copy link
Copy Markdown
Contributor Author

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.

@nwparker nwparker closed this Oct 26, 2026
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]: Remote hook install ignores CODEX_HOME set by Codex launcher wrapper

2 participants