Skip to content

fix(codex): preserve Windows hook exit codes - #1096

Open
daniel-bavrin wants to merge 1 commit into
cdeust:mainfrom
daniel-bavrin:fix/codex-windows-hook-exit
Open

daniel-bavrin wants to merge 1 commit into
cdeust:mainfrom
daniel-bavrin:fix/codex-windows-hook-exit

Conversation

@daniel-bavrin

Copy link
Copy Markdown

Summary

The Windows Codex hook launcher passed a multiword Python -c program through os.execv. On native CPython 3.12 the child received only from and printed a SyntaxError, while the launcher returned 0. That status could also lead the SessionEnd worker to mark the event as complete.

The Windows hook path now waits for the isolated interpreter and returns its status with standard streams inherited. The two blocking PreToolUse hooks use commandWindows to pass the exit status through PowerShell. This allows Codex to recognize exit 2 and stop the tool call. See OpenAI Codex #54072 for the host shell behavior.

Related to #730 (native host lifecycle verification).

Type of change

  • Bug fix

Test plan

Verified on a clean checkout of d48e08d7 on Windows with Python 3.12.13 and the locked development dependencies.

  • python -m pytest --tb=short -q -rs -p no:randomly for the Codex runtime, plugin contracts, SessionEnd queue, and Windows job tests — 63 passed, 0 failed, 1 skipped (POSIX signal/FIFO probe).
  • npm ci --prefix .github/mcpb --ignore-scripts followed by node --test .github/mcpb/test-forge-security.cjs — 2 passed, 0 failed, 0 skipped.
  • CORTEX_MEMORY_STORE_BACKEND=sqlite CORTEX_RERANKER_OFFLINE=1 python -m pytest --tb=short -q -rs -p no:randomly tests_py/integration — 30 passed, 0 failed, 4 skipped (require the PostgreSQL extra).
  • scripts/ci_unit.sh attempted on the same commit. Its PostgreSQL setup stopped before collection because Windows CPython has no fcntl.
  • Ruff 0.17.4 format and lint, the craftsmanship check, and the pre-commit gitleaks scan passed.
  • Before the fix, the blocking launcher test saw exit 0 with a SyntaxError, and the manifest test failed because the Windows overrides were absent.
  • Manual Windows verification with Cortex 4.24.0 and Codex Desktop ran each gate through the installed App Server. Both apply_patch calls produced a native blocked hook event, returned the matching gate diagnostic, and left the target files absent. A separate SessionEnd check produced both the saved session row and the completion receipt.

Risk and rollback

The two Windows overrides use PowerShell syntax. The launcher waits for the hook interpreter, so the host and the SessionEnd worker can observe its real exit code. Revert this commit with git revert d48e08d7.

Audit notes

Checked the process handoff, inherited stdin, exit codes 0 and 2, gate registration scope, and durable SessionEnd completion. The automated tests exercise the real wheel entry point and separately pin both host command overrides. The native App Server test covers the shell-to-Codex handoff.

Coding-standards compliance

  • Existing layer and package boundaries are preserved.
  • The new tests cover an allowed call and a rejected call, plus both manifest entries.
  • Ruff, craftsmanship, and secret scanning passed.

Breaking changes

Codex may request renewed trust for the updated plugin hooks. After review, rejected Windows tool calls and lifecycle failures are reported with the original hook exit status.

Screenshots / logs

The native trace reported preToolUse: blocked separately for decision_gate and no_deps_gate. Both returned Command blocked by PreToolUse hook.

Reviewer checklist

  • Changelog and Codex plugin documentation updated.
  • Pre-commit secret scan passed.
  • Hosted CI on the PR head.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T19:58:00.795534Z a1c191d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@daniel-bavrin
daniel-bavrin force-pushed the fix/codex-windows-hook-exit branch from d48e08d to 81a7ba2 Compare November 19, 2026 08:36
Run Windows hook interpreters with subprocess so the inline launcher code and child status survive. Forward decision and dependency gate statuses through PowerShell and cover both handoffs with regressions.
@daniel-bavrin
daniel-bavrin force-pushed the fix/codex-windows-hook-exit branch from 81a7ba2 to a1c191d Compare November 20, 2026 19:54

This branch has not been deployed

No deployments
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.

1 participant