[GTC] fix(tokenizer): bound pathological token counting#1036
Merged
esengine merged 1 commit intoMay 17, 2026
Conversation
Owner
|
Thanks @GTC2080 — clean fix and great test coverage on the perf bound. Merged. |
ChasLui
pushed a commit
to ChasLui/DeepSeek-Reasonix
that referenced
this pull request
May 23, 2026
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.
What
Adds bounded token counting for oversized text and routes the hot token-estimation paths through it: request estimation, context shrink ordering,
/contextbreakdowns, desktop context telemetry,/cost, streaming token-rate estimates, and subagent distillation metrics. This keeps exact counting for normal-sized inputs while sampling pathological large strings.Why
Fixes #558. A reproduction is a very large repetitive payload such as
"A".repeat(100_000)flowing into token-counting paths; exact BPE counting can spend multiple seconds there before shrink/healing gets a chance to reduce the content. The bounded counter avoids that stall while preserving a proportional estimate for context budgeting and UI telemetry.How to verify
npm run verifyRegression coverage added for
countTokensBounded("A".repeat(100_000))and for/contextbreakdown over a 100KB tool result, both asserting the pathological path stays under 1 second.Checklist
npm run verifypasses locally (lint + typecheck + tests + comment-policy gate)Co-Authored-By: Claudetrailer in commitsCHANGELOG.md— release notes are maintainer-written at release time