#3777·headroom

HEADROOM_OFFLINE=1 does not prevent the HuggingFace tokenizer download

Author: danielamadoriCreated Sep 24, 2026Updated Sep 24, 2026

HEADROOM_OFFLINE=1 does not prevent the HuggingFace tokenizer download

Version: headroom-ai 0.38.0 · macOS 15 (Apple Silicon) · Python 3.12

Summary

headroom/offline.py describes HEADROOM_OFFLINE as the "air-gap / no-egress master switch". With it set, is_offline() returns True and the proxy still downloads a tokenizer from huggingface.co on the first request for a model whose tokenizer is not cached.

The download is performed with trust_remote_code=True (headroom/tokenizers/huggingface.py:162 and :184), so remote Python is fetched and executed.

Reproduction

Pick a tokenizer that is not in the local HF cache, then:

python
import os
os.environ["HEADROOM_OFFLINE"] = "1"
from headroom import offline
assert offline.is_offline() is True          # the switch is active

from headroom.tokenizers.huggingface import _load_tokenizer
_load_tokenizer("Qwen/Qwen2-7B")             # downloads anyway

Observed: ~/.cache/huggingface/hub/models--Qwen--Qwen2-7B appears, and for a repo with custom code, configuration_*.py / tokenization_*.py land in ~/.cache/huggingface/modules/transformers_modules/.

Measured one setting at a time, removing the cache directory between runs:

setting download
HEADROOM_OFFLINE=1 yes
HEADROOM_HF_TOKENIZER_LOAD_TIMEOUT_SECS=0 no
HF_HUB_OFFLINE=1 no
TRANSFORMERS_OFFLINE=1 no

Why the timeout is not a substitute

_load_tokenizer runs the download on a daemon thread with a bounded join, and the comment states the download itself cannot be cancelled. On timeout the caller resumes while the network request and the remote-code execution continue, so a low timeout bounds the wait, not the egress.

Suggested fix

Have _load_tokenizer consult offline.is_offline() before the network attempt and fall back to estimation, the same path HEADROOM_HF_TOKENIZER_LOAD_TIMEOUT_SECS=0 already takes.

Note

Unrelated to the bug, but it surprised us: _TOKENIZER_MAP maps the prefix qwen to Qwen/Qwen-7B, so a Qwen3 model resolves to a first-generation tokenizer. Token counts reported for such models are computed with it.

Source: headroomlabs-ai/headroom