Skip to content

[PR] fix: include the declared mime in the shed image-downscale cache key - #6109

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-10_shed-mime-cache-key
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-10_shed-mime-cache-key

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #6108

来源: PR #6086 分析 image rescale cache key 问题时发现(shedDownscaleImage 缓存键缺 mime —— 与 #6086 所修 rescaleImage 缺 size limit 同机制家族的独立既有缺陷,master 上已存在,非本仓库在途工作引入)

What

src/image-rescale.ts shedDownscaleImage(): encode-cache key sha256(${dim}:${b64}) → sha256(${mime}:${dim}:${b64}).

doRescale() encodes in the declared mime's format (image-rescale.ts:122-124), so the key must cover the mime. Without it, identical bytes under two declared mimes both through forced shedding collide: the second caller gets the first mime's bytes under the second mime's wire label.

Evidence

  • New regression test tests/issue3400-image-rescale.test.ts "shed encode cache respects the declared mime": fails on unpatched code (verified by reverting the key line), passes with it.
  • Full file at this head: 24/24 pass; typecheck clean.
  • Same-class sibling: PR [PR] fix: include the active size limit in image rescale cache keys #6086 (rescaleImage key gains mime + maxDim) — independent defect, no textual overlap with this diff; merge order irrelevant.

Scope: one key line + doc comment in src/image-rescale.ts, one test added. No config surface, no wire-shape change (only serves correctly-labeled bytes), no kernel/ touch.

@ranxianglei ranxianglei changed the title fix: include the declared mime in the shed image-downscale cache key [PR] fix: include the declared mime in the shed image-downscale cache key Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-10_shed-mime-cache-key (17e7bd0)

Latest build — install this exact version

npm install -g billion-context@0.0.10786-pr.6109.2561afa

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
17e7bd0 billion-context@0.0.10786-pr.6109.2561afa build
c985b83 billion-context@0.0.8900-pr.6109.60ea5b7 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6109.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复. #6109 是 #6108 的唯一修复 PR(open+closed 全量检索 shedDownscaleImage / "6108"+type:pr:仅本 PR、#6086、已关闭的 #3706(原始 byte-shed 实现))。同机制家族的兄弟项 #6086(rescaleImage 键缺 mime+maxDim)是独立缺陷、不同函数、无文本重叠——PR body 已如实声明,不构成重复立项;本线程也没有第二个并行修复 PR。分支落后 master 0 个提交。

Live state (verified just now): PR open, mergeable=true, mergeStateStatus=blocked(仅因 CI 未完成);static-gates / build-artifact / gate / mysql-contract 已绿,test shards 仍在跑。

