fix(tokens): warm fallback tokenizer in background (#5861)

* fix(tokens): keep fallback token estimation offline

* fix(tokens): warm fallback tokenizer in background

* test(tokens): isolate agent fixtures from tokenizer readiness

* test(tokens): keep Codex pressure fixtures within byte budget

* docs: remove manual wrapping from troubleshooting prose
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-28 13:50:55 +08:00
1 parent e0b8efa0be
commit 4a7ad00e4f
16 files changed
+378 -101

No files matched your search

+4 -5
View File
@@ -3,9 +3,8 @@ import os
from pathlib import Path
import pytest
import tiktoken
from nanobot.utils import helpers
from nanobot.utils import helpers, token_encoding
from nanobot.utils.helpers import (
_write_text_atomic,
atomic_write_lines,
@@ -107,14 +106,14 @@ def test_truncate_text_to_tokens_keeps_text_within_budget():
assert result == text
def test_truncate_text_to_tokens_truncates_over_budget():
enc = tiktoken.get_encoding("cl100k_base")
def test_truncate_text_to_tokens_truncates_over_budget(monkeypatch, byte_encoding):
monkeypatch.setattr(token_encoding, "_encoding", byte_encoding)
text = "word " * 1_000
result = truncate_text_to_tokens(text, 50)
assert result.endswith("\n... (truncated)")
assert len(enc.encode(result)) <= 50
assert len(byte_encoding.encode_ordinary(result)) <= 50
def test_truncate_text_to_tokens_non_positive_budget_returns_text():