Skip to content

[v0.5.0] benchmark tokens — Claude token-count integration after client rewrap (live-phase-gated) #89

Description

@ayhammouda

Context

Parent: #63. Methodology: docs/benchmarks/PUBLIC-BENCHMARK-METHODOLOGY.md (work package 6; "Token Measurement" section). Roadmap decision 5.8: Claude tokenizer, measured after client-side rewrap. Maintainer decision on record (PLAN.md Amendment 2026-07-08): the Anthropic count-tokens API is the counting mechanism, confined to the maintainer-run live phase — exact counts for headline claims, zero runtime network access or new dependencies in the server itself. Token records (merged #75) carry client_wrapped_tokens: None / raw_payload_tokens: None placeholders; benchmarks/model_matrix.py exposes METHODOLOGY_TOKEN_LABEL = "Claude Tokens (Normalized Payload)".

Status: NOT agent-ready. Filed by the orchestrator per PLAN.md T6(b); Vision must review, create the .planning/agent-context/ file (decision 5.14, mirrored as an issue comment), and apply agent-ready before any dispatch.

Goal

Add the Claude token-count integration: capture the client-rewrapped message envelope per cell, count it via the Anthropic count-tokens API behind the live-phase guard, and fill the runner's token records — with approximations clearly marked and barred from headline claims.

Acceptance criteria (draft — Vision edits before agent-ready)

  • Envelope capture: the counting path takes the same client-side wrapping used by the benchmark client (methodology "Token Measurement" steps 1–3); where a client cannot expose its exact wrapped envelope, the record is marked approximation: true and the report generator ([v0.5.0] benchmark reporting — generate raw report and README-safe summary #74) must exclude it from headline-eligible tables.
  • The count-tokens API call sits behind require_live_environment() (same guard as [v0.5.0] benchmark adapters — define OpenAI/Google model matrix #85) plus an Anthropic key env var; CI and unit tests never call it — tests use a fake counter.
  • Completed token records fill client_wrapped_tokens and raw_payload_tokens (raw payload counted separately as diagnostic data), labeled Claude Tokens (Normalized Payload) via the exported constant — never confusable with provider billing tokens.
  • A new third-party runtime dependency (e.g. anthropic), if proposed, is a supervisor-review trigger: justify why a direct HTTPS call via existing deps is insufficient, and in any case the dependency must be an optional extra or dev/benchmark-only group — never a server runtime dependency.
  • Tests (additive, under tests/benchmarks/) cover fake-counter records, approximation marking, guard refusal without env config, and serialization-latency capture alongside counts (decision 5.8 reports tokens AND latency).
  • No README/benchmark claims; Refs #63, never Closes #63.

Scope boundaries

In scope: counting integration, guard, record filling, fake-counter tests. Out of scope: spending API credits (maintainer live phase only), report layout (#74), corpus, README.

Forbidden-territory reminder

Standard §2 list applies (notably: pyproject.toml [project] changes and new runtime deps are supervisor-review at minimum); merged tests additive-only; the server's offline-first runtime (principle 2.2) is untouchable — network lives only in the guarded benchmark live path.

Validation commands

uv run ruff check src/ tests/
uv run ruff check benchmarks/
uv run pyright src/
uv run pyright benchmarks/
uv run pytest --tb=short -q
uv run pytest tests/benchmarks -q
uv run python-docs-mcp-server doctor
uv lock --check   # if any dependency/extras change is proposed

Recovery

If client-rewrap capture proves impossible for a given client, stop and comment here with the exact gap — the methodology requires marking that result as an approximation, not guessing.

Effort estimate

4–8 hours.

Refs #63.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyIssue passed AGENT-EXECUTION-PIPELINE.md §10 pre-flight; scoped for an autonomous agentenhancementNew feature or requestpriority:P2Medium priority

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions