fix(agent): set safe=False on unblocked tool calls in chat() and chat_stream() - #4
Open
Adityakk9031 wants to merge 1 commit into
Open
fix(agent): set safe=False on unblocked tool calls in chat() and chat_stream()#4Adityakk9031 wants to merge 1 commit into
Adityakk9031 wants to merge 1 commit into
Conversation
…_stream() - In both chat() and _process_response_stream(), the safe flag was initialised to True and never set to False, even when an attacker successfully bypassed the guardrail (unblocked tool call). - Added safe = False in the else branch (unblocked path) at both sites. - Added engine/tests/test_safe_flag.py with 8 tests covering the blocked and unblocked cases for both the sync and streaming paths. Fixes fabraix#3
Author
|
@zachdotai have a look |
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
Fixes a logic flaw where the
safeflag was alwaysTrueregardless of whether an attacker successfully bypassed the guardrail. When a tool call was unblocked (the guardrail allowed it through),safewas never set toFalse, causing every response to be reported as safe.Closes #3
Root Cause
In both
chat()and_process_response_stream()inengine/agent.py, theelsebranch handling an unblocked tool call updatedreasonbut never updatedsafe:As a result, every final response and SSE
completeevent reported:{ "safe": true }even when the guardrail had been bypassed and the protected tool executed successfully.
Fix
Updated both affected code paths (
chat()and_process_response_stream()) to explicitly mark unblocked tool executions as unsafe:Files Changed
engine/agent.pysafe = Falsein the unblocked branch of bothchat()and_process_response_stream()engine/tests/test_safe_flag.pyImpact Before This Fix
completeevent andPlaygroundChatResponsereturned"safe": trueunconditionally.safe=Falsenever triggered.Tests
Added
engine/tests/test_safe_flag.pycovering both synchronous and streaming execution paths.Checklist
chat()and_process_response_stream())safe=Falseis returned for unblocked tool calls and reflected correctly in the UI