A Crashed Codex Hook Lets the Tool Run Unless You Opted In: What onFailure Actually Defaults To
A Crashed Codex Hook Lets the Tool Run Unless You Opted In: What onFailure Actually Defaults To
The idea in our backlog framed Codex v0.173.0’s onFailure = "block" as a “fail-closed by default” shift. The code says the opposite. A hook that crashes, times out or prints broken JSON still lets the tool run unless that handler sets onFailure to block. This article reads the hook engine to list exactly which failures block, which do not, and how to check your own setup.
A note on sourcing. The code is the openai/codex main branch at commit 936ac6d (1 December 2026).1 The release notes for rust-v0.173.0 and pull request #62831 supply the intent.23 I did not run Codex or any hook for this article, so what follows describes what the code and its tests assert. The official hooks page at developers.openai.com was not reachable from the research environment, so no documentation claim below rests on it.
What v0.173.0 Added
The release notes say: “Supported synchronous command and MCP tool hooks can set onFailure to block. A failed PreToolUse check then prevents the tool from running.”2 The pull request, merged 20 November 2026, says the same with the default stated outright: “The default continue preserves existing behavior. On supported synchronous hooks, block applies the event’s blocking behavior and reports the reason while preserving failure diagnostics.”3 It also notes that a failed PostToolUse check withholds the result of a tool that has already run.
The configuration schema agrees. HookFailurePolicy has two values, continue and block, and the field’s description reads “Defaults to continue; block applies the event’s blocking behavior on failure.”4 So the feature is opt-in, handler by handler. Nothing in the release changes what an existing hook does when it breaks.
What Counts as a Failure
The engine gives each hook run a status: completed, failed or blocked. A run becomes failed in several ways. In PreToolUse handling, the code marks it failed when:5
- the hook process errors before it produces a status (for example it cannot start);
- it exits with a code other than 0 or 2 (“hook exited with code N”);
- it exits with code 2 but writes nothing to stderr, so there is no reason to show;
- it prints something that looks like JSON but is not valid
PreToolUseoutput; - it returns a structured output that is flagged invalid.
The test file for the policy adds exit 1, exit 2, malformed JSON and a 10-second sleep against a 1-second timeout, and checks all of them.6 For MCP tool hooks it also covers an error result, a server disconnect and a request timeout.6
Then a single function decides what to do. apply_failure_policy returns nothing unless the status is failed; if so, it asks the handler for a block reason. If the handler’s policy is block, the status changes to blocked, the reason is recorded as feedback, and the tool call is stopped.7 If the policy is continue, the status stays failed, the error is recorded in the hook’s output entries, and the tool runs.
The test mcp_failures_block_only_when_opted_in states the result as an assertion. For each event it loops over no policy, continue and block, and expects a block only when the run failed and the policy is block.6
Which Failures Block Without Any Setting
One case blocks regardless of onFailure. A synchronous PreToolUse hook that exits with code 2 and writes a reason to stderr is a deliberate block: the status becomes blocked and the reason is passed back.5 The same holds for a valid JSON output that carries a block decision. These are the hook doing its job, not failing.
That distinction matters. A guard script that reports “no” by exiting 2 with a message is safe by default. A guard script that dies with exit 1 because a dependency is missing, a path is wrong or its interpreter crashed is not.
Three Quiet Ways a Guard Does Nothing
- A crash or non-zero exit that is not 2. The run is marked failed. The tool proceeds. The failure shows as an error entry on the hook run, which is only useful if someone reads it.
- A timeout. The test runs a hook that sleeps longer than its timeout and expects the run to be failed, and blocked only under
block.6 - An output Codex cannot use. One unit test is named
permission_decision_allow_without_updated_input_fails_open. A hook that returnspermissionDecision: "allow"without anupdatedInputis recorded as failed with the text “PreToolUse hook returned unsupported permissionDecision:allow”, and the tool call is not blocked.8 The same test shows an async handler given the same output completing normally, with the context kept.
None of these is a bug in the sense of misbehaving code. They are the documented default of the policy. The risk is a reader’s assumption that “the hook is configured” means “the check is enforced”.
What Setting It Changes
With onFailure: "block" on a sync handler, the run is converted to blocked and the block reason is a fixed string: “PreToolUse hook failed. This hook is configured to block continuation on failure.”9 The reason names the event type, so a failed PostToolUse check reads differently.
Three details from the tests are worth keeping:
- A successful hook cannot rescue a failed one. The test
failure_block_cannot_be_overridden_by_a_successful_hookpairs a failing command handler (onFailure: "block") with an MCP hook that returns an allow decision, and asserts the result is blocked.6 One passing check does not outvote a failed required check. - The failure remains visible. The blocked entry is added as feedback alongside the original error, so the diagnosis is preserved rather than replaced.7
- Blocking needs a synchronous handler. The code that applies the policy requires the handler to be able to apply control effects, which only sync handlers can, and excludes
SessionEnd.9 For managed hooks, the testmanaged_hooks_reject_failure_blocking_that_cannot_be_enforcedasserts thatonFailure: "block"on an async handler, onSessionEnd, or on the model-request events is not loaded; the handler list is empty and a load error says “onFailure:block requires a synchronous” hook.6 This covers the managed path the test builds; I did not check whether unmanaged hook files get the same rejection or silently ignore the setting.
The pull request also exposes the policy in the app-server’s configRequirements/read response, so a managed deployment can inspect it.3
A Checklist for Your Own Guards
- For every
PreToolUseorPermissionRequesthook that is meant to enforce something, setonFailure = "block"on that handler. Leaving it unset meanscontinue. - Make sure the handler is synchronous (not
async: true). - Use exit code 2 plus a stderr reason for a deliberate refusal. Do not rely on exit 1 to refuse.
- Break the guard on purpose in a scratch repository (rename its interpreter, make it exit 1, add
sleeppast the timeout) and confirm the tool is stopped and the block reason appears. The tests above show what to expect; only a run of your own configuration shows what you have. - Read the hook run output after a session. Under
continuea failed guard leaves only an error entry behind.
What This Article Does Not Establish
- It does not establish behaviour in a running Codex. No hook was executed; the claims rest on code and its tests at one commit.
- It does not cover the other tools in the backlog’s “silent success” list (Claude Code plugins, Gemini CLI goals, Copilot instructions files). Those were not examined.
- It does not show how a stable release ships this code. The release notes confirm
onFailurein v0.173.0; I did not diff the tag against the commit read. - It does not say whether any specific user configuration is affected, or whether OpenAI intends to change the default later.
-
openai/codexat commit936ac6d(“Add critical-path snapshots for turn milestones”, #64935), head ofmainon 1 December 2026. Source paths below are undercodex-rs/hooks/src/at that commit. ↩ -
Release notes for
rust-v0.173.0, “New Features”. ↩ ↩2 -
openai/codex#62831, “Let required hooks block continuation on failure”, merged 20 November 2026. ↩ ↩2 ↩3
-
codex-rs/core/config.schema.json, definitionsHookFailurePolicyandHookHandlerConfig(onFailure, for command and MCP tool handlers). ↩ -
events/pre_tool_use.rs, the result handling inparse_completed(exit codes 0, 2 and others, invalid JSON, missing stderr reason). ↩ ↩2 -
engine/failure_policy_tests.rs:mcp_failures_block_only_when_opted_in,command_start_failure_obeys_policy,command_exit_timeout_and_invalid_output_obey_policy,failure_block_cannot_be_overridden_by_a_successful_hook,managed_hooks_reject_failure_blocking_that_cannot_be_enforced. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 -
events/common.rs,apply_failure_policyandfailure_block_reason. ↩ ↩2 -
events/pre_tool_use.rs, unit testpermission_decision_allow_without_updated_input_fails_open. ↩ -
engine/mod.rs,ConfiguredHandler::failure_block_reasonandcan_apply_control_effects. ↩ ↩2