fix(tools): fail closed on non-bool approval results - #4849
fix(tools): fail closed on non-bool approval results#4849sylvesterkaczmarek wants to merge 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
fscfede-beep
left a comment
There was a problem hiding this comment.
There is one remaining fail-open path outside this diff. On current main, src/agents/mcp/server.py::_get_needs_approval_for_tool() wraps callable MCP approval policies separately and still ends with return bool(result). Because this PR only changes evaluate_needs_approval_setting(), an MCP callable that returns None (or another falsy non-bool) is still coerced to False there and can skip approval.
Could this wrapper be routed through evaluate_needs_approval_setting(policy, run_context, agent, tool) as well? A focused regression would be an MCP tool with sync/async approval policies returning None, asserting an approval interruption and zero MCP tool calls. That would make the fail-closed rule consistent across ordinary function tools and MCP tools.
Summary
Fixes #4845.
Callable
needs_approvalpolicies are declared to returnbool, but the approval helper currently coerces any result withbool(). A predicate that accidentally returnsNoneor another falsy non-bool value therefore becomesFalseand can let a guarded tool run without approval.This change preserves explicit
TrueandFalseresults and treats any non-bool callable result as requiring approval. Truthy non-bool results keep their existing effective behaviour, while falsy non-bool results now fail closed.Tests
Adds regression coverage for synchronous and asynchronous non-bool results and verifies explicit boolean results are unchanged.