Skip to content

Commit a1afa12

Browse files
rtaylor-oaicopyberry
authored andcommitted
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
1 parent 0a0b102 commit a1afa12

49 files changed

Lines changed: 1377 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎codex-rs/app-server-protocol/schema/json/v2/ConfigRequirementsReadResponse.json‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.

‎codex-rs/app-server-protocol/schema/typescript/v2/ConfiguredHookFailurePolicy.ts‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎codex-rs/app-server-protocol/schema/typescript/v2/ConfiguredHookHandler.ts‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎codex-rs/app-server-protocol/schema/typescript/v2/index.ts‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎codex-rs/app-server-protocol/src/protocol/v2/config.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ pub struct ConfiguredHookMatcherGroup {
738738
pub hooks: Vec<ConfiguredHookHandler>,
739739
}
740740

741+
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
742+
#[serde(rename_all = "camelCase")]
743+
#[ts(rename_all = "camelCase", export_to = "v2/")]
744+
pub enum ConfiguredHookFailurePolicy {
745+
Continue,
746+
Block,
747+
}
748+
741749
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
742750
#[serde(tag = "type")]
743751
#[ts(tag = "type", export_to = "v2/")]
@@ -756,6 +764,9 @@ pub enum ConfiguredHookHandler {
756764
#[serde(rename = "statusMessage")]
757765
#[ts(rename = "statusMessage")]
758766
status_message: Option<String>,
767+
#[serde(rename = "onFailure")]
768+
#[ts(rename = "onFailure")]
769+
on_failure: Option<ConfiguredHookFailurePolicy>,
759770
/// Approximate token threshold for spilling this hook's `additionalContext` to disk.
760771
/// `null` uses 2,500 tokens; `0` disables spilling for this hook. The threshold is
761772
/// evaluated against the original context; a spilled preview also includes recovery
@@ -776,6 +787,9 @@ pub enum ConfiguredHookHandler {
776787
#[serde(rename = "statusMessage")]
777788
#[ts(rename = "statusMessage")]
778789
status_message: Option<String>,
790+
#[serde(rename = "onFailure")]
791+
#[ts(rename = "onFailure")]
792+
on_failure: Option<ConfiguredHookFailurePolicy>,
779793
},
780794
#[serde(rename = "prompt")]
781795
#[ts(rename = "prompt")]

‎codex-rs/app-server/src/request_processors/config_processor.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use codex_app_server_protocol::ConfigRequirementsReadResponse;
2929
use codex_app_server_protocol::ConfigValueWriteParams;
3030
use codex_app_server_protocol::ConfigWriteErrorCode;
3131
use codex_app_server_protocol::ConfigWriteResponse;
32+
use codex_app_server_protocol::ConfiguredHookFailurePolicy;
3233
use codex_app_server_protocol::ConfiguredHookHandler;
3334
use codex_app_server_protocol::ConfiguredHookMatcherGroup;
3435
use codex_app_server_protocol::ExperimentalFeatureEnablementSetParams;
@@ -865,13 +866,15 @@ fn map_hook_handler_to_api(handler: CoreHookHandlerConfig) -> ConfiguredHookHand
865866
timeout_sec,
866867
r#async,
867868
status_message,
869+
on_failure,
868870
additional_context_limit,
869871
} => ConfiguredHookHandler::Command {
870872
command,
871873
command_windows,
872874
timeout_sec,
873875
r#async,
874876
status_message,
877+
on_failure: on_failure.map(map_hook_failure_policy_to_api),
875878
additional_context_limit,
876879
},
877880
CoreHookHandlerConfig::McpTool {
@@ -880,18 +883,29 @@ fn map_hook_handler_to_api(handler: CoreHookHandlerConfig) -> ConfiguredHookHand
880883
input,
881884
timeout_sec,
882885
status_message,
886+
on_failure,
883887
} => ConfiguredHookHandler::McpTool {
884888
server,
885889
tool,
886890
input,
887891
timeout_sec,
888892
status_message,
893+
on_failure: on_failure.map(map_hook_failure_policy_to_api),
889894
},
890895
CoreHookHandlerConfig::Prompt {} => ConfiguredHookHandler::Prompt {},
891896
CoreHookHandlerConfig::Agent {} => ConfiguredHookHandler::Agent {},
892897
}
893898
}
894899

900+
fn map_hook_failure_policy_to_api(
901+
policy: codex_config::HookFailurePolicy,
902+
) -> ConfiguredHookFailurePolicy {
903+
match policy {
904+
codex_config::HookFailurePolicy::Continue => ConfiguredHookFailurePolicy::Continue,
905+
codex_config::HookFailurePolicy::Block => ConfiguredHookFailurePolicy::Block,
906+
}
907+
}
908+
895909
fn map_sandbox_mode_requirement_to_api(mode: CoreSandboxModeRequirement) -> Option<SandboxMode> {
896910
match mode {
897911
CoreSandboxModeRequirement::ReadOnly => Some(SandboxMode::ReadOnly),

0 commit comments

Comments
 (0)