Local targeted verification at head c985b83:

  • tests/issue3400-image-rescale.test.ts: 24/24 pass;npm run typecheck clean — both claims in the PR body reproduce.
  • Test has teeth: reverting the key line to `${dim}:${b64}` makes "shed encode cache respects the declared mime" fail with its exact assertion; restored clean afterwards.
  • Mechanism confirmed at source: doRescale() decodes via Jimp.read (auto-detects real format from bytes, src/image-rescale.ts:112) but encodes in the DECLARED mime's format (src/image-rescale.ts:122-124). So under the old key, identical bytes under two declared mimes through forced shedding collide and the second caller gets the first mime's bytes under its own wire label. The fix moves the key to cover the deciding input (${mime}:${dim}:${b64}) at the decision point — right layer, not a mask. No field ambiguity: mime is a fixed 3-value set, b64 alphabet has no :.
  • Sole caller is egress-shed rung B (src/egress-shed.ts:314), which passes the wire-declared mediaType — consistent with the fix.
  • Regression surface: outbound bytes change ONLY in the collision case (which was the bug); same-bytes-same-label traffic stays byte-identical, so upstream prefix-cache stability (Egress image downscale: shrink big images before sending to the model, originals stay local and self-readable | 重做图片降采样(简化版):发模型前压大图、原图留本地不动、模型被告知尺寸后可自读原图 #3400 determinism contract) is untouched. Cache cap (512) and eviction order unchanged; process-local keys don't cross into any persisted or wire-visible surface. No config surface, no kernel/ touch.
  • Family-completeness note: after this merges, rescaleImage's key (src/image-rescale.ts:153) still omits mime+maxDim until [PR] fix: include the active size limit in image rescale cache keys #6086 lands — same family, separate defect, merge order irrelevant as stated. Both should merge for full coverage of the family.

标签: bug + scope/wiring + p3(缺陷类;出站协议边界上的缓存键缺陷;触发条件极窄——同一字节序列以两种声明 mime 同时走强制 shed 降采样,后果限于该次出站副本,存储原件不受影响)。

Final structured verdict (八问) follows once the CI test lanes finish — currently in progress.

@ranxianglei ranxianglei added bug Something isn't working p3 scope/wiring labels Nov 10, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI verdict — now fully green on head c985b83. The single failed shard test (windows-latest, 22, 3) was re-run and passed (job ran 07:58–08:05Z, same head sha). All required checks are green: 13/13 test shards + all static gates/guards. Live PR state: open, head unchanged (c985b83, single commit, 2 files), base advanced to master 4dea18e, mergeable=true, mergeStateStatus=blocked solely by the required-review gate (human-only merge per repo policy).

Why the one failure was not this diff. The original red was a single subtest out of 2058 in that shard — #5152 one worker per origin: repeated attach paths share, refcounted stop (tests/issue5152-owner-beat-survives-host-stall.test.ts:182, a beat-rate timing assertion, "4.0/s", 8.9s duration) — with zero overlap with a cache-key change in src/image-rescale.ts. Corroborating pattern from concurrent fleet runs today: two other heads failed different unrelated timing-sensitive subtests on different shards (win22-2: "abort x proxy-openai-sse: client abort mid-stream destroys the upstream request"; ub24-2: "successive rotations retain distinct payloads without overwriting") while our win22-3 subtest passed everywhere else it ran. That is runner-load flake behavior under heavy parallel execution, not an inherited master red (master's own issue5152 test file is unchanged since our base; the only attach-heartbeat.ts delta since base is the unrelated noteColdLoad invalid-savedAt handling from #6043). Nothing to fix inside this PR; if #5152 keeps flapping across unrelated heads on Windows node 22, that belongs in the CI master-control thread (#4599 — noting its last activity is 2026-10-24, so the sentinel may be dormant).

Code verdict (from my earlier pass, unchanged): fix correct, ship-ready.

  • Mechanism confirmed at source: doRescale() decodes via Jimp auto-detect but encodes in the declared mime's format (src/image-rescale.ts:122-124), so the encode-cache key must cover the mime; old key ${dim}:${b64} let identical bytes under two declared mimes collide, handing the second caller the first mime's bytes under its own wire label. Fixing the key at the decision point is the right layer, not a downstream mask.
  • Regression test has teeth: reverting just the key line makes the new test fail on its exact assertion; 24/24 file pass at this head; typecheck clean.
  • Clean minimal diff (one key line + doc comment + one test); no config surface, no wire-shape change (only serves correctly-labeled bytes), no kernel/ touch. §7.4 auto-merge profile met on every bullet — merge itself stays yours.
  • Footnote (pre-existing, out of scope): master branch protection lists test (windows-latest, 24, *) contexts the matrix never produces — stale required-context list, merges proceed via admin bypass (enforce_admins=false). Hygiene nit for whenever you touch protection rules.
  • Sibling [PR] fix: include the active size limit in image rescale cache keys #6086 (rescaleImage key missing mime+maxDim) remains open independently; merge order irrelevant, family complete only when both land.

八问(中文结构化结论)

  1. 是什么问题:shedDownscaleImage() 的编码缓存键只覆盖 (dim, b64),不含 mime —— 同一份图片字节以两种不同声明 mime 都走强制 shed 降采样时发生键碰撞,第二个请求拿到的是按第一个 mime 格式编码的字节、却挂着第二个 mime 的线上标签。
  2. 什么原因导致的:doRescale() 用声明的 mime 决定编码格式(image-rescale.ts:122-124),但缓存键没有覆盖这个编码维度——键的定义与编码决策脱节,属既有缺陷(非在途工作引入)。
  3. 影响范围与严重程度:触发条件窄(同字节 + 两种声明 mime + 均走强制 shed 降采样);后果限于该次出站副本标签与格式不符(Jimp 解码靠真实字节自动识别,故是错标而非数据损坏);会话存储原件不受影响。p3。
  4. 怎么修复的:缓存键加入 mime → sha256(${mime}:${dim}:${b64}),在决策点修根因;mime 为固定集合且 b64 字母表无分隔符歧义。
  5. 是否有回归问题:逐项审过既有行为——同字节同标签场景输出与改前逐字节一致(前缀缓存稳定不受扰);ENCODE_CACHE_MAX=512 与逐出顺序不变;键为进程内局部、从不落盘不上线;无配置面变化;未触碰 kernel/。无回归。
  6. 是否破坏缓存:有意的一次性失效——升级后旧键作废,每个 (mime,dim,content) 重编码一次;纯进程内 map,不涉及跨进程/持久化缓存策略。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

收工判定:CI 全绿、代码审毕、可合——等你的 review approval 即可合并。

doRescale encodes in the declared mime's format, so the encode-cache key
must cover it; identical bytes under two declared mimes otherwise collide
and the second caller receives the first mime's bytes under the wrong
wire label. Same mechanism family as PR #6086 (rescaleImage key gains
mime+maxDim); this is the pre-existing gap on the forced-shed path.
@ranxianglei
ranxianglei force-pushed the 2026-11-10_shed-mime-cache-key branch from c985b83 to 17e7bd0 Compare November 18, 2026 09:23
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Conflict resolved and pushed. The PR was dirty because it is a single commit on an old base (4dea18e) while master advanced 863 commits. Both sides touched shedDownscaleImage() in src/image-rescale.ts — this PR changed the encode-cache key (added mime), master refactored the encode cache (EncodeCacheEntry / cacheEncode / byte budget). I rebased onto current master (548e396022), resolved the one conflict as the union of both intents, and force-pushed the rebased single commit 17e7bd0d96. The branch is now 1 ahead / 0 behind master. This is the final head (no [ework:ci-held] marker), so CI runs its one full pass on it.

七问(CI 冲突处理)

  1. 是什么问题:本 PR(2026-11-10_shed-mime-cache-key)与 base 分支冲突(merge state: dirty),需解决冲突使其可合并。
  2. 什么原因导致的:PR 是旧 base(4dea18e)上的单提交,master 已前进 863 提交;shedDownscaleImage() 被两边同时改动——本 PR 改缓存键(加 mime),master 重构 encode 缓存(引入 EncodeCacheEntry/cacheEncode/字节预算),同函数体内相邻行相撞。
  3. 怎么处理的:rebase 到当前 master(548e396022),冲突点取两边意图的并集——保留本 PR「键含 mime」(${mime}:${dim}:${b64}) + 采用 master「encodeCache.get(hash)?.pending 新缓存 API」,if 块用 master 的 cacheEncode(...)。
  4. 解决了哪些冲突:src/image-rescale.ts 一处(shedDownscaleImage 的 hash 行 + pending 行);tests/issue3400-image-rescale.test.ts 自动合并成功(两边加在不同区域:本 PR 加 mime 测试 + import,master 加 dimension-limit / low-benefit 测试)。
  5. 是否有回归问题:无。解法是两边正交改动的并集,互不干扰;rescaleImage 的键(${mime}:${maxDim}:${b64},master 已改)、clearRescaleEncodeCache 字节预算、refForItemBytes 候选匹配(master 已改)均未被本 PR 触碰。本 PR 只改 shedDownscaleImage 的键 + 文档注释 + 一个测试。
  6. 本地验证结果:typecheck 干净(exit 0);tests/issue3400-image-rescale.test.ts 27/27 通过;teeth 检查——把键改回旧值(无 mime)后 mime 测试确实失败(not ok 5),恢复后通过,证明测试在新 base 上仍有牙。
  7. 当前状态 / 收工判定:已 force-push rebase 后的单提交 17e7bd0d96;分支领先 master 1、落后 0,冲突已清。这是本分支最终 head(无 [ework:ci-held]),CI 将在新 head 跑一次全量。等 CI 绿 + owner review 即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

APPROVE — reviewed end-to-end; verified both directions of the regression test locally.

Fix is correct and root-cause. shedDownscaleImage() keyed its encode cache on dim+content only, but doRescale() encodes in the declared mime's format (src/image-rescale.ts:170-172). Identical bytes under two declared mimes, both through forced byte-shed, collided on one entry: the second caller got the first mime's encoded bytes under the second mime's wire label. Keying on the normalized mime (sha256(\${mime}:${dim}:${b64}`)) fixes it at the source and matches the sibling rescaleImage() key (src/image-rescale.ts:201), which already carried the mime. image/jpg/image/jpeg` normalize to the same value and encode identically, so the key neither collides nor spuriously misses.

No other instance of the gap. The only other cache key in the module (rescaleImage) already includes the mime; the receipt digest (src/image-rescale.ts:334) is intentionally content-only.

Regression test has teeth (verified both ways). tests/issue3400-image-rescale.test.ts:128 — I reverted the key line locally and the test fails exactly as the PR claims (second call serves the first mime's PNG bytes under the jpeg label, notStrictEqual trips). With the fix the file is 27/27. It correctly relies on the in-test cache persisting (the beforeEach clears only before the test), which is precisely the collision window.

Risk. No config surface, no wire-shape change (only serves correctly-labeled bytes), no kernel/ touch, no persistence. Cache footprint grows by at most one entry per distinct mime (png/jpeg/bmp) — bounded, negligible. PR is fresh (base = current master 548e396), mergeable, CI green (0 failed).


8问(中文)

  1. 是什么问题:shedDownscaleImage 的编码缓存键只含 dim+内容、漏了声明的 mime,但 doRescale 按声明 mime 的格式编码——同字节、不同 mime 两次强制 shed 撞进同一缓存条目,第二个调用方拿到第一个 mime 的编码字节、却挂第二个 mime 的线标签。
  2. 什么原因导致的:缓存键漏掉了决定输出格式的变量(mime)。根因是键不完整,属"疏",在键的源头修,不在传输层过滤。
  3. 影响范围与严重程度:触发面窄(同字节 + 不同声明 mime + 都走强制 shed,同一进程生命周期内);后果是线级 mime/字节不匹配,上游可能解码失败或误读图像。严重度低(p3),无数据丢失、无安全暴露;master 既有,非本 PR 引入。
  4. 怎么修复的:把归一化后的 mime 加进缓存键(sha256(\${mime}:${dim}:${b64}`)),与已含 mime 的兄弟函数 rescaleImage` 对齐。
  5. 是否有回归问题:审过模块内全部缓存键——rescaleImage 本就含 mime、无问题;回执哈希本就只按内容匹配、无问题。非碰撞路径(同字节同 mime)键不变、仍命中;碰撞路径从"错误命中"变"正确落空重编码",正是修复目标。无 fail-fast 变吞错、无阈值/时序/输出格式漂移。
  6. 是否破坏缓存:进程内内存缓存,键格式变化不影响任何持久化/重试/游标/去重键;仅碰撞场景多一次(本就该做的)编码。
  7. 是否改了设计方向:否。单模块单行键修复 + 注释 + 一个回归测试,无架构/边界/数据流转向。
  8. 是否引入了新的配置:否。无新 env/config/默认值。

判定:可合(§7.4 auto-merge 全过;未触 kernel/,无需人工决策层)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of PR #6109 — verdict: APPROVE.

Reviewed end-to-end and verified the regression test both directions locally (not just read the diff):

  • Fix is correct & root-cause. doRescale() encodes in the declared mime's format (src/image-rescale.ts:170-172), so the encode-cache key must cover the mime. The one-line key change ${dim}:${b64} → ${mime}:${dim}:${b64} (PR head :232) fixes it at the source, matching the sibling rescaleImage() key (:201) which already carried the mime. image/jpg/image/jpeg normalize identically → no collision, no spurious miss.
  • No other instance of the gap in the module (the receipt digest at :334 is intentionally content-only).
  • Regression test has teeth (verified both ways). Reverted the key line → the new test (tests/issue3400-image-rescale.test.ts:128) fails exactly as the PR claims (second call serves the first mime's PNG bytes under the jpeg label, notStrictEqual trips); with the fix the file is 27/27. It correctly relies on the in-test cache persisting (beforeEach clears only before the test) — precisely the collision window.
  • No small findings to fix. No kernel/ touch, no kernel-change declaration → no human-decision gate, no needs-decision label.
  • Risk: no config surface, no wire-shape change (only serves correctly-labeled bytes), no persistence. Cache footprint grows ≤1 entry per distinct mime (bounded, negligible). PR is fresh (base = current master 548e396), mergeable, CI green (0 failed).

Full review (justification + 8问) is on the PR: #6109 (comment)


8问(中文)

  1. 是什么问题:shedDownscaleImage 的编码缓存键只含 dim+内容、漏了声明的 mime,但 doRescale 按声明 mime 的格式编码——同字节、不同 mime 两次强制 shed 撞进同一缓存条目,第二个调用方拿到第一个 mime 的编码字节、却挂第二个 mime 的线标签。
  2. 什么原因导致的:缓存键漏掉了决定输出格式的变量(mime)。根因是键不完整,属"疏",在键的源头修,不在传输层过滤。
  3. 影响范围与严重程度:触发面窄(同字节 + 不同声明 mime + 都走强制 shed,同一进程生命周期内);后果是线级 mime/字节不匹配,上游可能解码失败或误读图像。严重度低(p3),无数据丢失、无安全暴露;master 既有,非本 PR 引入。
  4. 怎么修复的:把归一化后的 mime 加进缓存键(sha256(${mime}:${dim}:${b64})),与已含 mime 的兄弟函数 rescaleImage 对齐。
  5. 是否有回归问题:审过模块内全部缓存键——rescaleImage 本就含 mime、无问题;回执哈希本就只按内容匹配、无问题。非碰撞路径(同字节同 mime)键不变、仍命中;碰撞路径从"错误命中"变"正确落空重编码",正是修复目标。无 fail-fast 变吞错、无阈值/时序/输出格式漂移。
  6. 是否破坏缓存:进程内内存缓存,键格式变化不影响任何持久化/重试/游标/去重键;仅碰撞场景多一次(本就该做的)编码。
  7. 是否改了设计方向:否。单模块单行键修复 + 注释 + 一个回归测试,无架构/边界/数据流转向。
  8. 是否引入了新的配置:否。无新 env/config/默认值。

判定:可合(§7.4 auto-merge 全过;未触 kernel/,无需人工决策层)。

遗留一项(非 PR 问题):评审车道要求的"协调 issue 一行汇报"未能发出——该协调 issue 不是 GitHub issue(open+closed 检索无匹配),其编号在本环境无法解析。PR 本身的评审与结论已全部完成。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p3 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shed image-downscale cache key omits the declared mime — same bytes under two mimes collide and serve the first mime's bytes

1 participant