Skip to content

[PR] fix: include the active size limit in image rescale cache keys - #6086

Closed
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-10_image-rescale-cache-policy
Closed

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-10_image-rescale-cache-policy

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

The ordinary rescaleImage cache uses only base64 content as its key. Reusing an image after maxDim changes returns dimensions from the previous policy; a cached no-op at a larger limit also suppresses required resizing at a smaller limit.

Changes

Include MIME and maxDim with the image content in the ordinary rescale cache key. Same-policy requests still reuse their result. Forced shedding retains its existing independent behavior.

Validation

  • Before: tests/issue3400-image-rescale.test.ts — 23 passed, 3 failed.
  • After: 26 passed, 0 failed, including decoded-dimension and same-policy reuse controls.
  • npm run typecheck — passed.
  • npm run build — passed.
  • Published fork tree 18e8c24304c9af6f8f0c7d70701c82221674f828 exactly matches tested local commit 967971bbe3712ae403dc101cb08e2f8efba4a45f.

The full remote-suite verdict belongs to CI. #3425 introduces preprocessing, #3565 covers settings, and #3706 keys forced shedding by dimension. This fixes the separate ordinary rescale cache, including negative results. All 3,221 historical PRs were screened; independent of #6046–#6055.

Closes #6085

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Verdict: APPROVE. The fix is correct, minimal, and pinned by tests with teeth. Guards (gate/kernel-guard/config-surface-guard/mysql-contract) are green at this head; the test shards were still running when I reviewed, with 0 failures — the full-suite verdict rides on CI.

Correctness. rescaleImage() gates on maxDim before touching the cache (src/image-rescale.ts:151), and doRescale output is fully determined by (mime, maxDim, content) — the encode format follows the declared mime (src/image-rescale.ts:122-124). The new key sha256(${mime}:${maxDim}:${b64}) (src/image-rescale.ts:153) covers exactly those inputs. Negative results (low-benefit skip → null) are cached per policy too, which is what makes the BMP 1600→800 sequence work: a null at one limit no longer poisons another.

Teeth. At this head the file passes 26/26 locally; swapping master's src/image-rescale.ts back in fails exactly the 3 new tests (23p/3f) — they reproduce the reported bug, not just the happy path. Both directions of the gate are asserted (same policy → cache hit + log once; different dim → re-encode + log again), per the negative-assertion discipline (#3617).

