Skip to content

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

Closed

Description

@squid-protocol

What

gitgalaxy/core/detector.py loads tiktoken's encoding at import time, and only guards ImportError:

HAS_TIKTOKEN = False
try:
    import tiktoken
    HAS_TIKTOKEN = True
    ENCODER = tiktoken.get_encoding("cl100k_base")   # downloads on first use
except ImportError:
    pass

When tiktoken is installed but cl100k_base isn't cached and can't be downloaded, get_encoding raises, and import gitgalaxy.core.detector fails. Examples: a network-restricted sandbox, an air-gapped machine, a corporate proxy. That takes galaxyscope and every test that imports the engine down with it. The failure is a requests.exceptions.ProxyError (or a DNS or timeout error), not an ImportError.

This contradicts Zero-Dependency Mode (docs/zero_dependency_mode.md): "tiktoken unavailable" is supposed to mean token mass comes back NULL and the scan proceeds. It is also the air-gapped scenario the project explicitly supports.

Reproduce

In an environment where openaipublic.blob.core.windows.net is blocked, with no TIKTOKEN_CACHE_DIR / data-gym-cache entry:

pip install tiktoken
python -c "import gitgalaxy.core.detector"
# requests.exceptions.ProxyError: ... /encodings/cl100k_base.tiktoken ... 403 Forbidden

Found while writing the session setup hook for #3778. That hook now leaves tiktoken uninstalled when the host is unreachable, as a workaround.

Fix

  • Catch any exception from get_encoding, not only ImportError.
  • Leave HAS_TIKTOKEN = False (so missing_dependencies() reports tiktoken missing, and the run is labelled Zero-Dependency Mode).
  • Log one warning naming the cause.
  • Add a test that monkeypatches tiktoken.get_encoding to raise and asserts the module still imports with HAS_TIKTOKEN is False.

Activity

  1. added
    bug
    core-engine
    on Sep 26, 2026
  2. squid-protocol commented on Sep 26, 2026

    @squid-protocol
    OwnerAuthor

    don't degrade automatically, these are typically an AI getting the wrong env, perhaps we should make the dependencies more clear on if they need to run or not, what is acceptable, but we can't change modes randomly for temporal comparability.

  3. added a commit that references this issue on Oct 1, 2026
  4. added
    scope:infra
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginescope:infra

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions