Repository navigation
test: pin the token estimators' arithmetic and history signature - #284
Merged
Zongwei9888 merged 1 commit intoOct 28, 2026
Merged
Conversation
estimate_prompt_tokens and estimate_message_tokens decide when the pressure gate compacts or discards history, and history_signature is the contract by which the token meter's anchor and the compaction memo agree on what "unchanged" means. All three were exercised only indirectly, through the meter. Add direct tests that lock the offline estimator's length-over-four arithmetic, the per-field collection that lets a tool turn's price move, the script-blindness that prices a CJK prompt like an ASCII one of equal length, and the signature prefix property the anchor relies on. The tokenizer is forced off so every value is exact regardless of what the machine happens to have installed.
Collaborator
|
Thanks @raymondginger2018-sudo, merged as 3d0bfe8. Having these helpers pinned directly is useful. One note for later: the |
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.
Why
estimate_prompt_tokensandestimate_message_tokensdecide when the pressure gate compacts or discards history, andhistory_signatureis the contract by which the token meter's anchor and the compaction memo agree on what "unchanged" means. All three were exercised only indirectly, through the meter, so a silent change here would surface as a context overflow or an anchor that quietly stops anchoring.What
New file
tests/test_token_estimator.py(13 tests, no production code touched):len(payload) // 4 + 4 * messagesand the 4-token floor, with the tokenizer forced off so every value is exact on any machine.tool_calls,reasoning_content,name,tool_call_id) and thetoolsschema is asserted to move the price; text-parts are priced like the equivalent string, non-text parts are not.cl100k_basea CJK character costs more than ASCII. Both behaviours are pinned so a future script-aware change is a reviewed decision.Test plan
pytest tests/test_token_estimator.py— 13 passed.pytest tests/test_token_meter.py tests/test_token_meter_wiring.py tests/test_tool_result_spill.py— all green (the tests that exercise these helpers indirectly).pre-commit run --all-files— all hooks passed.pip check— only unrelated ML-package conflicts from the local global env; CI installs from the lockfile in a clean venv.