Repository navigation
SWF(bug): count legacy completion prompt tokens once per request - #72
Merged
maplepaladin73 merged 1 commit intoNov 23, 2026
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
/v1/completionswithn > 1reportedusage.prompt_tokensmultiplied byn(n=2 with a 1-token prompt reported 2). Now each prompt is counted once.Root cause: in
run_blocking(crates/spark-server/src/api/completions_exec.rs),sum_prompt += prompt_tokens.len()sat inside the per-choicefor n_i in 0..nloop, so the same prompt was added once per choice. The fix moves it to the outer per-prompt loop. Completion tokens are still summed across choices. For the same reason, cached prompt tokens now take the largest cached prefix per prompt instead of summing it per choice, which matches blocking chat and keepscached_tokens <= prompt_tokens.Test plan
New regression
completion_usage_counts_prompt_once_for_multiple_choicescalls the real handler with a scheduler fixture: n=2, 1-token prompt. It expects 2 choices, prompt 1, completion 2, total 3, cached 1.Try it:
Before the fix (main):
After the fix:
Full CPU suite
cargo test -p spark-server --bin spark:3253 passed; 0 failed; 14 ignored.cargo fmt --all -- --checkATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000): cleanbash scripts/check-license-headers.sh: OKtypos: cleanNotes for reviewers
Untested: live serving on GPU and streaming
/v1/completions(this changes only the blocking path).CLA
Implemented in session Count legacy completion prompt tokens once per request
Review with Devin · Open in Devin Desktop