You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(tests): the synthetic tiktoken encoding of the prepared-cache test stays in tiktoken's registry, so later token counts on that worker are per byte #2002
_prepare_o200k_cache_dir in tests/test_context_budget.py builds a synthetic o200k_base encoding, in which almost every token is one byte. When count_tokens loads it, tiktoken stores it in its own registry, tiktoken.registry.ENCODINGS. The helper removes the key with monkeypatch.delitem(..., raising=False). When the key was absent before the test, monkeypatch records nothing to restore, so the synthetic encoding stays in the registry after the test. The reset_tiktoken_encoding_cache reset in tests/conftest.py clears only the lru_cache of devops-cli, not tiktoken's registry.
Every later count_tokens call in that process then counts about one token per byte. The pre-push gate of #1995 failed on worker gw4 with four tests: test_truncate_to_token_limit (assert 37 <= 30, where 37 is count_tokens('\n...[truncated due to context budget]')), test_pack_code_fallback_on_non_python, test_pack_snippets_distributes_budget and test_pack_snippets_small_budget_never_exceeds_total.
Give the test its own registry with monkeypatch.setattr(tiktoken.registry, "ENCODINGS", {}). monkeypatch then puts the original dict back at teardown, and the synthetic encoding goes with the test's dict.
Acceptance criteria
A test runs the prepared-cache test and then counts tokens with the real encoding in the same process, and the count is the real one.
Activity
fix(tests): the synthetic tiktoken encoding of the prepared-cache tes…