Repository navigation
SWF(bug): accept count_tokens requests without max_tokens - #73
Merged
Merged
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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
POST /v1/messages/count_tokensnow accepts requests withoutmax_tokens, matching Anthropic's API, instead of returning 400.Root cause:
count_tokensdeserialized the body intoMessagesRequest, whosemax_tokensfield is required for generation. Axum's JSON extractor rejected otherwise valid counting requests withmissing field 'max_tokens'.Fix: a dedicated
CountTokensRequest(model, messages, system, tools, tool_choice, thinking: the fields that affect the prompt) that lowers through the existingMessagesRequest→ IR adapter with generation fields unset. The count still uses the same prompt rendering path as serving./v1/messagesstill requiresmax_tokens.Test plan
Regression test
anthropic::handlers::tests::count_tokens_without_max_tokenssends the real route a request with nomax_tokens, using a fixture tokenizer.Before fix (on main):
After fix:
Full suite (
ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark):A contract test,
count_tokens_request_contract, checks that an emptymessageslist parses, thatMessagesRequeststill rejects a body withoutmax_tokens, and that a body missingmodelormessages, or with the wrongmessagestype, is still rejected.cargo fmt --all -- --check: passATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy -p spark-server --tests: pass, no warningsbash scripts/check-license-headers.sh: 4267 valid, 0 invalidtypos: passTry it (against a running server):
Notes for reviewers
Untested: a live-model or Docker run; clippy ran on
spark-serveronly, not the whole workspace (only this crate changed).Implemented in session Accept count_tokens requests without max_tokens
Review with Devin · Open in Devin Desktop