Repository navigation
[PR] fix: price the image sidecar into every size judgment (#3947) - #4016
ranxianglei wants to merge 1 commit into
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.5299-pr.4016.eed5e13This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4016.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复 —— 本 PR 是 #3947 五因中「尺寸判定族」(因 1–3) 的独立修复,与 #3950(因 5,中文措辞解析)及第二 PR(因 4)分属不同失败面;仓库内无同机制在途 PR。 方向审:方案打到根因而非治标 —— 把图片 sidecar 的真实 token 成本纳入所有尺寸判定(计量 / refold / preflight),让图片主导的载荷按线上真实字节定价,而不是只信文本估算。方向正确。 下面是 review 结论(结构化八问)。我已在「PR rebase 到当前 master」的本地树上做了独立验证,不是只看 diff:typecheck 绿、#3769 过、作者点名的 7 个回归套件 55 pass / 0 fail。
阻塞项(合并前必须处理):
结论:代码逻辑正确、口径对齐、配对纪律安全,rebase 后应能全绿;但按当前交付状态不可合 —— 主回归测试缺失。补齐测试 + rebase 后即可走人工合并。(我不会自行 merge。) |
f9406f2 to
9d56adf
Compare
(ai: vllm-qwen/qwen3.8-27b) 冲突已解决:PR 分支已 rebase 到最新 master( 结构化八问
遗留事项(非本次 rebase 引入,维持 floor 4 结论)
判定冲突已清除,PR 技术上可合并;但在缺失的回归测试补齐之前不建议合并(floor 4 的 🔴 阻塞项仍然成立)。合并操作按仓库规则由人工执行。 |
…te (#3947) Image-heavy sessions undercounted the outbound payload by ~19x because every size judgment priced images with the pixels prior while the usage-grade meter anchor dropped the image channel entirely: - effectiveTokenCount: the usage/overflow-arm fast path returned the anchor bare. It now lifts it by (current image reserve - the reserve co-stamped at the anchor round's send chokepoint) only; text-side stays byte-identical (#1839/#1820 ghost discipline). New SessionStats.lastInputImageTokens is stamped in forward()'s send chokepoint (learned ?? prior caliber, same as the prepare lanes) and reset with the anchor at compaction boundaries. - settleRejectionImageLearning: unbilled overflow rejections state the rejected payload's own size ("you requested N tokens"); armOverflowShrink now teaches that into the existing per-route learned store (same EMA/TTL/cap guards as the billing channel). While every forward is rejected this is the only evidence available, so the learned reserve stops underpricing the sidecar. - #1800 arbitration: an overflow-arm below the window IS overflow evidence (the classified rejection itself proved overflow); previously only >= window counted, which left the forward hatch open after every no-window arm (min(declared, defaultCountTokens(rawBody)) sits far below the window for CJK/base64 bodies) and re-opened #488's identical-400 loop. Image-dominated payloads now fold or fail fast locally (deterministic-exhaustion 413) instead of re-forwarding a guaranteed-rejected body forever. Part of #3947 (causes 1-3 of 5; cause 4 rescale gate and cause 5 CJK overflow parsing land separately).
fd7c38c to
290a31b
Compare
|
(ai: zhipuai-lb/glm-5.3) 孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。 |
Part of #3947 — fixes causes 1–3 of the five identified (the meter/size-judgment mechanism family). Cause 4 (rescale admit/refuse gate) lands as a second PR; cause 5 (CJK overflow-window parsing) is reporter's #3950.
What was wrong
An image-dominated session (incident: 7 base64 images, 5.12 MiB wire body, relay cap 1.5M tokens) undercounted its own payload ~19× and re-forwarded the identical body on every retry with no self-heal, because:
effectiveTokenCount's usage/overflow-arm fast path returned the anchor bare, so after one reading the meter froze at the text-side number while images accumulated;settleImageLearninggates onbilledTotal > 0); when every forward is rejected no report ever lands, so the learned reserve stayed at the pixels prior forever;min(declared, defaultCountTokens(rawBody)), far below the window for CJK/base64 bodies), so the PR #489 后续: 默认图片计费 b64/4 在像素 tile 计费上游(官方 Anthropic/OpenAI)会硬 502 误杀多模态会话 #496 forward-anyway hatch re-opened after every rejection → identical-400 loop.The fix
SessionStats.lastInputImageTokensrecords the image reserve (learned ?? prior — the same caliber the prepare lanes feedinboundImageTokens) at the send chokepoint of each round. The fast path now lifts the anchor by(current reserve − anchor-round reserve)only. Text-side stays byte-identical: a text-only or same-image turn returns the raw anchor unchanged (任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839/post-rebuild usage estimate inflates ~3.4x after a big fold, firing an EMERGENCY T1 nudge into an over-budget context #1820 ghost discipline — this exact invariant caused two regressions in an earlier draft that lifted by text estimate).settleRejectionImageLearningconsumes the same one-shot send-chokepoint facts withstatedTotalfrom the rejection body ("you requested N tokens") instead of a bill. Wired intoarmOverflowShrink— the classified-rejection seam. Same store, same EMA/TTL/cap guards, same inconsistency drop (stated < our text estimate ⇒ mis-parse ⇒ dropped). CJK count phrasings start being consumed automatically once [PR] fix(util): parse the window out of CJK context-overflow rejections #3950 extendsparseOverflowCounts.Behavior changes (old → new)
learnedImageCostsstore (previously billing-only). Guarded identically; one-shot pairing prevents double-counting with a later bill.preflight_compress_failed(retryable=false) with the exhaustion detail. Pixel-tile flows without any arm are untouched.Config surface
N/A — no config fields, env vars, or CLI flags added/changed. Reuses existing
imageBillingFor/imageTokenCapForresolution.Tests
tests/issue3947-image-sidecar-meter.test.ts(new): unit pairs pin lift exactness, paired/same-image and pure-text byte-identity (= #1820B ghost-cheap shape), shared EMA store with one-shot cross-channel pairing, and inconsistent/out-of-band sample drops; e2e drives a bytes-billing relay through r1 200 → r2 count-stating 400 (teaches cost, arms) → r3 local 413 with the rejected body forwarded exactly ONCE (loop broken). Verified against the regression surface: issue1820-post-rebuild-anchor, issue3787-overflow-refold, issue1492-stale-estimate-view, issue1839-ghost-denominator, issue1843-learned-image-cost, issue1800-image-arbitration-compress, cache-ledger, e2e-overflow-selfheal + 8 more targeted suites all green locally; full-suite verdict = CI on this head.kernel-change declaration (appended by CI auto-fix worker, 2026-10-23)
kernel-change: sync kernel/package-lock.json version lines to 0.0.160 (lockfile metadata only, no kernel source change)
The only
kernel/diff in this PR is commit efdb214, which syncs the two version lines inkernel/package-lock.json0.0.159 → 0.0.160 — byte-exactly what theCI / lock-syncjob's own regeneration produces. It is required because master commit f7d5e86 (#4292) bumpedkernel/package.jsonwithout regenerating either lockfile, so EVERY merge ref built from that master is red on lock-sync independent of this PR's content. Nokernel/src/**change; kernel-guard rule 2 (version discipline) is unaffected. The identical master-side fix rides separately in #4420 / #4419 / #4416; once one of them merges, this commit becomes redundant in this PR.