Skip to content

test(codex): validate guarded POSIX hook launchers - #8390

Closed
bbingz wants to merge 5 commits into
stablyai:mainfrom
bbingz:fix/codex-hooks-argv-safe-posix
Closed

bbingz wants to merge 5 commits into
stablyai:mainfrom
bbingz:fix/codex-hooks-argv-safe-posix

Conversation

@bbingz

@bbingz bbingz commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Closeout

Do not merge. The original root-cause claim was overturned by primary-source and runtime evidence, so this PR is closed as unsupported rather than landing a harmful compatibility change.

Official openai/codex executes the complete hook command through the detected shell (-c, with $SHELL -lc fallback); hooks engine history shows that behavior from its initial implementation. The proposed direct /bin/sh <path> launcher removed Orca's missing/unreadable-script guard and stdin drain. With a missing managed script and a 1 MiB payload, it reproducibly returned exit 127 and raised EPIPE under both -c and -lc. It also could not represent paths containing spaces under the hypothesized naive whitespace splitter.

Head 305bf6b8ecc5826e06b3e414eafba4ff129f70aa restores the guarded launchers before closure, so this branch is no longer unsafe to check out. Relative to main, the remaining production diff is only compatibility bookkeeping for direct trust hashes emitted by this unmerged PR; that is not a justified long-term product change.

Related: #8110 remains open. Closing it requires the reporter's exact codex --version, binary provenance, and actual child argv/runner trace.

Verification

  • RED on the direct launcher: missing script under shell -c and -lc produced exit 127 plus write EPIPE.
  • GREEN after restoring guards: 5 focused files, 110 passed and 8 platform-skipped.
  • pnpm run typecheck passed.
  • pnpm run lint passed, including reliability, max-lines, and localization gates.
  • oxfmt --check on all 6 changed files passed.
  • git diff --check passed.

Primary evidence

  • openai/codex command_runner.rs: the complete command is appended to shell args and stdin is written after spawn.
  • openai/codex session shell wiring: detected POSIX shells use -c; fallback uses $SHELL -lc.

