Files
pxpipe/tests
teamchong c36ec3fd39 fix(gate): slab call site uses empirically-grounded cpt=2.5 (was 4)
Production data (N=354 cold-miss count_tokens probes, 2026-05-18..05-20):
real body-level chars-per-token is 1.17 median, 2.62 max — never near
the English-prose 4 baked into CHARS_PER_TOKEN. The gate has been
estimating text-token cost at 3.4× cheaper than reality and silently
rejecting every realistic Claude Code system slab.

Concrete production case (orig_chars=161,101, multi-col=2):
  • OLD gate (cpt=4):  text = 161101/4   = 40,275 tok
                       image = 8 × 5500  = 44,000 tok
                       → reject (margin: -3,726)
  • NEW gate (cpt=2.5): text = 161101/2.5 = 64,440 tok
                       image = 8 × 5500  = 44,000 tok
                       → ACCEPT (margin: +20,440)
  • Reality (cpt=1.17): text = 137,694 tok, savings = 93,694 tok/request

SLAB_CHARS_PER_TOKEN=2.5 is the upper bound of observed cpt across the
sample — picking the upper bound keeps the prime-directive guarantee
intact: the text-token estimate is a LOWER bound on real text cost, so
any `imageCost < textTokens` decision is also `imageCost < realTextCost`
for any future workload with cpt ≤ 2.5.

Scope: this is slab-specific. Reminders and tool_result content have
unknown shape (could be raw English prose with cpt~4), so those gate
call sites still use the conservative CHARS_PER_TOKEN=4. Host can
override per-request via TransformOptions.charsPerToken (e.g., to plug
a live empirical fit in front of the static default).

Tests: 2 new regression tests pinning (a) the production-shape 161k slab
compresses end-to-end without an explicit cpt override, and (b) the gate
math at cpt=2.5 vs cpt=4 produces accept-vs-reject on the same input.

272 tests pass, typecheck clean, build clean.
2026-05-20 00:15:55 -04:00
..