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(ai): the context-budget tokenizer downloads its encoding on first use and silently falls back to a heuristic #1421
_get_tiktoken_encoding (src/devops_cli/ai/context_budget.py:21-32 on release/v0.2.29 at 05e9388) calls tiktoken.encoding_for_model. tiktoken loads the BPE file from its local cache and downloads it from its public blob store when the cache doesn't have it. The function catches every exception, logs it at DEBUG, and returns None. Because it is wrapped in functools.lru_cache, that None is kept, so the process falls back to the 4-characters-per-token heuristic in count_tokens for its whole life, and nothing above DEBUG says so.
Profiling #1363's tests showed collect_context → truncate_to_token_limit reach this call and hit the test suite's socket guard (tests/conftest.py, guarded_connect). So the suite depends on whether the cache is warm, and the context budget in the Service image depends on whether its first call can reach the internet.
Key question: does the Service image have a populated tiktoken cache, and does its network policy allow that download? Check before choosing the remedy.
Proposed remedy
Populate the tiktoken cache at image build (tiktoken reads TIKTOKEN_CACHE_DIR) and in the dev environment's setup, so the encoding loads with no request. When it still can't load, log a WARNING once naming the cache directory, rather than silently switching to the heuristic.
Acceptance criteria
With sockets blocked, a test loads the encoding from a prepared cache directory and opens no connection.
The Service image build populates the cache, and a test on the Dockerfile or image build asserts it.
A failed load logs one WARNING naming the cache directory.
Tests are offline, each call phase stays under 1 s, and uv run devops ci passes.
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
Priority: P2-Medium. Token-counting accuracy and test-suite determinism are degraded, but the system still functions with a coarser estimate rather than failing outright.
Value: Medium. Correct token budgeting directly affects how much context reaches the LLM and whether the Service image behaves consistently in air-gapped or restricted-network environments.
Effort: Low. The fix is bounded: pre-populate the tiktoken cache at image build, bump the log level to WARNING, and add a few offline tests.
Activity
dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
Token-counting accuracy and test-suite determinism are degraded, but the system still functions with a coarser estimate rather than failing outright.Correct token budgeting directly affects how much context reaches the LLM and whether the Service image behaves consistently in air-gapped or restricted-network environments.The fix is bounded: pre-populate the tiktoken cache at image build, bump the log level to WARNING, and add a few offline tests.fix(ai): populate tiktoken cache at image build and warn on fallback (#…
dan-petty commentedon Oct 21, 2026
What changed
#1770, merged into
release/v0.2.38as ad391be.7 file(s) changed.
How it was verified
Check runs at 67596a4:
Acceptance Criteria of
docs/agent/tasks/task-1421-tiktoken-cache-and-warning.md:No Acceptance Criteria section.
feat(release): v0.2.38 (#1799)
feat(release): v0.2.38 (#1798)