Repository navigation
Fix Codex WSL runtime status hooks - #7969
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 5281da9572a26ac24dbc87b248d92e55eccea4a9 and 04a05cf. 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis PR adds WSL runtime support for Codex hook installation. It introduces WSL-specific path planning for configuration, trust, script, and command locations, including UNC, mounted-drive, and canonicalized Linux paths. The POSIX hook script loads command-file endpoints, posts form-encoded payloads through curl, and falls back to Windows curl.exe when needed. Runtime install and refresh flows manage hooks.json and Orca-managed trust entries. Launch preparation uses runtime-home-specific methods with fallbacks. Tests cover path planning, script behavior, subprocess posting, installation, refresh, and trust preservation. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 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: 4
🧹 Nitpick comments (1)
src/main/codex/hook-service-wsl-runtime.test.ts (1)
190-228: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueInclude stderr in assertion failure messages for faster debugging.
When the curl.exe fallback test fails,
expect(result.status).toBe(0)gives no context. Includingresult.stderrandresult.errorin the failure message would help diagnose script or environment issues quickly.♻️ Proposed improvement
expect(result.status).toBe(0) + if (result.status !== 0) { + throw new Error(`Script exited with status ${result.status}\nstderr: ${result.stderr}`) + } const posted = readFileSync(capturePath, 'utf-8')
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1d8a5761-2b2f-4b81-bcf5-a647ff5dd9b5
📥 Commits
Reviewing files that changed from the base of the PR and between 6cff93c and 17ec80cad3abbbe254f1b00174bc8f71abb2b06c.
📒 Files selected for processing (4)
src/main/codex/codex-wsl-hook-install-plan.tssrc/main/codex/hook-service-wsl-runtime.test.tssrc/main/codex/hook-service.tssrc/main/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/index.ts
| it.skipIf(process.platform === 'win32')( | ||
| 'refreshes stale hook coordinates from a Windows endpoint file', | ||
| () => { | ||
| const plan = createTestPlan() | ||
| const root = dirname(plan.configPath) | ||
| const endpointPath = join(root, 'endpoint.cmd') | ||
| const binDir = join(root, 'bin') | ||
| const curlPath = join(binDir, 'curl') | ||
| const capturePath = join(root, 'curl-args.txt') | ||
| mkdirSync(binDir, { recursive: true }) | ||
| writeFileSync( | ||
| endpointPath, | ||
| [ | ||
| 'set ORCA_AGENT_HOOK_PORT=43210', | ||
| 'set ORCA_AGENT_HOOK_TOKEN=fresh-token', | ||
| 'set ORCA_AGENT_HOOK_ENV=development', | ||
| 'set ORCA_AGENT_HOOK_VERSION=1', | ||
| '' | ||
| ].join('\r\n'), | ||
| 'utf-8' | ||
| ) | ||
| writeFileSync( | ||
| curlPath, | ||
| '#!/bin/sh\nprintf \'%s\\n\' "$@" > "$ORCA_TEST_CAPTURE"\ncat >> "$ORCA_TEST_CAPTURE"\n', | ||
| 'utf-8' | ||
| ) | ||
| chmodSync(curlPath, 0o755) | ||
| mkdirSync(dirname(plan.scriptPath), { recursive: true }) | ||
| writeFileSync(plan.scriptPath, _internals.getManagedScript('posix'), 'utf-8') | ||
|
|
||
| const result = spawnSync('/bin/sh', [plan.scriptPath], { | ||
| encoding: 'utf-8', | ||
| input: '{"hook_event_name":"UserPromptSubmit","prompt":"restart"}', | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${binDir}:${process.env.PATH ?? ''}`, | ||
| ORCA_AGENT_HOOK_ENDPOINT: endpointPath, | ||
| ORCA_AGENT_HOOK_PORT: '1', | ||
| ORCA_AGENT_HOOK_TOKEN: 'stale-token', | ||
| ORCA_PANE_KEY: 'pane-1', | ||
| ORCA_TEST_CAPTURE: capturePath | ||
| } | ||
| }) | ||
|
|
||
| expect(result.status).toBe(0) | ||
| const posted = readFileSync(capturePath, 'utf-8') | ||
| expect(posted).toContain('http://127.0.0.1:43210/hook/codex') | ||
| expect(posted).toContain('X-Orca-Agent-Hook-Token: fresh-token') | ||
| expect(posted).not.toContain('stale-token') | ||
| } | ||
| ) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add a timeout to spawnSync calls to prevent indefinite CI hangs.
Both subprocess tests (lines 168 and 209) call spawnSync without a timeout. If the hook script blocks on a network call or unexpected input, the test will hang indefinitely in CI with no output. Adding timeout: 10_000 (or similar) and checking result.error/result.signal would make failures fast and diagnosable.
🛡️ Proposed fix
const result = spawnSync('/bin/sh', [plan.scriptPath], {
encoding: 'utf-8',
+ timeout: 10_000,
input: '{"hook_event_name":"UserPromptSubmit","prompt":"restart"}',
env: {
...process.env,
PATH: `${binDir}:${process.env.PATH ?? ''}`,
ORCA_AGENT_HOOK_ENDPOINT: endpointPath,
ORCA_AGENT_HOOK_PORT: '1',
ORCA_AGENT_HOOK_TOKEN: 'stale-token',
ORCA_PANE_KEY: 'pane-1',
ORCA_TEST_CAPTURE: capturePath
}
})
- expect(result.status).toBe(0)
+ expect(result.status).toBe(0)
+ if (result.status !== 0) {
+ throw new Error(`Script exited with status ${result.status}\nstderr: ${result.stderr}`)
+ }📝 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.
| it.skipIf(process.platform === 'win32')( | |
| 'refreshes stale hook coordinates from a Windows endpoint file', | |
| () => { | |
| const plan = createTestPlan() | |
| const root = dirname(plan.configPath) | |
| const endpointPath = join(root, 'endpoint.cmd') | |
| const binDir = join(root, 'bin') | |
| const curlPath = join(binDir, 'curl') | |
| const capturePath = join(root, 'curl-args.txt') | |
| mkdirSync(binDir, { recursive: true }) | |
| writeFileSync( | |
| endpointPath, | |
| [ | |
| 'set ORCA_AGENT_HOOK_PORT=43210', | |
| 'set ORCA_AGENT_HOOK_TOKEN=fresh-token', | |
| 'set ORCA_AGENT_HOOK_ENV=development', | |
| 'set ORCA_AGENT_HOOK_VERSION=1', | |
| '' | |
| ].join('\r\n'), | |
| 'utf-8' | |
| ) | |
| writeFileSync( | |
| curlPath, | |
| '#!/bin/sh\nprintf \'%s\\n\' "$@" > "$ORCA_TEST_CAPTURE"\ncat >> "$ORCA_TEST_CAPTURE"\n', | |
| 'utf-8' | |
| ) | |
| chmodSync(curlPath, 0o755) | |
| mkdirSync(dirname(plan.scriptPath), { recursive: true }) | |
| writeFileSync(plan.scriptPath, _internals.getManagedScript('posix'), 'utf-8') | |
| const result = spawnSync('/bin/sh', [plan.scriptPath], { | |
| encoding: 'utf-8', | |
| input: '{"hook_event_name":"UserPromptSubmit","prompt":"restart"}', | |
| env: { | |
| ...process.env, | |
| PATH: `${binDir}:${process.env.PATH ?? ''}`, | |
| ORCA_AGENT_HOOK_ENDPOINT: endpointPath, | |
| ORCA_AGENT_HOOK_PORT: '1', | |
| ORCA_AGENT_HOOK_TOKEN: 'stale-token', | |
| ORCA_PANE_KEY: 'pane-1', | |
| ORCA_TEST_CAPTURE: capturePath | |
| } | |
| }) | |
| expect(result.status).toBe(0) | |
| const posted = readFileSync(capturePath, 'utf-8') | |
| expect(posted).toContain('http://127.0.0.1:43210/hook/codex') | |
| expect(posted).toContain('X-Orca-Agent-Hook-Token: fresh-token') | |
| expect(posted).not.toContain('stale-token') | |
| } | |
| ) | |
| it.skipIf(process.platform === 'win32')( | |
| 'refreshes stale hook coordinates from a Windows endpoint file', | |
| () => { | |
| const plan = createTestPlan() | |
| const root = dirname(plan.configPath) | |
| const endpointPath = join(root, 'endpoint.cmd') | |
| const binDir = join(root, 'bin') | |
| const curlPath = join(binDir, 'curl') | |
| const capturePath = join(root, 'curl-args.txt') | |
| mkdirSync(binDir, { recursive: true }) | |
| writeFileSync( | |
| endpointPath, | |
| [ | |
| 'set ORCA_AGENT_HOOK_PORT=43210', | |
| 'set ORCA_AGENT_HOOK_TOKEN=fresh-token', | |
| 'set ORCA_AGENT_HOOK_ENV=development', | |
| 'set ORCA_AGENT_HOOK_VERSION=1', | |
| '' | |
| ].join('\r\n'), | |
| 'utf-8' | |
| ) | |
| writeFileSync( | |
| curlPath, | |
| '#!/bin/sh\nprintf \'%s\\n\' "$@" > "$ORCA_TEST_CAPTURE"\ncat >> "$ORCA_TEST_CAPTURE"\n', | |
| 'utf-8' | |
| ) | |
| chmodSync(curlPath, 0o755) | |
| mkdirSync(dirname(plan.scriptPath), { recursive: true }) | |
| writeFileSync(plan.scriptPath, _internals.getManagedScript('posix'), 'utf-8') | |
| const result = spawnSync('/bin/sh', [plan.scriptPath], { | |
| encoding: 'utf-8', | |
| timeout: 10_000, | |
| input: '{"hook_event_name":"UserPromptSubmit","prompt":"restart"}', | |
| env: { | |
| ...process.env, | |
| PATH: `${binDir}:${process.env.PATH ?? ''}`, | |
| ORCA_AGENT_HOOK_ENDPOINT: endpointPath, | |
| ORCA_AGENT_HOOK_PORT: '1', | |
| ORCA_AGENT_HOOK_TOKEN: 'stale-token', | |
| ORCA_PANE_KEY: 'pane-1', | |
| ORCA_TEST_CAPTURE: capturePath | |
| } | |
| }) | |
| expect(result.status).toBe(0) | |
| if (result.status !== 0) { | |
| throw new Error(`Script exited with status ${result.status}\nstderr: ${result.stderr}`) | |
| } | |
| const posted = readFileSync(capturePath, 'utf-8') | |
| expect(posted).toContain('http://127.0.0.1:43210/hook/codex') | |
| expect(posted).toContain('X-Orca-Agent-Hook-Token: fresh-token') | |
| expect(posted).not.toContain('stale-token') | |
| } | |
| ) |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/codex/codex-wsl-hook-install-plan.ts (1)
24-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueHardcoded
/mnt/automount root; add a brief rationale comment.The fallback assumes the default WSL automount root (
/mnt/). This is correct for default configs but breaks for users who set a customautomount.rootin/etc/wsl.conf. Since this only runs as a last-resort fallback (whenparseWslUncPathyields nolinuxPath) and a wrong path degrades to anullplan downstream via thestartsWith('/')guard, the risk is low. Consider a short comment noting the default-automount assumption so the constraint is obvious to future readers.As per coding guidelines: "When writing or modifying code driven by a design doc or another non-obvious constraint, add a brief comment explaining why the code behaves that way."
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c3068449-7a7a-4411-8b68-124c72352c4a
📥 Commits
Reviewing files that changed from the base of the PR and between 17ec80cad3abbbe254f1b00174bc8f71abb2b06c and 5281da9572a26ac24dbc87b248d92e55eccea4a9.
📒 Files selected for processing (4)
config/tsconfig.cli.jsonsrc/main/codex/codex-wsl-hook-install-plan.tssrc/main/codex/hook-service.tssrc/main/index.ts
✅ Files skipped from review due to trivial changes (1)
- config/tsconfig.cli.json
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/index.ts
5281da9 to
04a05cf
Compare
Reconcile presence-gated Codex launch prep with main's #7969 WSL runtime-home status-hook install: - WSL runtime-home installs (installForRuntimeHome/refreshRuntimeUserHooksForRuntimeHome) run unconditionally and synchronously — never presence-gated, since the Windows-side PATH probe cannot see a codex CLI living inside the WSL distro (gating it would regress #7969). - Non-WSL launches keep the presence gate plus the always-run #7896 approval promotion from this branch's review fixes. - Keep both new tsconfig.cli entries and the added imports (getDefaultWslDistro, codexLaunchNeedsDirectApprovalPromotion).
Clean auto-merge, no conflicts (109 files, +7490 from main). Brought in: - Codex WSL runtime status hooks (#7969); WSL/SSH agent path resolution past shell aliases (#7867); WSL source-control path separators (#7966); WSL GitLab-auth wake fix (#7967); WSL Codex usage RPC refresh (#7567/#7658) - Improve workspace cleanup list (#7053) + background removal - mobile: per-host connection log + Tailscale wedge recovery (#7984/#7980), wake slept agents on mobile worktree open (#7906) - Harden layout validation, watcher lifecycle, connection robustness (#7924) - Disable experimental worktree card style by default (#7977) Perf-branch structure preserved (clean auto-merge). typecheck 0 errors; lint 0 errors. CI is the release gate (local runs skipped per env lag). Co-authored-by: Orca <[email protected]>
* Fix Codex WSL runtime status hooks * Harden Codex WSL hook restart handling * Harden Codex WSL hook path handling * Fix Codex hook CLI type boundary
Summary
CODEX_HOMEinstead of falling back to the Windows host runtime hook install/bin/shwrapper for UNC-written filescurlto/mnt/c/Windows/System32/curl.exeFixes #6907
Validation
pnpm exec vitest run --config config/vitest.config.ts src/main/codex/hook-service-wsl-runtime.test.ts src/main/codex/hook-service.test.ts src/main/codex/hook-trust-promotion.test.tspnpm run typecheck:nodepnpm exec oxlint src/main/codex/hook-service.ts src/main/index.ts src/main/codex/hook-service-wsl-runtime.test.tspnpm exec oxfmt --check src/main/codex/hook-service.ts src/main/index.ts src/main/codex/hook-service-wsl-runtime.test.tsElectron E2E
window.api.app.getIdentity()matchedJinwoo-H/wsl-6907-codex-worktree-status.\\wsl.localhost\Ubuntu\home\jinwoo\orca-6907-e2e-20260709161127and verified the active worktree/terminal in the sidebar.hooks.json,config.toml, and.orca/agent-hooks/codex-hook.shunder\\wsl.localhost\Ubuntu\home\jinwoo\.local\share\orca\codex-runtime-home\home, with hook commands using Linux paths.curlhidden fromPATH; the script used the Windows curl fallback and posted a native CodexUserPromptSubmitform body to the live Electron app.Working node spawned wsl hook to app 1783629054303 - Codexandlast-status.jsoncontained the same prompt, WSL worktree id, launch token, andagentType: "codex".