Regression audit (existing behaviors on the touched paths):

  • Same-policy reuse (the #3400 feature): preserved — identical (mime, maxDim, content) still encodes once; log-once retained (pre-existing "hash cache" test unchanged, passing).
  • Cross-limit behavior: INTENDED change, already disclosed in the PR body. Old: the first (mime, maxDim) pair seen per process lifetime won for that content forever. New: each active limit gets its own entry, so a mid-process BILI_IMAGE_RESCALE_MAX_DIM change takes effect at next egress instead of pinning until restart. Key old→new: sha256(b64) → sha256(${mime}:${maxDim}:${b64}); reason: the old key was the reported bug (#6085).
  • Forced-shed path (shedDownscaleImage): untouched by this diff; verified byte-identical.
  • Cache cap (512 entries, src/image-rescale.ts:48) and eviction mechanism: unchanged; key space grows by distinct (mime, maxDim) pairs, bounded by the cap.
  • Wire shape: unchanged — same block fields; only the encoded payload differs when the active limit differs.
  • Byte-stability within a fixed policy: preserved ("byte-stable" test passing).
  • Config surface / persistence / kernel/: none touched.

Finding from this review (non-blocking; pre-existing on master, NOT introduced here). shedDownscaleImage() keys its encode cache on sha256(${dim}:${b64}) (src/image-rescale.ts:186) without the mime, while its output format follows the declared mime — identical bytes under two declared mimes both through forced shedding would serve the first mime's bytes under the second's wire label. Same mechanism family as this PR, independent defect. Trigger is narrow (identical bytes + two declared mimes + both shed within one process lifetime), so p3-class. The author's fork has maintainer edits disabled, so I could not land it on this branch; per house tiny-fix discipline it ships separately: issue #6108 ([no-dispatch] recording, labeled bug/scope-wiring/p3) + fix PR #6109 (key gains the mime; new regression test fails without the change, file 24/24 with it). Merge order relative to this PR is irrelevant — no textual overlap.

One factual observation for the author, no action demanded: with the new key, the doc comment above rescaleImage ("Cached per content hash…") and the cap comment ("unique images per process") now understate what the key covers.

Clean diff (2 files, every line on-purpose), references its issue, single-module scoped pure fix — meets the §7.4 auto-merge gate criteria; merge decision stays human.


中文八问:

  1. 是什么问题:图像重缩放缓存键只含内容 hash——同一张图在进程生命周期内被第一个遇到的 size limit 策略钉死,之后改 limit、或同内容图在不同 limit 下先后出现时,都会拿到旧策略的编码结果(包括旧的 null 结果)。
  2. 什么原因导致的:缓存键设计漏掉了两个决定输出的输入——声明的 mime 与当前生效的 maxDim(doRescale 的输出完全由这三者决定,编码格式还跟着声明的 mime 走)。
  3. 影响范围与严重程度:所有开启 BILI_IMAGE_RESCALE 的会话;触发条件=进程内 size limit 变化(env/config 改动)或同内容图跨 limit 出现。后果是发出错误尺寸的图(体验/成本瑕疵),不丢数据、无安全问题 → 特定条件下有问题,p2-p3。
  4. 怎么修复的:缓存键从 sha256(b64) 扩为 sha256(mime:maxDim:b64),让键覆盖全部输出决定因素;负结果(null)同样按策略缓存,不再跨策略污染。
  5. 是否有回归问题:逐项审过——同策略复用保持(编码一次+日志一次)、跨策略为有意变更(正文已披露旧值→新值+原因)、shed 路径未触碰、缓存上限 512 机制不变、wire 形状不变、固定策略内字节稳定性保持。无意回归:无。
  6. 是否破坏缓存:上游前缀缓存不受影响(仅图片 payload 数据可能变化);本模块自身 encode 缓存行为按第 5 条逐项核对过。
  7. 是否改了设计方向:不改——仍是进程级 encode 缓存,只是键的定义修正为与输出一致。
  8. 是否引入了新的配置:无。

判定:可合并(APPROVE)。审查中发现的 shed 路径同类缺陷已独立立项(#6108)+修复 PR(#6109),不属于本 PR 范围。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete: APPROVE posted on PR #6086 → #6086 (review) (full English justification + 八问 in the review body).

Verified (targeted local runs):

  • Mechanism correct: gate on maxDim precedes the cache (src/image-rescale.ts:151); output fully determined by (mime, maxDim, content) with encode format following declared mime (src/image-rescale.ts:122-124); new key sha256(${mime}:${maxDim}:${b64}) covers exactly those inputs; null results cached per policy too.
  • Teeth: file 26/26 at PR head; master's src/image-rescale.ts swapped back fails exactly the 3 new tests (23p/3f) — matches the PR's claim; both gate directions asserted. egress-shed suites 22/22; typecheck clean.
  • Regression audit: same-policy reuse + log-once preserved; cross-limit change = intended disclosed drift (old→new key stated in review); shed path untouched by this diff; cache cap 512 unchanged; wire shape unchanged; byte-stability within policy preserved; no config/kernel touch. Meets §7.4 auto-merge criteria — merge stays human.
  • CI: guards green (gate/kernel-guard/config-surface-guard/mysql-contract), test shards still running at review time, 0 failures — full-suite verdict rides on CI.

Review finding (non-blocking, pre-existing on master, NOT introduced by this PR): shedDownscaleImage() keys its encode cache without the declared mime (src/image-rescale.ts:186) — identical bytes under two declared mimes through forced shedding would serve the first mime's bytes under the second's wire label (p3-class, narrow trigger). Author's fork has maintainer edits disabled, so it could not be fixed on this branch; shipped separately per house tiny-fix discipline:

Coordination one-liner posted on #4599. No open ends: the finding ends FIXED-in-separate-PR (receipt above), nothing parked.


中文八问(精简版):

  1. 是什么问题:图像重缩放缓存键只含内容 hash,同一张图被进程内第一个遇到的 size limit 策略钉死,之后改 limit 或跨 limit 出现都拿到旧策略结果。
  2. 什么原因导致的:缓存键漏掉两个输出决定因素——声明的 mime 与当前生效的 maxDim。
  3. 影响范围与严重程度:所有开启 BILI_IMAGE_RESCALE 的会话;触发=进程内 limit 变化或同内容跨 limit;后果为发出错误尺寸的图,不丢数据、无安全问题(p2-p3)。
  4. 怎么修复的:缓存键扩为 sha256(mime:maxDim:b64),负结果按策略缓存。
  5. 是否有回归问题:逐项审过,无意回归无;跨策略行为为已披露的有意变更。
  6. 是否破坏缓存:上游前缀缓存不受影响;本模块缓存逐项核对过。
  7. 是否改了设计方向:不改,仅修正键定义与输出一致。
  8. 是否引入了新的配置:无。

收工判定:PR #6086 可合并(APPROVE 已提交);审查中发现的 shed 路径同类缺陷经 #6108/#6109 独立闭环,无遗留。

@ranxianglei

Copy link
Copy Markdown
Owner

Landed via batch PR #6439 (merged) — closing as superseded.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Acknowledged. Verified on current master: the #6086 fix is in via batch #6439 — src/image-rescale.ts:153 now keys on sha256(${mime}:${maxDim}:${b64}).

Status of the follow-up from my review (independent, pre-existing defect on the forced-shed path):

Nothing else pending on this thread.

@ranxianglei ranxianglei reopened this Nov 14, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 重复 — 本 PR 的改动已经合入 master,PR 本身是空操作/重复项,建议关闭。

I reviewed PR #6086 ("include the active size limit in image rescale cache keys"). The finding: the exact change this PR proposes is already in master, so the PR is a complete duplicate of already-merged work.

Evidence

  1. The PR's own commit 4bead210c6 ("fix: scope image encodes to their resize policy") changes exactly two files:
    • src/image-rescale.ts:153 — rescale cache key b64 → `${mime}:${maxDim}:${b64}`
    • tests/issue3400-image-rescale.test.ts — +25 lines (3 new tests)
  2. That commit was cherry-picked into master as 2480d88d00 — its message literally reads "(cherry picked from commit 4bead21)" — and merged through PR [PR] chore(batch): land 50 open Afloat16 fixes in one history-preserving batch #6439 (ranxianglei/afloat-dry, "land 50 open Afloat16 fixes in one history-preserving batch"). git merge-base --is-ancestor 2480d88d00 HEAD → yes, it's in current master.
  3. git diff HEAD 4bead210c6 -- src/image-rescale.ts tests/issue3400-image-rescale.test.ts → empty. Both files are byte-identical between master and the PR head.
  4. I built the current master tree and ran the targeted suite: tests/issue3400-image-rescale.test.ts → 26 passed, 0 failed. The 3 tests this PR adds are already present in master and green.

The PR head (4bead210c6) sits on a stale base (merge-base 541cf260c4, ~5 days behind), so GitHub reports it behind; merging it would be a no-op at best or a conflict at worst.

The fix itself is correct — scoping the rescale cache key by normalized MIME + maxDim is the right call: same-policy requests still reuse their result, a changed maxDim now re-encodes instead of returning the stale dimensions, and a cached low-benefit no-op no longer suppresses a later stricter resize. It just doesn't need to land again — it already did, via #6439.

Recommendation: close PR #6086 as a duplicate of the already-merged #6439 cherry-pick. Per policy I won't close or relabel the source PR myself — flagging for the owner.


结构化八问

  1. 是什么问题:PR [PR] fix: include the active size limit in image rescale cache keys #6086 要修的是「普通 rescaleImage 缓存键只用了 base64 内容,maxDim 变化后会返回旧策略结果 / 大 limit 下缓存的 no-op 会压制小 limit 下必需的降采样」;审核结论是这份修复已经通过 cherry-pick 合入 master,PR 是重复项。
  2. 什么原因导致的:同一份改动被 cherry-pick 到更新的 base 上、经批量 PR [PR] chore(batch): land 50 open Afloat16 fixes in one history-preserving batch #6439 合入 master;而 PR [PR] fix: include the active size limit in image rescale cache keys #6086 的 base 停留在旧 master,所以两边是同一份 diff、PR 成了遗留空操作。
  3. 影响范围与严重程度:无新增影响——修复已在 master 生效。原始 bug 属「maxDim 会话中途变化」的窄边界(体验瑕疵/特定条件),现已修复。PR 本身若合入是空操作或冲突。
  4. 怎么修复的:(PR 的修法本身正确)把规范化 MIME + maxDim 纳入缓存键,使不同策略各自独立缓存;但无需再合,master 已有。
  5. 是否有回归问题:无——master 现有代码已含此修复,目标套件 26/26 通过;本 PR 不引入任何新变更。
  6. 是否破坏缓存:不破坏——这正是该修复要解决的缓存键问题,master 已修好;同策略复用、异策略重编码的行为都正确。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

判定:PR #6086 为已合入 master 的重复项(#6439 cherry-pick),建议 owner 关闭,不予合并。

ranxianglei pushed a commit that referenced this pull request Nov 18, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image rescale cache reuses results from a different size limit

2 participants