Skip to content

feat(guardrails): configurable check timeout, default 60 s - #29

Open
vrajp-lyzr wants to merge 1 commit into
mainfrom
fix/guardrails-timeout-60s
Open

vrajp-lyzr wants to merge 1 commit into
mainfrom
fix/guardrails-timeout-60s

Conversation

@vrajp-lyzr

Copy link
Copy Markdown
Contributor

A policy with slow checks (e.g. a banned-topics list: ~3.4 s per tool call, over 5 s per message) hit the fixed 5 s guardrails timeout. The check then failed closed with guardrails unreachable: ReadTimeout, which denied the tool or blocked the message.

Setting: ComputerAgent(guardrails_timeout_s=…) > COMPUTER_AGENT_GUARDRAILS_TIMEOUT_S > 60 s (was 5 s). Anything but a positive number is a SettingsError. It bounds the input check (SrsTurnGuard) and every tool-call check (SrsToolGate).

Claude hook budget: on claude-agent-sdk the tool check runs inside a PreToolUse hook, and the CLI's default hook budget is 60 s. With a 60 s check the CLI could give up first, and its outcome is not the SDK's deny. The hook budget is now the check timeout + 30 s, carried by a new optional EngineContext.policy_timeout_s.

Tests:

  • settings: the default, the env var, the argument winning, bad values refused;
  • the hook budget following the configured timeout;
  • the existing ENV_VARS and missing-settings tests updated for the new optional setting.

Full suite: 695 passed, 1 skipped. ruff clean. mypy: the error set is identical to main's.

Smoke: a real ComputerAgent against a guardrails server answering in 2 s. With the env var at 1 s the message is blocked after 1.0 s. With the argument at 3 s it is allowed after 2.0 s, and the argument wins over the env var.

Note: the UAT agent gateway's own SRS_TIMEOUT is 10 s, so a check slower than that still ends at the gateway, whatever the SDK allows.

ComputerAgent(guardrails_timeout_s=...), else COMPUTER_AGENT_GUARDRAILS_TIMEOUT_S,
else 60 s (was a fixed 5 s). It bounds the input check and every tool-call
check. A policy with slow checks (several seconds per call) failed closed with
'guardrails unreachable: ReadTimeout'.

On claude-agent-sdk the policy PreToolUse hook's CLI budget is the timeout
plus 30 s (the CLI default is 60 s), carried by EngineContext.policy_timeout_s,
so the check's own timeout still decides.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant