Repository navigation
[PR] fix(egress-shed): archive past the 64-image cap so image-dense bodies reach the byte budget - #5754
Conversation
… reach the byte budget
The pre-send egress byte-shed capped its work list at MAX_SHED_IMAGES (64) for BOTH rungs. A session with more than 64 inline history images could therefore never shed enough bytes to get under network.httpOutboundBytes: the body stayed over budget, upstream rejected it (400, no overflow marker), nothing self-healed, and the session retried the identical over-budget body forever ('shed to X MiB but still over budget ... sending anyway').
Rung A (archiving) is a cheap string swap, not a jimp pass, so the per-request CPU bound does not apply to it. Rung A now walks every non-tail occurrence oldest-first until the estimate fits; the 64-image bound stays only on rung B (downscale), where it bounds decode/re-encode CPU. The protected-tail invariant is unchanged (tail is still never archived, only downscaled).
Regression test: tests/issue5745-image-shed-cap.test.ts (fails on the old code with 'archived 64 images', passes here).
Fixes #5745
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8284-pr.5754.fe7c77eThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5754.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 查重: 不重复 —— 在途 [PR] 线程里只有本线程针对 #5745 的图片 shed 上限问题,无并行 PR。 标签: 不打([PR] 镜像线程惯例不打标签;底层缺陷在上游 #5745 已带 bug/p1/zcode/scope/wiring)。 中期状态(代码审完、CI 红灯已定位,结论随后补):
|
[bot] 🏷 最终结论(结构化八问):
收工判定:可以合并。按 §7.4 属人工合并层(出站字节行为变更),请 owner 自行合并:#5754 。备注:我推送时发现分支已被哨兵先行同步 master(non-fast-forward),遂放弃重复 merge、改在新 head 上做验证,未产生多余提交。 |
(ai: vllm-qwen/qwen3.8-27b) CI 修复完成:PR #5754 转绿 @ 七问:
协调留痕:已在 #4599 评论一行(继承红判定 + merge sha)。本轮无 🔶 需要决策项。等 owner 合并。 |
|
(ai: vllm-qwen/qwen3.8-27b) APPROVE — 审的是 PR #5754(head 八问
测试: 不涉 kernel/(无 kernel-change 需求)。diff 收敛到 2 文件、无无关改动,CI 绿。证据基础:静态审读全函数 + 两个调用点 + 关键 helper(decodeImageDims/b64Bytes/refForItemBytes)+ 真实回归测试 + 远端 CI 绿(本地未重跑全量,遵本地测试纪律)。 结论:可合(APPROVE)。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1059-master.078379f # this exact build
npm install -g billion-context@master # always the newest merged build
|
…dentity lane, ranxianglei#5754 image-shed cap, ranxianglei#5689 render-snapshot plane
…ed cap, render-snapshot plane Upstream 2919794..ce8f92e (57 commits) lands three large planes: - ranxianglei#5652 fastpath-v6 identity lane (c295f90 storage layer, d55a50c composite identity, 9c1fb86 full-list wire, da6885d fixed tail window, plus the review follow-ups) - ranxianglei#5754 image-shed 64-item cap (6aed3b8) - ranxianglei#5689 render-snapshot plane (acca4db schema v12, 6d3ca30 O(1) steady turns, 49ba14d seal-shut probe) - ranxianglei#5721 witnessed rebase supplement Overlap with this lane was four files. src/plugin.ts auto-merged (upstream touches the handoff-reply import at :31 and handlePluginTool at :2337; this lane owns the strip entry points at :22 / :61 / :2640..:4554). The two CONFIGURATION files are generated and were regenerated from the seed. One real conflict, in tests/issue4666-migration-dedup.test.ts line 158: upstream re-swept the sqlite user_version pin to the literal 13, this lane had already derived it. Kept the derived form -- that is the whole point of the earlier sweep, and the literal is what goes stale on the next bump. That conflict resolution exposed a latent bug of mine. 3eb22b1 ("pin the mysql lock lane to the CURRENT schema version") derived the mysql stamp assertions from STORAGE_SCHEMA_VERSION as well. When it was written both numbers were 9; ranxianglei#5652/ranxianglei#5689 have since pushed the sqlite unified store to 13 while the MySQL backend stayed at 11, because the v12 identity plane and the v13 render-snapshot plane are sqlite-only. The mysql-contract lane therefore asserted "13" against a migrator that correctly stamps "11". Fixed by exporting MYSQL_SCHEMA_VERSION from src/storage/mysql.ts and pointing the four mysql-side assertions at it; the sqlite assertions keep deriving from STORAGE_SCHEMA_VERSION. Verified String(MYSQL_SCHEMA_VERSION) is "11", i.e. byte-identical to the literal upstream asserts. Verification on the merge tree: issue5175 58/0, tag-echo 79/0, issue2190-degen-close 32/0, golden-storage-render 5/0, storage-engine-proofs 12/0, native-compact-terminal 1/0, plugin-passthrough-tag-strip-chat 20/0, issue4666-migration-dedup 2/0 (the three mysql cases skip without BILI_MYSQL_TEST_DSN; no local MySQL or docker socket in this sandbox). tsc --noEmit clean, all four gates exit 0, generated docs byte-identical.
What & why
A session with more than 64 inline history images on the plain/proxy HTTP relay lane could never be brought under the egress byte budget (
network.httpOutboundBytes, default 10 MiB). The pre-send byte-shed capped its work list atMAX_SHED_IMAGES(64) for both rungs, so once a session had >64 sheddable images the excess bytes were permanently un-removable: the body stayed over budget, upstream rejected it (400 with no overflow marker), nothing self-healed, and the session retried the identical over-budget body every round —shed to X MiB but still over budget … sending anyway.Reported repro (#5745): ZCode / openai wire, 582 images, 39.6 MiB out → shed to 31.4 MiB → permanent 400 loop, session unusable.
Fix
Rung A (archiving an image into a
[image: … omitted]placeholder note) is a cheap string swap — it does not decode/re-encode through jimp — so the per-request CPU bound does not apply to it. Rung A now walks every non-tail occurrence oldest-first until the estimate fits; the 64-image bound stays only on rung B (downscale), where it bounds decode/re-encode CPU. This mirrors what the count-shed sibling (shedWireImagesToCount) already does and documents as intentional ("that bound caps jimp CPU, while archiving is a cheap string swap").The protected-tail invariant is unchanged: the last 8 entries are still never archived, only downscaled. Yielding the tail when even that falls short is a separate design decision (raised on the issue thread), not part of this fix.
Behavior change (intended, disclosed)
read_original_image).Old → new: rung A work list was
occurrences.slice(0, 64)(capped); nowoccurrences(all non-tail, stopping as soon as the estimate fits). Rationale: the cap was applied to a non-CPU-bound action by accident of sharing the variable with rung B.Tests
New
tests/issue5745-image-shed-cap.test.ts:archived > 64andfinalBytes <= budget. Fails on the old code (archived 64 images), passes here — verified by stashing the source fix.Existing shed suites stay green locally (targeted runs):
issue3701-ws-byte-budget+issue3909-http-byte-budget+issue4124-image-count-cap+issue3400-image-rescale(all pass). Full-suite verdict = remote CI. Typecheck clean.Fixes #5745