mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
Let required hooks block continuation on failure (#62831)
## Why A required hook check can fail to run or return a usable result. Continuing after that failure can let an action proceed without a completed check. ## What changed Add per-handler `onFailure` for command and MCP tool hooks. 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. For example, a failed `PreToolUse` check prevents the tool from running, while a failed `PostToolUse` check withholds the result of a tool that already ran. Expose the policy in the app-server's `configRequirements/read` response. ## Testing Add tests for command and MCP failures under both policies, and scenario coverage for blocked tool execution, withheld results, and completion after a `Stop` hook recovers. GitOrigin-RevId: 20d6ebda0094382fe052bbf34338edb994cc7bd3
This commit is contained in:
@@ -159,6 +159,10 @@ pub enum HookHandlerConfig {
|
||||
r#async: bool,
|
||||
#[serde(default, rename = "statusMessage")]
|
||||
status_message: Option<String>,
|
||||
/// Failure policy for synchronous hooks that support blocking.
|
||||
/// Defaults to continue; block applies the event's blocking behavior on failure.
|
||||
#[serde(default, rename = "onFailure", skip_serializing_if = "Option::is_none")]
|
||||
on_failure: Option<HookFailurePolicy>,
|
||||
/// Approximate token threshold for spilling this hook's `additionalContext` to disk.
|
||||
/// Unset uses 2,500 tokens; `0` disables spilling for this hook. The threshold is
|
||||
/// evaluated against the original context; a spilled preview also includes recovery
|
||||
@@ -180,6 +184,10 @@ pub enum HookHandlerConfig {
|
||||
timeout_sec: Option<u64>,
|
||||
#[serde(default, rename = "statusMessage")]
|
||||
status_message: Option<String>,
|
||||
/// Failure policy for MCP hooks that support blocking.
|
||||
/// Defaults to continue; block applies the event's blocking behavior on failure.
|
||||
#[serde(default, rename = "onFailure", skip_serializing_if = "Option::is_none")]
|
||||
on_failure: Option<HookFailurePolicy>,
|
||||
},
|
||||
#[serde(rename = "prompt")]
|
||||
Prompt {},
|
||||
@@ -187,6 +195,14 @@ pub enum HookHandlerConfig {
|
||||
Agent {},
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum HookFailurePolicy {
|
||||
#[default]
|
||||
Continue,
|
||||
Block,
|
||||
}
|
||||
|
||||
// Reject values such as null that cannot be represented in TOML for trust hashing.
|
||||
fn deserialize_mcp_tool_input<'de, D>(
|
||||
deserializer: D,
|
||||
|
||||
Reference in New Issue
Block a user