Repository navigation
fix(agent): refuse tool calls outside the dispatched toolChoice - #171
Open
alexb-openrouter wants to merge 1 commit into
Open
alexb-openrouter wants to merge 1 commit into
alexb-openrouter wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
alexb-openrouter
marked this pull request as ready for review
November 30, 2026 16:03
This was referenced Nov 30, 2026
This branch has not been deployed
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
toolChoice(including a set narrowed throughnextTurnParams) is only sent to the server as a request. If the server or model ignores it and returns a call to a withheld tool, the engine ran that tool anyway. This PR makes the engine check each returned call against thetoolChoiceit actually dispatched for that turn.beginToolChoiceDispatchnow records the wiretoolChoiceindispatchedToolChoice. This covers caller config, forced-choice relaxation,nextTurnParams, and doom-loop advisor overrides.functionToolsPermittedByToolChoicemaps it to the function tools that are allowed:undefined/'auto'/'required'→ no restriction'none'→ none{ type: 'function', name }→{name}allowed_tools→ itsfunctionentrieshandleApprovalCheckcalls the newdenyCallsOutsideToolChoicebefore approval classification. Each out-of-set call:hookDeniedCalls, soexecuteSingleToolCallreturns the same{ error }output aPermissionRequestdeny producesrequireApproval,PermissionRequest, PreToolUse, doom-loop declaration, orexecuteunsentToolResultsas a rejected result when a permitted sibling pauses the run for approvalexecute/onToolCalled) are never run by the engine, so they are still returned to the caller.'none') do not execute calls, so they are unchanged.Tests
tests/unit/tool-choice-enforcement.test.tscovers:allowed_tools, forcedfunction, and'none'nextTurnParamson the follow-up turnPermissionRequestfor a withheld toolunsentToolResultspath'auto'still running every toolSix of the seven fail on
main. The full unit suite passes (1299 tests), along with lint and typecheck.