Skip to content

Allow UserPromptSubmit hooks to fail closed before model requests #33630

Open

Description

@AleZworks

What variant of Codex are you using?

Codex Desktop/App, app-server, and CLI. The motivating reproduction was on Windows with Codex 0.144.5; the proposed behavior was also implemented and validated against current main.

What feature would you like to see?

Add an opt-in fail-closed policy for UserPromptSubmit command hooks so a detector or policy hook can prevent prompt transmission when the hook itself fails.

Today, a UserPromptSubmit hook can reject a prompt through a valid blocking result, but Codex continues submission when the hook process crashes, times out, cannot be executed, or emits malformed output. That makes the hook unsuitable for local secret-paste prevention or similar pre-transmission policy checks: detector failure must not silently become permission to send the prompt.

A narrow configuration shape would be:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "",
        "failureMode": "block",
        "hooks": [
          {
            "type": "command",
            "command": "path/to/local-detector"
          }
        ]
      }
    ]
  }
}

Proposed semantics:

  • failureMode accepts continue or block.
  • Omitted or continue preserves the existing fail-open behavior.
  • block applies only to UserPromptSubmit; other events warn and remain fail-open.
  • Nonzero exit, timeout, missing executable, malformed output, and event-serialization failure produce a redacted blocking diagnostic and no model request.
  • The policy participates in hook trust hashing so changing it requires re-trust.
  • Desktop/app-server config reads expose the effective value so UI and runtime state remain consistent.

This is the concrete blocking-policy part of the broader cross-surface hook goals tracked in #21753.

Additional information

I prepared a validated candidate implementation because external code contributions are invitation-only:

The candidate:

  • implements the opt-in policy in config and the hook engine;
  • carries it through configRequirements/read for Desktop/app-server consumers;
  • regenerates config, JSON Schema, and TypeScript artifacts;
  • adds unit and RPC coverage;
  • adds a Linux core integration test that asserts a failed fail-closed UserPromptSubmit hook results in zero model requests.

Local validation completed:

  • just write-config-schema
  • just write-app-server-schema
  • just test -p codex-app-server-protocol (262 passed)
  • just test -p codex-config (205 passed)
  • just test -p codex-hooks -E 'test(user_prompt_submit)' (8 passed)
  • just test -p codex-hooks -E 'test(failure_mode_changes_hook_trust_hash)' (1 passed)
  • just test -p codex-app-server -E 'test(config_requirements_read_includes_hook_failure_mode)' (1 passed)
  • targeted just fix across affected crates
  • cargo fmt --all

The core hooks integration suite is cfg-disabled on Windows and is intended to run in Linux CI.

Activity

  1. added
    enhancementNew feature or request
    appIssues related to the Codex desktop app
    CLIIssues related to the Codex CLI
    hooksIssues related to event hooks
    app-serverIssues involving app server protocol or interfaces
    windows-osIssues related to Codex on Windows systems
    configIssues involving config.toml, config keys, config merging, or config updates
    on Jul 16, 2026
  2. SirRadek commented on Sep 22, 2026

    @SirRadek

    Additional Linux evidence for this request, from a disposable synthetic app-server fixture:

    • Desktop native binary 0.154.0-alpha.6.2 on Linux x86_64.
    • Two synchronous, system-managed command hooks (SessionStart and UserPromptSubmit), with hooks forced on through managed requirements.
    • Isolated filesystem and network namespace, synthetic configuration/identity, empty MCP set, and a loopback-only no-auth HTTP sink returning a fixed 400. No real account credentials, prompts, provider inference, or project data were used.

    Observed results:

    Prompt hook outcome Local model-endpoint requests
    Explicit block 0
    Successful continue 1
    Process exits 1 1

    In the exit-1 case, the host emitted one failed UserPromptSubmit completion, the local sink received one request, and a terminal event was observed. SessionStart completed normally. We changed only the generated disposable prompt-hook copy; original hook bytes and native/configuration/identity integrity checks remained unchanged.

    The block and continue controls also passed on CLI 0.154.0. The exit-1 fault case was tested on the Desktop binary only; this is not a claim that every failure class or client was covered.

    Our sequence was initialize → requirements/config read → empty MCP check → hook inventory → thread/start → thread-scoped MCP check → turn/start. Both hook lifecycles and their initiating thread/turn binding were checked. The controls distinguish hook blocking from an unreachable endpoint.

    This supports an opt-in native failure policy, rather than changing the compatibility default for advisory hooks. For administrator-mandated bootstrap/admission checks, the policy needs to remain enforceable against lower-priority overrides and expose its effective value to Desktop/app-server clients. A wrapper can translate some inner errors into an explicit block, but cannot supply the same guarantee when the wrapper itself is missing, crashes, or times out.

    Has a supported implementation of this policy landed, and if so, which Desktop/CLI versions support it? Otherwise, this remains a deployment blocker for a mandatory pre-transmission gate. Related tool-dispatch coverage is tracked in #41979.

    These are summarized observations, not a standalone portable reproduction bundle or a claim of a broader host sandbox vulnerability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIappIssues related to the Codex desktop appapp-serverIssues involving app server protocol or interfacesconfigIssues involving config.toml, config keys, config merging, or config updatesenhancementNew feature or requesthooksIssues related to event hookswindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions