Skip to content

[PR] fix: image recovery — one ref per split image, DSH attachments recoverable (root-cause: image-recovery-spill) - #6902

Open
ranxianglei wants to merge 4 commits into
masterfrom
2026-11-16_image-recovery-spill
Open

ranxianglei wants to merge 4 commits into
masterfrom
2026-11-16_image-recovery-spill

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Root cause: image-recovery-spill

One root cause, two facets — bili's image-media recovery path either
over-recovers (restores sibling images it was never asked for, spilling
quadratic files) or under-recovers (treats a durable, re-fetchable image
handle as unrecoverable and pins the message forever). This PR fixes both so a
single image ref recovers exactly its own image, and a DSH attachment stops
being permanently pinned.

Facet 1 — #6851: Responses split image refs restore sibling images + quadratic spill files

A multi-image Responses user item is split into one core image per ref, but
each split image's rawResponsesItem still carries the FULL original item.
The host recovery index (src/image-restore.ts) then bound every split ref to
every image in that carrier: for N images, N × N spill files, and
decompressing one ref restored all N siblings (cross-image contamination).

Facet 2 — #6875: DSH read_image/screenshot attachment permanently BLOCKED

A DSH read_image/screenshot tool result carries its image as
{type:"image", attachment:{attachmentId}} in the content array. The codec
(openaiToCore) reduced tool results to text only, so the attachment never
reached CoreMessage and extractMediaRefs could never see it — the message
looked like plain text while its media was invisible. The classifier then
pinned it as unrecoverable media (BLOCKED) and it could never fold. The
reporter's session had 836 such stale BLOCKED rows (~160K tokens) that never
migrated.

Fix

Both commits cherry-picked with -x (authorship preserved).

Verification

kernel-change: recognize DSH attachment refs as recoverable media (#6875) —
the codec preserves attachment-carrying image parts on tool results into the
rawOpenaiContentParts sidecar, extractMediaRefs enumerates the
attachmentId as a durable handle, and coreToOpenai re-emits them; message
ID unchanged (ref stability).

Fixes #6851
Fixes #6875

@ranxianglei ranxianglei added bug Something isn't working p1 root-cause labels Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-16_image-recovery-spill (201bc88)

Latest build — install this exact version

npm install -g billion-context@0.0.11019-pr.6902.51330ce

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
201bc88 billion-context@0.0.11019-pr.6902.51330ce build
0bf0e24 billion-context@0.0.10371-pr.6902.8e13d57 build
e907528 billion-context@0.0.10350-pr.6902.3f86b4b build
ae77b9d billion-context@0.0.10337-pr.6902.2add84d build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: image recovery — one ref per split image, DSH attachments recoverable (root-cause: image-recovery-spill) [PR] fix: image recovery — one ref per split image, DSH attachments recoverable (root-cause: image-recovery-spill) Nov 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 本 PR 是 image-recovery-spill 根因家族的指定唯一聚合 PR(#6894,rcagg:image-recovery-spill 标记),合并 #6851 + #6875。镜像 [PR] 行清单中无其他 PR 指向本线程;相关的仅两个 cherry-pick 源 PR(#6854、#6879),本 PR 合并后它们变为冗余(owner 关闭,agent 不关)。

Review of the aggregation PR — GitHub #6902, head e90752841f.

Cherry-pick fidelity (verified, not taken on faith). git patch-id --stable confirms both commits are byte-identical applications of the reviewed source PRs onto current master (de895aa88c):

Head e90752841f is an empty CI re-trigger commit (identical tree bc8b0b6b…, the concurrency group had cancelled the opened wave before jobs started) — no code changed since my verification.

Facet 1 (#6851, host) — verified. The bug is real: the Responses codec (kernel/src/wire/responses.ts) splits a multi-image user item into one core per image, but each split image core still carries the WHOLE original item as rawResponsesItem, and the host recovery index (src/image-restore.ts messageImageBytes) bound every split ref to every image in that carrier — N×N spill files, and decompressing one ref restored all N siblings. The fix gates on mm.imagePart === true (set only on split image cores): return only its own sidecar (remote-only → []); unsplit carriers and tool outputs keep the full-carrier walk. Scope check: rawResponsesItem is set ONLY by the Responses codec (5 sites) — no cross-wire impact (anthropic/openai/google cores lack it). Tests are strong: 20 images → exactly 20 spill files (not 400), a split ref restores its own pixels only (receipt text must not name a sibling path), remote-only refs carry no pixels, unsplit carriers keep both images under one ref.

Facet 2 (#6875, kernel) — verified. The bug is real (the reporter confirmed the codec-layer direction in #6875: 「之前一直以为问题在 hasUnrecoverableMediaPayload 那一层,方向错了」): DSH read_image/screenshot tool results carry {type:"image", attachment:{attachmentId}} on the wire; openaiToCore reduced tool results to text only, so the attachment never reached CoreMessage, extractMediaRefs never saw it, and the classifier pinned the message as unrecoverable media (BLOCKED) — the reporter's 836 stale rows (~160K tokens) never migrated. The fix lands all three parts together (per the #6875-trap rule — a sidecar without enumeration would newly pin):

  1. openaiToCore preserves ONLY attachment-carrying image parts into the rawOpenaiContentParts sidecar (isDshAttachmentPart: type image + attachment object + non-empty string attachmentId);
  2. extractMediaRefs enumerates the attachmentId as a durable content-addressed handle (bare id, parallel to a DeepSeek file_id; the pushRef guards apply — non-empty, not data:, not ephemeral);
  3. coreToOpenai re-emits the parts (text-only results keep the legacy string shape byte-identically).

Message-ID stability verified: the tool core id is deriveCanonicalMessageId("tool","tool-result", stringContent(m.content), {toolName}) — stringContent is unchanged, so ids are stable across the upgrade (ref stability holds). Stale BLOCKED migration fires via the existing #2607 mechanism (tested: BLOCKED → fresh numeric ref, never reused).

Local verification (all on the PR head): typecheck clean, build clean; 42 host (image-restore + fix-1205) + 13 kernel (issue6875-*) + 91 kernel (issue5620 + issue3939-* + protected-*) + 35 verif guards (openai.ts is a Tier-A guarded file: verif-subset-guard + wire-stability + roundtrip suites) = 181 pass, 0 fail (a superset of the PR's claimed 124).

CI: the wave on ae77b9d170 was fully green (27/28 jobs success, 1 skipped by design = red-signal watchdog; the "22 cancelled" runs were the duplicate wave the concurrency group reaped — hence the empty re-trigger). The new wave on e90752841f is queued (cache 09:07Z: 14 test shards queued, 0 failed); the tree is byte-identical, so the green verdict carries over.

Existing-behavior audit (regression review):

One open risk (not resolvable from this environment): upstream acceptance. coreToOpenai now re-emits the DSH attachment part to the DeepSeek API for the first time. The balance of evidence strongly suggests acceptance — it is DSH's own wire shape, designed for the DeepSeek route (DSH 0.2.2-rc.3 source: "stable model-facing handle for one exact request image"; the part is what DSH puts on the wire and bili is a transparent proxy), and the reporter's session has been running on it. But there is no live confirmation from a real DSH session yet. If the API rejects it, it would be an immediately visible p1 for DSH image users, and the revert path is clean: drop the coreToOpenai re-emission (and its roundtrip test) — the foldability fix (sidecar + enumeration) stands independently and the stale-BLOCKED migration still fires.

Aggregation requirements (#6894): all met — single root-cause PR, Fixes #6851 + Fixes #6875, cherry-pick -x (authorship preserved, patch-id verified), rcagg marker in the body, labels bug + p1 + root-cause applied (per the 2026-11-12 rule I do not relabel the source PR; the pipeline's labels satisfy the requirement), kernel-change declaration present.

Verdict: mergeable. The code is correct, the tests are strong (both gate directions, migration repro, byte-identical negative cases), CI is green on the identical tree, and the diff is clean (11 files, every line on-purpose). Two human-side notes: (1) the kernel change is human-only review tier (Kernel Boundary rule 3) — the merge is yours either way; (2) if a real DSH session 400s on the re-emitted part, trimming the re-emission post-merge is a clean fallback — the foldability fix does not depend on it. Post-merge: #6854 and #6879 become redundant (owner closes); the reporter can confirm the stale-BLOCKED migration on their session (the 836 rows should migrate to fresh refs on the next fold pass).


中文八问

  1. 是什么问题: 一个根因两个面——图片恢复溢出:①Responses 多图消息拆分后,恢复任一 ref 会把同一 carrier 里的所有兄弟图片一起恢复(N×N 个 spill 文件、跨图污染);②DSH 的 read_image/截图工具结果以 attachment 部件携带图片,codec 把它降成纯文本,分类器看不到媒体,把消息永久钉死为不可恢复(BLOCKED)——报告者会话里 836 行陈旧 BLOCKED(~160K tokens)永不迁移。
  2. 什么原因导致的: ①Responses codec 拆分多图时,每个拆分图片核仍携带整个原始 item(rawResponsesItem),宿主恢复索引把每个拆分 ref 绑定到 carrier 里的全部图片;②openaiToCore 把工具结果只降为文本,attachment 从未到达 CoreMessage,extractMediaRefs 无法枚举,分类器按「不可恢复媒体」钉住。
  3. 影响范围与严重程度: ①Responses 多图会话(OpenAI/Codex 线):解压恢复时跨图污染 + 二次方 spill 文件;②DSH 图片会话:带图片工具结果的消息永远不能折叠,会话只增不减(报告者:836 行 ~160K tokens 且持续增长)。属「上下文/存储只增不减」类 → p1。
  4. 怎么修复的: ①宿主恢复索引在 imagePart===true(仅拆分图片核)时只返回自己的 sidecar(纯远端 → 空),未拆分 carrier 与工具输出保持全 carrier 遍历;②codec 只保留携带 attachment 的图片部件进 rawOpenaiContentParts sidecar,extractMediaRefs 把 attachmentId 枚举为持久内容寻址句柄(裸 id,与 DeepSeek file_id 平行),coreToOpenai 重新发射部件——三者必须一起落地(sidecar 无枚举会新钉住消息,即 Image messages become permanently BLOCKED and can never be compressed(DSH attachment structure not recognized)图片消息永久变成 BLOCKED、无法压缩(attachment 结构未被识别) #6875 陷阱);消息 id 不变(ref 稳定)。
  5. 是否有回归问题: 无。逐项审过既有行为:未拆分 carrier/工具输出的全 carrier 遍历不变(有测试);纯文本工具结果保持 legacy 字符串形状逐字节一致(有测试);非 attachment 的不透明工具部件保持 legacy 文本降级(负向门双向测试);无跨线影响(rawResponsesItem 仅 Responses codec 设置;DSH 形状仅 openai codec);分类器未改——DSH 用户消息带 attachment 部件时同样从钉住翻转为可折叠(与 [Bug] Config save rejects valid mitm:// provider lanes as "invalid recipe on named provider" | 整文件保存把 mitm:// 路由误判为命名配方 #5620 拆分原则一致,非漂移);token 计量对 tool 角色前后都不计费(Image errors accumulating in the conversation | 对话中图片错误堆积 #3398 门未动,无行为变化,仅其注释前提对该形状已过时——观察项,非阻塞);陈旧 BLOCKED 迁移走既有 建议:compress.stripImages 默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 机制(有测试:BLOCKED → 新编号,永不复用)。
  6. 是否破坏缓存: 否。重新发射的部件逐请求确定;消息 id 不变;不影响缓存/重试/增量游标。
  7. 是否改了设计方向: 否。遵循既有 [Bug] OpenAI 线解析/重建无条件丢弃非 text/image_url 的 content part(如 DeepSeek Files API file part)——不压缩也丢图 #1205 模式(未知不透明部件保留+重发)与 [Bug] Config save rejects valid mitm:// provider lanes as "invalid recipe on named provider" | 整文件保存把 mitm:// 路由误判为命名配方 #5620 拆分原则(可 ref 恢复 vs 不可恢复媒体)。
  8. 是否引入了新的配置: 否。无新 env/config/默认值。

判定:可合并。 代码正确、测试扎实(双向门、迁移复现、逐字节负例)、相同树上 CI 绿、diff 干净(11 文件,每行都在目的内)。两点人工侧提示:kernel 变更属人工评审档(Kernel Boundary 规则 3),合并权在你;若真实 DSH 会话对重发射的部件返回 400,可后续裁掉 coreToOpenai 重发射(折叠性修复不依赖它)。合并后 #6854/#6879 变为冗余(owner 关闭);报告者可在其会话验证 836 行陈旧 BLOCKED 的迁移。

Afloat16 and others added 3 commits November 16, 2026 17:39
Use split image sidecars instead of expanding the whole carrier under
every image ref; preserve unsplit and tool-result image groups.

Fixes #6851

(cherry picked from commit f5aeb28)
DSH read_image results carry {type:"image", attachment:{attachmentId, ...}} in tool results. Two gaps stacked: the codec reduced tool results to text so the part never reached a CoreMessage, and extractMediaRefs never enumerated the shape so the message pinned forever. This lands both halves together: the tool branch preserves attachment-carrying image parts (and re-emits them), the classifier reads attachmentId as a durable re-access handle, and the drop detector stops counting preserved parts as dropped. Already-BLOCKED history migrates via the existing #2607 mechanism on the next compress.

(cherry picked from commit 0e8b779)
…d run)

The main CI workflow's runs were cancelled by the pull_request concurrency
group before any jobs started (0 jobs), so the full test lanes never ran.
This empty commit triggers a fresh synchronize event to re-run them.
@ranxianglei
ranxianglei force-pushed the 2026-11-16_image-recovery-spill branch from e907528 to 0bf0e24 Compare November 16, 2026 09:41
…00 -> 0.0.201)

Master advanced its kernel version past this PR's bump (0.0.198->0.0.199) to 0.0.200 (commit b805e43 resolved the same 0.0.199 collision with #7252). This PR's kernel/src changes (media-refs.ts, openai.ts for #6875) are new work not in any released version, so the merged tree bumps the kernel version to 0.0.201 (master's 0.0.200 + 1) to satisfy the Kernel Boundary version discipline (kernel/src changed => version must advance past the base).

The only conflicts were the three version fields (kernel/package.json, kernel/package-lock.json, root package-lock.json). All code files merged cleanly: the PR's first commit (image-restore, #6851) is already in master as fb7047c (identical change), and the PR's kernel files are disjoint from master's kernel changes.

kernel-change: recognize DSH attachment refs as recoverable media (#6875) - version bump to 0.0.201 is the mechanical consequence of merging master ahead of this PR's kernel work.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Merge conflict resolved — PR is now mergeable.

I merged master into the PR head branch (2026-11-16_image-recovery-spill) and resolved the conflict. The only conflicts were three kernel-version fields; all code files merged cleanly. Pushed as a fast-forward (remote head was unchanged): 0bf0e2492ca..201bc88f497.

What conflicted and how I resolved it:

Note for the reviewer: the PR body's "kernel 0.0.198 → 0.0.199" line is now stale — the effective bump is 0.0.198 → 0.0.201 (master consumed 0.0.199/0.0.200 in between). I did not edit the PR body (out of scope for this lane); flagging it here.

Local verification: version consistency confirmed across all three files, no leftover conflict markers, PR kernel changes + master changes both present, merged diff vs master = exactly the PR's kernel commit. A local npm run typecheck could not run (fresh worktree, no node_modules — environment, not the change); the full typecheck/test verdict is the remote CI on the new head 201bc88f497.


结构化八问

  1. 是什么问题:PR [PR] fix: image recovery — one ref per split image, DSH attachments recoverable (root-cause: image-recovery-spill) #6902 与 master 冲突(merge state: dirty),无法合并。
  2. 什么原因导致的:master 的 kernel 版本从 PR 分叉点(0.0.198)推进到 0.0.200(b805e43acb8 已解决过与 [PR] compress.reasoning.tail: drop reasoning of any closed round in the protected window (#7144 follow-up) #7252 的 0.0.199 碰撞),而本 PR 把 kernel 版本 0.0.198→0.0.199,两边都占 0.0.199,产生版本字段冲突。
  3. 影响范围与严重程度:仅阻塞该 PR 合并,不影响任何已发布行为。严重程度:不修则 PR 永远 dirty(可用性阻塞,非数据/缓存问题)。
  4. 怎么修复的:master merge 进 PR 分支,三个版本字段统一解析为 0.0.201(master 0.0.200 + 1)。代码文件全部干净合并——PR 首 commit(image-restore [Bug] Responses split image refs restore sibling images and create quadratic spill files #6851)已在 master(fb7047c7771,改动相同),PR 的 kernel 文件与 master kernel 改动不相交。
  5. 是否有回归问题:无。只动版本号;代码改动要么已在 master(CI 已验证),要么与 master 改动不相交。高危模式逐项:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。
  6. 是否破坏缓存:不涉及。版本号不影响缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:不涉及,纯机械冲突解决。
  8. 是否引入了新的配置:不涉及,无新 env/config/默认值。

判定:冲突已解决,PR 现 mergeable=True(mergeable_state=blocked = 等 CI/审批,属正常)。本车道工作完成。

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 p1 root-cause

Projects

None yet

3 participants