Files
pxpipe/tests
teamchong b563751cf6 fix(gate): history call site uses empirically-grounded cpt=2.5 (was 4)
Production telemetry (N=10 events with history_reason="not_profitable",
2026-05-18..05-20) shows body-level chars-per-token on rejected history
events: median 1.09, max 1.10. The gate at cpt=4 was estimating text as
3.7× cheaper than reality on every history-collapse decision in the
sampled traffic — same shape of bug as the slab path fixed in c36ec3f.

Why this matters more than the slab fix:
  • The slab is cached (cache_create×1.25 once, cache_read×0.10 after).
    Slab compression saves bytes mostly on cold misses + 2k tok/warm hit.
  • History content is NOT cached. Once turns leave the cache breakpoint
    budget (4 max per request), every subsequent request pays 100% for
    them. A long agentic session re-bills the same closed-prefix turns
    on every turn — exactly the workload Variant C was designed to
    compress, and exactly the path the gate was silently rejecting.

Apply same fix as c36ec3f: HISTORY_CHARS_PER_TOKEN=2.5 (upper bound of
empirical data, identical safety property to SLAB_CHARS_PER_TOKEN since
history content shape ⊆ slab content shape in tool-heavy sessions).

Host can still override via TransformOptions.charsPerToken. The
override-gate `o.charsPerToken !== CHARS_PER_TOKEN` means unspecified
requests (DEFAULTS.charsPerToken=4) get the empirical cpt while explicit
non-default host values win — same intentional pattern as the slab path.

Test: regression fixture pinning a 14-turn × 1500 chars/turn conversation
where:
  • cpt=4 path → 'not_profitable' rejection (image cost 5k > text 4k)
  • cpt=2.5 path → 'collapsed' with 10 turns merged (text 6.4k > image 5k)
Counterfactual half uses cpt=4.5 to bypass the override-gate (passing
exactly 4 collides with the DEFAULTS sentinel).

273 tests pass, typecheck clean, build clean.
2026-05-20 07:52:58 -04:00
..