Repository navigation
SWF(bug): reject named tool_choice not among declared tools - #52
Merged
Merged
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration
Bot
force-pushed
the
devin/1795371427-named-tool-choice
branch
from
November 22, 2026 18:29
c477a44 to
92223a4
Compare
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
A chat request whose
tool_choicenames a function that isn't intools(or with notoolsat all) is now rejected with a 400 (param: "tool_choice") instead of being silently accepted.Root cause:
validate_inputincrates/spark-server/src/api/chat_phases.rsonly matchedToolChoice::Mode(auto/none/required), soToolChoice::Specific { function }skipped validation entirely. The new guard checks the name against the declaredtool.function.names. Anthropic{type:"tool", name}converts to the sameToolChoice::Specificand runs throughchat_completions_inner→validate_input, so it is covered by the same check.Test plan
Failing run on unfixed code (regression test added first; captured before the rebase onto #51, with the stray attribute removed locally):
Passing run with the fix:
Full
sparktest binary on the rebased branch:The rejection test covers omitted
tools, emptytools, and a non-matching tool; the acceptance test covers a declared name among several. Existing Anthropic conversion tests: 11 passed.Try it (after
bash scripts/ci_gpu_stubs.sh):ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark named_tool_choiceBlueprint lint (
cargo fmt --all -- --check && cargo clippy --workspace --tests && check-license-headers.sh && typos):cargo fmt --all -- --check--workspace --testsbash scripts/check-license-headers.shNotes for reviewers
validate_inputunit level only.tool_choiceof typetoolwith nonamestill falls back toauto; that behaviour is unchanged.Implemented in session Validate named tool_choice against declared tools
Review with Devin · Open in Devin Desktop