← Back to Pull requests

feat(tokenizer): lcc fetch-tokenizer for exact counts on first run #130

Open
unknown opened this pull request with 170 lines diff across 2 files
View on GitHub
unknown unknown commented on Oct 28, 2026 20:09 UTC
Author

A new user who follows the README (pip install "local-context-compiler[tiktoken]", then lcc measure-session) gets tokens (approximate) and a four-line warning, because lcc blocks tiktoken's download to stay offline (ADR 0008). The only fix was setting TIKTOKEN_CACHE_DIR by hand.

This adds one explicit command:

  • lcc fetch-tokenizer downloads cl100k_base and o200k_base into ~/.cache/lcc/tiktoken (or TIKTOKEN_CACHE_DIR when set). It is the only command that goes online.

  • When TIKTOKEN_CACHE_DIR is unset and that directory exists, counters.py points tiktoken at it. An explicit TIKTOKEN_CACHE_DIR always wins.

  • The approximate-count note now names the command.

  • README install block gains the line; CHANGELOG entry.
  • Normal operation stays offline: the no-network guard is unchanged and still wraps every count.

    Measured (2026-10-28, one 3,898-message session, fresh HOME): before fetch 523,741 tokens (approximate); after lcc fetch-tokenizer, 844,444 tokens (exact). One session, so the 38% gap is an example, not a general error rate.

    Tests: test_fetch_tokenizer_fills_the_cache_dir_with_network_allowed; tests/test_token_budget.py tests/test_session_report.py tests/test_docs.py pass; ruff check clean. ruff format --check flags counters.py for a missing blank line that is already on main, left as is.

    Diff: 170 lines (+127 / -43) across 2 files Reviewer: claude[bot] Review duration: 1m
    All Vouch review confidence checks passed
    Residual risk 0.47 = Change Risk (0.58) × (1 − Review Confidence (0.19)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.58 · 170 lines diff across 2 files
    0.58
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 23% · Reviewer familiarity: 35%
    18%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.308
    Sensitive Paths sensitive_paths
    0.058
    Real PR Conversation Timeline
    1 comments
    "Review active on #130"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 18.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 58.4% (MEDIUM) · Higher = larger blast radius
    58.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 18.9% · Lower = rushed or shallow review
    18.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 47.3% · Moderate risk
    47.3%