Skip to content

An installed tiktoken that cannot load its encoding no longer takes the engine down (#3791) - #4064

Merged
squid-protocol merged 1 commit into
mainfrom
fix/tiktoken-offline-3791
Oct 1, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/tiktoken-offline-3791

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3791.

gitgalaxy/core/detector.py loads tiktoken's cl100k_base at import time and caught only ImportError. Offline (an air-gapped site, a proxy, a sandbox), get_encoding raises a network error when the encoding is not cached. That made import gitgalaxy.core.detector fail, which took down galaxyscope and every engine test.

Fix

  • Any exception from loading the encoding now leaves HAS_TIKTOKEN False.
  • HAS_TIKTOKEN is set only after the encoding loads.
  • The result matches the case where tiktoken is not installed: token mass is NULL, missing_dependencies() reports tiktoken, and the run is labelled Zero-Dependency Mode.
  • One warning names the cause and TIKTOKEN_CACHE_DIR.

The porting tickets' tokenizer already handled this (#3863).

Test (tests/core_engine/test_zero_dependency.py): a fresh interpreter, given a tiktoken whose get_encoding raises ConnectionError, imports the engine with HAS_TIKTOKEN False and token mass None. The test fails without the fix. tests/core_engine passes (2,072), and audit_check is clear.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ

…takes the engine down

detector.py loads tiktoken's cl100k_base at import time and caught only
ImportError. Offline -- an air-gapped site, a proxy, a sandbox --
get_encoding raises a network error when the encoding is not cached, and
`import gitgalaxy.core.detector` (galaxyscope, every engine test) failed.

Any exception from loading the encoding now leaves HAS_TIKTOKEN False:
token mass is NULL, missing_dependencies() reports tiktoken, the run is
labelled Zero-Dependency Mode -- as when tiktoken is not installed -- and
one warning names the cause and TIKTOKEN_CACHE_DIR. HAS_TIKTOKEN is set
only after the encoding loads. The porting tickets' tokenizer already
handled this (#3863).

Test: a fresh interpreter with a tiktoken whose get_encoding raises
ConnectionError imports the engine, HAS_TIKTOKEN is False and token mass
is None (fails before the fix).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
@squid-protocol squid-protocol added this to the Side Quests 🗺️ milestone Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 068104a into main Oct 1, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the fix/tiktoken-offline-3791 branch October 1, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

detector.py: an installed tiktoken whose encoding can't be downloaded makes the whole engine fail to import (instead of Zero-Dependency Mode)

1 participant