Skip to content

Measure tool_tokens — a stale comment hid 28% of the window - #2157

Merged
joelteply merged 1 commit into
canaryfrom
fix/331-tool-token-cost
Aug 6, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/331-tool-token-cost

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The token accounting closes with no missing term. after_framing = 4,634 on a 16,384 window, and 16384 − 4096 reserve − 3045 framing − 4634 leaves ~4,609 for the native tool schemas.

I had been computing after_framing by hand as 16384 − 4096 − 3045 ≈ 9,243 — omitting the tool reserve — and calling the difference an unexplained gap.

describe_tool_tokens was raised as a suspect and then dismissed, because its doc says "a SINGLE tiny schema … a few dozen tokens, not the 4–5k the old full-registry dump cost." That was written when the native surface was a two-tool discovery pair. #206 deliberately removed that clamp and restored ~a dozen tools offered in full. The comment didn't follow, and reading it killed the right answer — the same failure mode as BOOTSTRAP_WORKING_SET.

  • tool_tokens now measured on delib.context.render instead of asserted in prose
  • the prose corrected to say what the surface actually is

Open question, not a claim: the tool surface is paid twice — native schemas (~4,609) plus the human-readable menu in compose_system (~1,000+, inside framing_tokens). That's over a third of a 16k window on tool description before a single message. Whether that duplication is intended needs someone who knows the native-vs-text-model tradeoff.

Tests green (prompt_shaping 18/0).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…window

The accounting closes. `after_framing` reads 4,634 on a 16,384 window, and
`16384 − 4096 reserve − 3045 framing − 4,634` leaves ~4,609 for the native tool
schemas. There was never a missing term: I had been computing `after_framing`
by hand as `16384 − 4096 − 3045 ≈ 9,243`, forgetting the tool reserve entirely,
and calling the difference a phantom.

`describe_tool_tokens` was the suspect I raised and then dismissed — because its
own doc says "a SINGLE tiny schema … a few dozen tokens, not the 4-5k the old
full-registry dump cost." That sentence was written when the native surface WAS a
two-tool discovery pair. #206 deliberately removed that clamp (a native-tool model
can only call what it was offered; the amputated surface stranded it in a
`commands/help` loop and wrote nothing), restoring ~a dozen tools offered in FULL.
The comment did not follow. Reading it is what killed the right answer.

Same failure as `BOOTSTRAP_WORKING_SET`: a comment that outlived its code, trusted
because it was specific. So the number is now MEASURED on the probe as
`tool_tokens` instead of asserted in prose, and the prose says what it actually is.

What this exposes, stated as a question rather than a claim: the tool surface is
paid TWICE — once as these native schemas (~4,609) and again as the human-readable
menu inside `compose_system` (inside `framing_tokens`, ~1,000+). Together that is
over a third of a 16k window spent describing tools before one message is read.
Whether the duplication is intended is not something I can settle from here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 4b6de22 into canary Aug 6, 2026
1 check passed
@joelteply
joelteply deleted the fix/331-tool-token-cost branch August 6, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant