Files
pxpipe/tests
teamchong 178fd4af6f fix(gate): scale per-image token cost by numCols (close multi-col loss-risk)
Production runs multiCol=2 by default. The pre-flight gate
`isCompressionProfitable()` was using a flat TOKENS_PER_IMAGE=2500
constant at every numCols, so it believed multi-col images were ~2x
cheaper than they actually are and would let net-loss compressions
through on wider canvases.

Replace the flat constant with `effectiveTokensPerImage(numCols)`:
  numCols=1: 2500  (empirical, N=33 cold-miss measurement)
  numCols>1: 2500 * n * 1.10  (linear extrapolation + 10% margin)

The 10% margin absorbs extrapolation noise — we don't yet have
empirical cost measurements at numCols>=2. Per user constraint
"ok pre-flight gate is ok to be not correct as long as we don't
lose money," every uncertainty resolves in favor of pass-through.
At worst we miss opportunities; we never burn money on net-loss
images.

Test fixtures bumped to match the new break-even (~22k chars at
n=2). Two obsolete cpt-flip tests REWRITTEN to assert the safe
behavior: cpt override flips at numCols=1, but at numCols=2 the
safety margin holds and the slab stays rejected.

  Old break-even at default cpt=4:
    n=1: ~10k chars  (1 image @ 2500 tok == 10k/4 = 2500 text tok)
    n=2 [old/wrong]: ~10k chars (same flat cost)
    n=2 [new/safe]:  ~22k chars (1 image @ 5500 tok == 22k/4 text tok)

Verified: 263/263 tests pass, typecheck clean, build clean.
2026-05-19 23:33:22 -04:00
..