Codex direct-execs hooks.json commands via argv split, not a shell.
wrapPosixHookCommand's if/then/fi guard became argv0=`if` → exit 127 and
Broken pipe on every managed hook (stablyai#8110). Emit `/bin/sh '<path>'` for
Codex local/WSL/SSH installs, keep the guarded wrapper for shell-based
agents, and still recognize legacy guarded trust hashes on remove.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Codex POSIX trust cleanup now recognizes guarded, direct, readable, executable, and legacy command variants, including timeout-bearing and timeout-free hashes. WSL runtime tests cover legacy trust replacement, shell execution with -c and -lc, quoted script paths, stdin draining, and missing scripts. Additional tests assert exact wrapped POSIX commands in installer output and generated Codex runtime hooks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description does not follow the required template and is missing the Summary, Screenshots, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description using the repository template and fill in all required sections, including the cross-platform review and security audit.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the main POSIX hook-launcher validation work in this PR.

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.

🧹 Nitpick comments (1)
src/main/agent-hooks/installer-utils.ts (1)

134-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Single-quote escaping logic is duplicated across three call sites.

The `'${scriptPath.replaceAll("'", "'\\''")}'` POSIX-quoting expression is repeated verbatim in wrapPosixHookCommand (this file), wrapPosixDirectHookCommand (this file), and again inline in codexPosixTrustCommandVariants (src/main/codex/hook-service.ts:148). Extracting a shared exported helper would reduce the risk of the escaping logic silently diverging across sites.

♻️ Proposed shared helper
+export function posixSingleQuote(value: string): string {
+  return `'${value.replaceAll("'", "'\\''")}'`
+}
+
 export function wrapPosixHookCommand(scriptPath: string, env: Record<string, string> = {}): string {
-  const quoted = `'${scriptPath.replaceAll("'", "'\\''")}'`
+  const quoted = posixSingleQuote(scriptPath)
   ...
 }

 export function wrapPosixDirectHookCommand(scriptPath: string): string {
-  const quoted = `'${scriptPath.replaceAll("'", "'\\''")}'`
+  const quoted = posixSingleQuote(scriptPath)
   return `/bin/sh ${quoted}`
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f36fe6ac-4a3e-40d6-bb65-c1c7592b09ba

📥 Commits

Reviewing files that changed from the base of the PR and between 26934b1 and 71725cb.

📒 Files selected for processing (5)
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/codex/hook-service.test.ts
  • src/main/codex/hook-service.ts

Current Codex launches hooks via $SHELL -lc with the full command as one
arg, so if/then/fi would work — but stablyai#8110's 127 also matches pure
whitespace argv-exec (argv0=`if`) and quoted `/bin/sh 'path'` fails that
model because quotes stay in the path token. Emit unquoted
`/bin/sh <path>` when the path is argv-safe; fall back to single-quoted
paths for spaces/metacharacters. Keep legacy trust variants for remove.

Co-Authored-By: Claude <noreply@anthropic.com>
…0-current

# Conflicts:
#	src/main/codex/hook-service-wsl-runtime.test.ts
#	src/main/codex/hook-service.ts
@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review current head bef0a65 after the CI-discovered test contract fix.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@bbingz Got it — I'll review the latest head commit bef0a65, including the CI-discovered test contract fix.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz bbingz changed the title fix(codex): use argv-safe POSIX hook commands test(codex): validate guarded POSIX hook launchers Jul 13, 2026
@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing as unsupported after exact-head audit. The direct launcher reintroduced the same exit-127/Broken-pipe class when the managed script is missing and could not support quoted home paths under the claimed naive splitter. Head 305bf6b restores the safe guarded behavior before closure. Issue #8110 remains open pending an exact reporter runtime and child-argv trace.

@bbingz bbingz closed this Jul 13, 2026

@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 (3)
src/main/codex/hook-service.ts (1)

142-154: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract shared POSIX quoting in hook-service.ts

The '${scriptPath.replaceAll("'", "'\\''")}' quoting is duplicated across wrapReadablePosixHookCommand, getLegacyDirectPosixHookCommand, and codexPosixTrustCommandVariants. Pull it into a local helper so the guarded/readable/legacy command variants stay in sync.

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

83-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Solid execution-regression coverage; helper is correct.

runInstalledHook correctly spawns /bin/sh with array args, captures stdin errors instead of throwing, and times out defensively. The "spaces and quotes" loop test (259-289) relies on installManagedHooksIntoWslRuntime writing the actual script at plan.scriptPath during install (confirmed by the sibling test's rmSync(plan.scriptPath, ...) at line 306), so both /bin/sh -c and -lc executions genuinely exercise the real script, not just the drain fallback.

One nit: this "spaces and quotes" execution loop is nearly identical to the one added in src/main/agent-hooks/installer-utils.test.ts (Lines 320-337) — same home-name fixtures ('Jorge Silva', "O'Brien"), same shell-flag loop, same assertion shape. Consider extracting a shared test helper (e.g., a small fixture module exporting the home-name list and a runUnderShell wrapper) to keep both suites in sync as quoting rules evolve.

Also applies to: 259-313

src/main/agent-hooks/installer-utils.test.ts (1)

14-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good regression coverage for quoted/spaced POSIX paths; minor cross-file duplication.

The new loop correctly writes, chmods, and executes the script via spawnSync('/bin/sh', [shellFlag, wrapPosixHookCommand(scriptPath)]), validating both -c and -lc invocation styles against tricky path characters — good defense against the quoting regression this PR fixes.

As noted in the companion file, this test is structurally identical to the new "spaces and quotes" loop added in src/main/codex/hook-service-wsl-runtime.test.ts (Lines 259-289): same homeName fixtures and shell-flag loop, just exercising wrapPosixHookCommand directly instead of through the WSL installer. Worth consolidating into a shared helper/fixture to avoid future drift between the two.

Also applies to: 320-337


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e9a7eaf7-f1fd-4922-9671-03c9d5246654

📥 Commits

Reviewing files that changed from the base of the PR and between b35fa6f and 305bf6b.

📒 Files selected for processing (5)
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/remote-hook-service-installers.test.ts
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/codex/hook-service.test.ts
  • src/main/codex/hook-service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex/hook-service.test.ts

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.

2 participants