Repository navigation
fix: count the image term in effectiveTokenCount's anonymous fork branch - #1139
ranxianglei wants to merge 1 commit into
Conversation
The anonymous prefix-affinity early return in effectiveTokenCount still returned estimateCoreMessagesUpper(msgs) — text only — even though #1120 made the explicit-identity min-cap branch image-aware and all four prepare sites pass inboundImageTokens. Wire codecs move images out of CoreMessage.text into sidecars, so an image-heavy fork replaying its full raw history read a text-only char count: usage % far below reality, decideNudge structurally unfireable, over-window payload forwarded raw. Hoist raw above the early return: a fork replays the FULL raw history in one request, so this request's image term IS the whole history's image mass. Conservative direction unchanged (upper bound → compress earlier, never later); the #728 stale-high invariant is preserved untouched. Regression pin in tests/fork-nudge-trigger.test.ts: an anonymous image-heavy fork whose text-only bound (~58% of an 80k window) sits below every nudge band but whose image-aware bound (~83%) crosses the 75% pressure band — fails pre-fix (no nudge), passes post-fix; preflight stays silent and nothing folds. Fixes #1137
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1139Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1139.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR review complete — verified independently, ready to merge. Branch/base: single commit Code review (against #1137's scope):
Independent A/B reproduction (not just trusting the claims):
Pre-flight on head CI: PR is open with E2E note: the full Verdict: single-module pure fix, regression test reproduces the original bug, green on the rebased head, diff clean, references its issue via 修复了 |
|
Closing as duplicate of #1140 — both PRs implement the identical fix for #1137 (hoist |
What
Residual from #1119 / PR #1120 review, per @ranxianglei's scope correction: PR #1120 made the #728 min-cap branch of
effectiveTokenCountimage-aware (const raw = estimateCoreMessagesUpper(msgs) + inboundImageTokens, all four prepare sites passingimageTokensInParsedBody(...)), but the anonymous prefix-affinity early return still computed its bound text-only:Wire codecs move images out of
CoreMessage.textinto sidecars, so an image-heavy fork replaying its full raw history (client reload / #553 forks on usage-silent upstreams) read a text-only char count: usage % far below reality →decideNudgestructurally unfireable → over-window payload forwarded raw (the #1110 shape, minus the crash).Fix
Hoist
rawabove the early return — exactly as scoped in the issue comment: since a fork replays the FULL raw history in one request, this request'simageTokensInParsedBodyis the whole history's image mass, so one hoist is the complete fix. No call-site changes needed (they already pass the image term with per-protocol billing).Verification
tests/fork-nudge-trigger.test.ts: single anonymous request, window 80k, text-only bound ≈ 58% (below every band — 45% first-sight / 70% host emergency / 75% pressure) + 2 × 10k-token inline images → image-aware bound ≈ 83% ≥ 75% pressure band. Fails pre-fix (no nudge — bug reproduced), passes post-fix (trailing nudge injected, images ride un-folded, preflight silent, all messages survive un-folded). Numbers mirror the proven effectiveTokenCount's text-only raw bound caps away the image term from the nudge numerator (silent-backend sessions) #1119 pin insilent-backend-nudge.test.ts.3c8cc3b+ this commit): typecheck clean, full suite 2216 tests / 2214 pass / 0 fail / 2 skipped (e2e-gated), build green.Fixes #1137