Skip to content

Fix Codex WSL runtime status hooks - #7969

Merged
Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/wsl-6907-codex-worktree-status
Jul 10, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/wsl-6907-codex-worktree-status

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • install Codex managed status hooks into Orca-managed WSL CODEX_HOME instead of falling back to the Windows host runtime hook install
  • write WSL runtime hook commands with Linux paths and a readable-script /bin/sh wrapper for UNC-written files
  • bridge WSL loopback failures by falling back from Linux curl to /mnt/c/Windows/System32/curl.exe
  • add focused coverage for WSL hook path planning and POSIX fallback script generation

Fixes #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.ts
  • pnpm run typecheck:node
  • pnpm exec oxlint src/main/codex/hook-service.ts src/main/index.ts src/main/codex/hook-service-wsl-runtime.test.ts
  • pnpm exec oxfmt --check src/main/codex/hook-service.ts src/main/index.ts src/main/codex/hook-service-wsl-runtime.test.ts

Electron E2E

  • Launched the dev app for this worktree with CDP and verified window.api.app.getIdentity() matched Jinwoo-H/wsl-6907-codex-worktree-status.
  • Added a WSL-backed repo at \\wsl.localhost\Ubuntu\home\jinwoo\orca-6907-e2e-20260709161127 and verified the active worktree/terminal in the sidebar.
  • Verified the WSL runtime home had hooks.json, config.toml, and .orca/agent-hooks/codex-hook.sh under \\wsl.localhost\Ubuntu\home\jinwoo\.local\share\orca\codex-runtime-home\home, with hook commands using Linux paths.
  • Ran the generated WSL hook script with Linux curl hidden from PATH; the script used the Windows curl fallback and posted a native Codex UserPromptSubmit form body to the live Electron app.
  • Confirmed the visible sidebar row updated to Working node spawned wsl hook to app 1783629054303 - Codex and last-status.json contained the same prompt, WSL worktree id, launch token, and agentType: "codex".

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 98880ebd-0cb2-4829-89b3-758db6f00618

📥 Commits

Reviewing files that changed from the base of the PR and between 5281da9572a26ac24dbc87b248d92e55eccea4a9 and 04a05cf.

📒 Files selected for processing (5)
  • config/tsconfig.cli.json
  • src/main/codex/codex-wsl-hook-install-plan.ts
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/codex/hook-service.ts
  • src/main/index.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • config/tsconfig.cli.json
  • src/main/index.ts
  • src/main/codex/hook-service.ts

📝 Walkthrough

Walkthrough

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

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but it omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including Screenshots, AI Review Report, Security Audit, and Notes, or state No visual change where applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing Codex WSL runtime status hooks.
Linked Issues check ✅ Passed The changes directly address #6907 by installing managed WSL hooks, using Linux paths, and adding curl.exe fallback behavior and tests.
Out of Scope Changes check ✅ Passed The modified files are all tied to WSL hook planning, installation, refresh, and test coverage, with no clear unrelated changes.
✨ Finishing Touches
📝 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: 4

🧹 Nitpick comments (1)
src/main/codex/hook-service-wsl-runtime.test.ts (1)

190-228: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Include stderr in assertion failure messages for faster debugging.

When the curl.exe fallback test fails, expect(result.status).toBe(0) gives no context. Including result.stderr and result.error in 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.ts
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/codex/hook-service.ts
  • src/main/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/index.ts

Comment on lines +138 to +188
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')
}
)

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

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.

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

Comment thread src/main/codex/hook-service.ts Resolved
Comment thread src/main/codex/hook-service.ts Resolved

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

🧹 Nitpick comments (1)
src/main/codex/codex-wsl-hook-install-plan.ts (1)

24-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hardcoded /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 custom automount.root in /etc/wsl.conf. Since this only runs as a last-resort fallback (when parseWslUncPath yields no linuxPath) and a wrong path degrades to a null plan downstream via the startsWith('/') 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.json
  • src/main/codex/codex-wsl-hook-install-plan.ts
  • src/main/codex/hook-service.ts
  • src/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

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/wsl-6907-codex-worktree-status branch from 5281da9 to 04a05cf Compare July 10, 2026 00:13
@Jinwoo-H
Jinwoo-H merged commit 4ead072 into main Jul 10, 2026
2 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/wsl-6907-codex-worktree-status branch July 10, 2026 00:17
brennanb2025 pushed a commit that referenced this pull request Jul 10, 2026
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).
Jinwoo-H added a commit that referenced this pull request Jul 10, 2026
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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Fix Codex WSL runtime status hooks

* Harden Codex WSL hook restart handling

* Harden Codex WSL hook path handling

* Fix Codex hook CLI type boundary
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]: Codex launched in a WSL worktree does not appear in agent status/sidebar

1 participant