fix(pragent): bake the tiktoken encodings so a read-only install works (0.12.1) - #233
Merged
Merged
Conversation
Every /describe and /review on an installed Windows build died with PermissionError under C:\Program Files. The cause is a bad file in the package, not a permissions setting. litellm points TIKTOKEN_CACHE_DIR at its own tokenizers/ directory and ships encoding files there to be offline-capable, but the files it ships fail the expected_hash pinned by the tiktoken it depends on -- all three of them. tiktoken therefore treats the cache as invalid on every run and re-downloads into site-packages, which is writable while building and read-only once installed. It is not model specific: every path that counts tokens goes through it. scripts/tiktoken-cache.py prime repairs the bundled bytes at assemble time, so the cache is a hit and nothing is written at runtime. verify asserts it, and runs after slimming so a slim rule that deletes the cache is caught too. The assertion compares hashes rather than just loading the encoding, because loading proves nothing here: a stale file loads fine on a machine that can re-download it. That is exactly how 0.12.0 shipped -- assembled clean, smoke tested clean, then failed on the first run of every install. Expected hashes are read from the installed tiktoken rather than copied here, so they cannot drift from it on the next upgrade. Documents the general rule in AGENTS.md and the runtime design doc: the install directory is read-only, a dev machine never shows this because vendor/ is writable, so a dependency that writes under its own package must be pre-populated at assemble time and asserted. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Patch release for the read-only install failure (#232): version, changelog section in both locales with their compare links, lockfile synced. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 10, 2026
Merged
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.
Fixes #232 and prepares the 0.12.1 patch release.
The released 0.12.0 Windows build fails every
/describeand/reviewwithPermissionErrorunderC:\Program Files, which makes the installed app unusable.Cause
Not a permissions setting — a bad file inside the package.
litellm points
TIKTOKEN_CACHE_DIRat its ownlitellm_core_utils/tokenizers/and ships encoding files there so tiktoken works offline. But the files it ships fail theexpected_hashpinned by the tiktoken it depends on — all three of them (litellm 1.99.0 / tiktoken 0.12.0). tiktoken therefore treats the cache as invalid on every run: it deletes the file and re-downloads it intosite-packages. Writable while building, read-only once installed.Not model specific: the reported trace is a CLI provider (
o200k_base), but agptmodel resolves throughencoding_for_model()to the same stale files.Why it shipped
Worth stating, because it explains why the existing gates were useless here:
vendor/is writable, so tiktoken repairs itself on first run and stays fine forever.Fix
scripts/tiktoken-cache.py:Two deliberate choices:
verifyruns after slimming, so a slim rule that deletes the cache is caught too.Verification
Four steps, closing the loop in both directions:
verifyprime.tmpleftovers cleanedicacls)PermissionErrorexactlylint/typecheck/test/buildpass.Rule recorded
Same class as the pre-written
.secrets.tomlalready handled in the assembler — a dependency writing under its own package at runtime. That was fixed as a one-off without becoming a rule, which is why this recurred. Now in AGENTS.md (engineering maintenance pitfalls) anddocs/arch/02-agent/05-pragent-runtime.md: when adding or upgrading a Python dependency, check whether it writes under its own package at runtime; if so pre-populate it at assemble time and assert it, because the build machine can always write.Release
This branch also carries the
chore(release): 0.12.1commit (version, both changelogs with compare links, lockfile). After merging todev, the release flow isdev → master, tagv0.12.1, back-merge, bump.🤖 Generated with Claude Code