Repository navigation
refactor(rust): split token counter backends - #42165
Merged
Merged
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
yujonglee-berri
approved these changes
Sep 20, 2026
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Contributor
|
This comment has been minimized.
This comment has been minimized.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
|
@greptile-apps wdyt |
yujonglee-berri
enabled auto-merge
September 20, 2026 22:18
yujonglee-berri
approved these changes
Sep 20, 2026
4 of 6 tasks
4 tasks done
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.
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a Rust caller loads a malformed rank file and receives an incorrect count
input_tokens=3input_tokens=2After: the same caller gets an explicit error for the malformed file
error=failed to load tokenizer: tiktoken rank file: rank 4294967295 is reservedinput_tokens=2Relevant issues
Affected release
Linear ticket
Pre-Submission checklist
Validation
The four tokenizer crates pass 168 tests. The counter tests and Python bridge checks pass with each of the eight feature combinations. Workspace Clippy passes with warnings denied, including benchmark targets. Full workspace test compilation, Rust formatting, and the CI shell syntax checks pass
The regression test fails without the reserved-rank validation and passes with it. The shared cl100k/o200k fixtures now run against both fast and tiktoken, including requests with tools and large prompts. Every named tiktoken encoding is checked against its reference encoder on ordinary text, Unicode, whitespace, and special-token spellings. Encoding failures preserve the backend error source
Dependency inspection confirms that the default Python bridge includes only fast, and the counter with default features disabled has no built-in tokenizer dependency
Screenshots / Proof of Fix
These are real calls through the public Rust library, without mocks. Token counting is local and does not call an LLM provider
Shared setup and complete client
Run from the PR checkout. The before snapshot uses the merge base, and the after client uses the current checkout
Save this as
/tmp/pr42165-audit/before-client/src/main.rsand copy it to/tmp/pr42165-audit/after-client/src/main.rsBefore (0e61ed5)
Reserved rank
cargo run --quiet --manifest-path /tmp/pr42165-audit/before-client/Cargo.toml -- /tmp/pr42165-audit/reserved.tiktokeninput_tokens=3Valid rank
cargo run --quiet --manifest-path /tmp/pr42165-audit/before-client/Cargo.toml -- /tmp/pr42165-audit/valid.tiktokeninput_tokens=2After (661da87)
Reserved rank
cargo run --quiet --manifest-path /tmp/pr42165-audit/after-client/Cargo.toml -- /tmp/pr42165-audit/reserved.tiktokenerror=failed to load tokenizer: tiktoken rank file: rank 4294967295 is reservedValid rank
cargo run --quiet --manifest-path /tmp/pr42165-audit/after-client/Cargo.toml -- /tmp/pr42165-audit/valid.tiktokeninput_tokens=2Type
Refactoring and bug fix
Caveats (if any)
Medium
Low
Final Attestation