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

+3 -1
View File
@@ -22,7 +22,7 @@ from nanobot.providers.openai_codex_provider import OpenAICodexProvider, _CodexH
from nanobot.providers.openai_responses import build_responses_state
def _request_state(provider, *, prior_tokens=180_000, repetitions=15_000):
def _request_state(provider, *, prior_tokens=180_000, repetitions=12_000):
model = "openai-codex/gpt-5.6-sol"
accepted = [
{"role": "system", "content": "Continue the coding task."},
@@ -42,6 +42,8 @@ def _request_state(provider, *, prior_tokens=180_000, repetitions=15_000):
],
usage=LLMUsage.reported(input_tokens=prior_tokens, output_tokens=10),
)
# The default delta pressures prior state but fits after compaction, even with
# UTF-8 byte estimates while the fallback tokenizer is unavailable.
delta = {"role": "tool", "name": "read_file", "tool_call_id": "read-1",
"content": "source_line\n" * repetitions}
raw = [*deepcopy(accepted), delta]
+3 -1
View File
@@ -136,6 +136,7 @@ class TestTurnTranscriptSummary:
runtime,
summary,
):
runtime = replace(runtime, context_window_tokens=4096)
accepted = [
{"role": "system", "content": "stable system"},
{"role": "user", "content": "accepted history"},
@@ -401,7 +402,7 @@ class TestConsolidatorSummarize:
mock_provider,
runtime,
):
runtime = replace(runtime, generation=GenerationSettings(max_tokens=96))
runtime = replace(runtime, generation=GenerationSettings(max_tokens=256))
mock_provider.chat_stream_with_retry.side_effect = RuntimeError("API error")
result = await _archive(
@@ -910,6 +911,7 @@ class TestCompactIdleSession:
store,
runtime,
):
runtime = replace(runtime, generation=GenerationSettings(max_tokens=256))
mock_provider.chat_stream_with_retry.side_effect = [
LLMResponse(content="Earlier durable checkpoint.", finish_reason="stop"),
RuntimeError("LLM unavailable"),
+2
View File
@@ -396,6 +396,7 @@ class TestEphemeralDirect:
provider.get_default_model.return_value = "test-model"
provider.supports_tools = True
provider.generation = MagicMock(max_tokens=4096)
provider.estimate_prompt_tokens.return_value = (100, "test")
provider.chat_stream_with_retry = AsyncMock(
return_value=LLMResponse(content="done", tool_calls=[], finish_reason="stop", usage=None)
)
@@ -671,6 +672,7 @@ class TestEphemeralHooks:
provider.get_default_model.return_value = "test-model"
provider.supports_tools = True
provider.generation = MagicMock(max_tokens=4096)
provider.estimate_prompt_tokens.return_value = (100, "test")
provider.chat_stream_with_retry = AsyncMock(
return_value=LLMResponse(
content="done", finish_reason="stop", tool_calls=[], usage=None,
+3
View File
@@ -86,6 +86,9 @@ async def test_process_message_hands_complete_replay_to_runner(tmp_path: Path) -
@pytest.mark.asyncio
async def test_runner_checkpoint_keeps_current_user_as_replay_boundary(tmp_path: Path) -> None:
loop = _make_loop(tmp_path, context_window_tokens=8_000)
loop.provider.estimate_prompt_tokens.side_effect = (
lambda messages, tools, model: (100 * len(messages), "test")
)
loop.provider.chat_stream_with_retry = AsyncMock(
return_value=LLMResponse(content="ok", tool_calls=[], usage=None)
)
@@ -31,6 +31,9 @@ class RecordingProvider(LLMProvider):
def get_default_model(self) -> str:
return self.name
def estimate_prompt_tokens(self, messages, tools=None, model=None) -> tuple[int, str]:
return 100, "test"
@pytest.mark.asyncio
async def test_sessions_run_concurrently_with_isolated_model_presets(tmp_path) -> None: