Skip to content

v2.0.6 ONNX cold-start still ~11s — transformers.AutoTokenizer drags torch #1

Description

@nachogeinfor-ops

Summary

v2.0.6's spec promised cold-start would drop from ~13s to ~3s via the ONNX swap, closing F0. Post-release validation shows the actual cold-start is ~11s, not ~3s. F0 closes only partially in environments with generous probe budgets; strict-timeout hosts still drop the 8 mcp__code-context__* tools.

Empirical attribution

Fresh venv install of code-context-mcp==2.0.6.1 on Windows 11 / Python 3.13 / warm HF cache:

Phase Cost
from transformers import AutoTokenizer 5.69s (and triggers import torch transitively)
onnxruntime.InferenceSession(...) ~0.8s
HF cache lookups + tokenizer.from_pretrained ~1s
MCP server boot + stdio handshake ~2-3s
Total ~11s

code-context doctor mcp reports:

initialize (open stdio + handshake)   ok    (11.64s)
list_tools                            ok    (0.00s)
Tools advertised: 8/8 expected

The dominant cost is transformers.AutoTokenizer import. It was assumed to be a thin Python wrapper around the Rust tokenizers library; in reality it pulls in import torch at module init time, which alone is ~5s cold. The ONNX swap saved only the SentenceTransformer ctor (~3.7s), not the transformers/torch chain.

Proposed fix (v2.0.7)

Replace transformers.AutoTokenizer with the tokenizers library directly (HuggingFace's underlying Rust tokenizer, no torch dependency, no Python wrapper). Same tokenizer.json produces byte-identical token IDs — embedding outputs unchanged.

Expected impact: cold-start ~11s → ~3s. Closes F0 strictly.

Design spec: docs/superpowers/specs/2026-05-20-v207-drop-transformers-onnx-path-design.md

Validation already done for v2.0.6.1

✅ Server-side correctness: code-context doctor 28/28 pass, doctor mcp 8/8 tools advertised.
✅ ONNX path produces correct embeddings (smoke run on python fixture: NDCG@10 0.7587).
✅ Tree-sitter chunker works on all 5 supported Python versions (after 1.6.3 pin-out).
⚠️ Cold-start does NOT meet the ~3s spec target.

Workaround for users on v2.0.6.1

If F0 reproduces on your host (Claude Code shows 0 tools after claude mcp list cycles between Connected / Failed), set CC_EMBEDDINGS_BACKEND=torch to fall back to the v2.0.5 behaviour. You lose the partial speedup but get back to a known state.

Acceptance criteria for v2.0.7

  1. import torch is NOT in sys.modules after a fresh LocalONNX(...).embed(['x']).
  2. code-context doctor mcp reports initialize ok (≤3.0s) on warm HF cache.
  3. Existing baseline NDCG@10 matches v2.0.6 within 0.001 (token IDs identical).
  4. All existing tests pass after the test-mock rewrite.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions