fix(approvals): fail closed when a callable needs_approval returns a non-bool - #4846
Open
ayaangazali wants to merge 1 commit into
Open
fix(approvals): fail closed when a callable needs_approval returns a non-bool#4846ayaangazali wants to merge 1 commit into
ayaangazali wants to merge 1 commit into
Conversation
…non-bool evaluate_needs_approval_setting coerced the predicate's answer with bool(), so a callable that fell through a branch and returned None was read as False and the guarded tool ran with no approval requested. The declared contract is Callable[..., MaybeAwaitable[bool]], so a non-bool answer means the predicate did not answer the approval question at all. Treat that the same way openai#3867 treats arguments the predicate cannot inspect, by requiring approval rather than skipping it. Genuine True and False answers are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
evaluate_needs_approval_settingcoerces the predicate's answer withbool():A callable that falls through a branch returns
None,bool(None)isFalse, and the guarded tool runs with no approval requested. The declared contract isCallable[..., MaybeAwaitable[bool]], so a non-bool answer does not mean "no approval needed", it means the predicate did not answer the question.Measured on
mainat89c02c82, asking the only question that matters, whether the guarded tool actually ran without approval:After the change the two controls are unchanged and every non-bool answer requires approval instead.
This is the same shape as #3867, "fail closed on invalid callable approval arguments", where an approval question that cannot be answered results in
return Truerather than a permissive default. That fix handled the case where the predicate cannot be given valid arguments; this one handles the case where it is given valid arguments and still does not answer.Behaviour change worth stating plainly: a predicate that returns a falsy non-bool such as
0or""and today means "do not ask" will now ask. That is deliberate, it is out of contract either way, and the safe direction for a security gate is to ask.Test plan
tests/test_hitl_error_scenarios.py, next to the #3867 tests and following their shape.test_callable_function_approval_fails_closed_for_non_bool_verdict, parametrized overNone,"",0,[]and{}. Each asserts the run was interrupted for approval and that the tool'son_invoke_toolnever recorded an invocation, so it asserts the outcome rather than an intermediate value.test_callable_function_approval_honors_real_bool_verdicts, parametrized overTrueandFalse, pinning that genuine answers keep their meaning:Trueinterrupts and does not run,Falseruns.Verified the first fails without the source change by reverting
src/: all five parametrizations fail. The two bool controls pass either way, which is the expected split for a test that also pins existing behaviour..agents/skills/code-change-verification/scripts/run.shpasses end to end: format, lint, typecheck and the full suite.Issue number
Fixes #4845
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR@mahirhir wrote #4845 with the mechanism and the fail-closed argument already worked out, including the controls, so the analysis is his and I only implemented and re-measured it. Happy to step aside if he would rather carry it. The judgement I would most like checked is treating every non-bool the same way rather than special casing
None: it matches the declared return type and avoids a second rule, but it does change behaviour for anyone returning0today. I'm a freshman in college, so if you would rather this raised aUserErrorlike the invalid-setting branch just above it, say so and I will switch it.