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:
Ryan Taylor
2026-11-20 20:24:34 +00:00
committed by copyberry
parent 0a0b1021f0
commit a1afa12273
49 changed files with 1377 additions and 52 deletions
@@ -1032,6 +1032,11 @@ class ConfigReadParams(BaseModel):
include_layers: Annotated[bool | None, Field(alias="includeLayers")] = None
class ConfiguredHookFailurePolicy(Enum):
continue_ = "continue"
block = "block"
class CommandConfiguredHookHandler(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -1047,6 +1052,7 @@ class CommandConfiguredHookHandler(BaseModel):
async_: Annotated[bool, Field(alias="async")]
command: str
command_windows: Annotated[str | None, Field(alias="commandWindows")] = None
on_failure: Annotated[ConfiguredHookFailurePolicy | None, Field(alias="onFailure")] = None
status_message: Annotated[str | None, Field(alias="statusMessage")] = None
timeout_sec: Annotated[int | None, Field(alias="timeoutSec", ge=0)] = None
type: Annotated[Literal["command"], Field(title="CommandConfiguredHookHandlerType")]
@@ -1057,6 +1063,7 @@ class McpToolConfiguredHookHandler(BaseModel):
populate_by_name=True,
)
input: dict[str, Any]
on_failure: Annotated[ConfiguredHookFailurePolicy | None, Field(alias="onFailure")] = None
server: str
status_message: Annotated[str | None, Field(alias="statusMessage")] = None
timeout_sec: Annotated[int | None, Field(alias="timeoutSec", ge=0)] = None