Skip to content

[PR] fix(kernel): DSH read_image attachments are recoverable media (#6875) - #6879

Open
sx4im wants to merge 2 commits into
ranxianglei:masterfrom
sx4im:fix-6875-dsh-attachment-recoverable
Open

sx4im wants to merge 2 commits into
ranxianglei:masterfrom
sx4im:fix-6875-dsh-attachment-recoverable

Conversation

@sx4im

@sx4im sx4im commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What broke
DSH read_image and screenshot results carry their image as {type:"image", attachment:{attachmentId, ...}} in tool results. Two gaps stacked: openaiToCore's tool branch reduced every tool result to text, so the part never reached a CoreMessage; and extractMediaRefs never enumerated the attachment shape, so even a carried part classified as unrecoverable media. The messages pinned forever and their refs went BLOCKED, about 160K tokens stuck in the reporter's session.

What changed

  • kernel/src/wire/openai.ts: the tool branch now preserves attachment-carrying image parts into rawOpenaiContentParts, and coreToOpenai re-emits them after the text part. Any other opaque tool part keeps the legacy text-only reduction.
  • kernel/src/media-refs.ts: extractMediaRefs reads attachmentId as a durable content-addressed re-access handle (a bare id, same class as a DeepSeek file_id), so the message is ref-recoverable and folds, with the id recorded in the block summary's MEDIA REFS section. An attachment with no usable id still pins.
  • src/wire-drop-warn.ts: the drop detector no longer counts preserved DSH attachment parts as dropped.
  • kernel 0.0.200 -> 0.0.201, both lockfiles synced.

kernel-change: DSH attachment refs are recoverable media (#6875)

How verified

  • New regression tests pass (13 kernel, 2 host); the classifier half was verified red on the unpatched tree before the fix. Neighbors green: full kernel suite 1652 pass with 1 pre-existing perf-timing failure (issue5337-shared-screening, fails identically on pristine HEAD). Kernel tsc clean.
  • Already-BLOCKED history: no migration code and no hand-editing the refs table. Protection is re-evaluated every compress pass, so once the classifier sees the handle the existing 建议:compress.stripImages 默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 migration mints a fresh number. A directed test runs the full chain (parse a DSH tool result, then assignRefs over a stale BLOCKED binding).

Scope note
Folding keeps the attachmentId handle in the summary's MEDIA REFS section, same as remote-URL media since #5620; the image bytes themselves no longer ride the request, same as remote-URL media. The reporter's second question is answered by the migration above: already-BLOCKED ranges unblock on the next compress after this lands.

Fixes #6875

…ei#6875)

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 ranxianglei#2607 mechanism on the next compress.
@ranxianglei ranxianglei changed the title fix(kernel): DSH read_image attachments are recoverable media (#6875) [PR] fix(kernel): DSH read_image attachments are recoverable media (#6875) Nov 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 Searched open+closed issues/PRs for the DSH attachment / read_image / BLOCKED / recoverable-media signatures. The only related prior work is #3398/#3412 (merged 2026-10-18) — same root problem (DSH {type:"image",attachment:{…}} shape unrecognized) but a different mechanism: #3412 fixed the counting half (custom-shape media invisible to context-size decisions → no compression triggered). This PR fixes the protection/pinning half (shape not recognized as recoverable media → message pinned BLOCKED, can't fold). Different failure domain, different fix path. No duplication.

Review of PR #6879 — fix(kernel): DSH read_image attachments are recoverable media (#6875)

I checked out the PR head (0e8b7794d4), read the diff against master, ran the new tests locally, and verified the verif guards. CI is still running (11 test shards in progress; static-gates/gate/build-artifact/mysql-contract already green; all e2e lanes skipped including the DSH headless lane). I'll follow up when CI completes.

What I verified locally:

  • 13/13 new kernel tests pass (issue6875-dsh-attachment-refs.test.ts 6 + issue6875-tool-result-sidecar.test.ts 7).
  • verif-subset-guard passes (openai.ts is a Tier-A guarded file; no violations, no stale exceptions).
  • verif-adapter-wire-stability 17/17, verif-wire-anthropic-roundtrip + verif-wire-responses-stability + verif-wire-google-rebuild-stability 15/15, verif-bug3676-wire-reorder 1/1 — all pass.
  • Kernel tsc clean (build succeeds).

Code assessment:

The fix is a root-cause fix (疏, not 堵) with two required halves, both correctly implemented:

  1. Codec half (kernel/src/wire/openai.ts): the tool branch now preserves attachment-carrying image parts into rawOpenaiContentParts (the sidecar), and coreToOpenai re-emits them after the text part. The type guard isDshAttachmentPart is precise: type === "image" + attachment object + non-empty string attachmentId. Any other opaque tool part keeps the legacy text-only reduction. This closes the gap where the tool branch had no parity with the user branch (which already attaches unknown opaque parts to the sidecar since [Bug] OpenAI 线解析/重建无条件丢弃非 text/image_url 的 content part(如 DeepSeek Files API file part)——不压缩也丢图 #1205).

  2. Classifier half (kernel/src/media-refs.ts): extractMediaRefs now reads attachmentId as a durable content-addressed re-access handle (a bare id, same class as a DeepSeek file_id). The sha256:... id passes all pushRef guards (not a data: URL, not an http URL, not ephemeral). So hasRefRecoverableMediaPayload returns true → hasUnrecoverableMediaPayload returns false → the message is no longer pinned. The 建议:compress.stripImages 默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 stale-BLOCKED migration in refs.ts:114-121 then mints a fresh ref number on the next compress pass (protection is re-evaluated every pass, not persisted).

The src/wire-drop-warn.ts change mirrors the type guard so the drop detector doesn't false-warn on preserved DSH attachment parts. A bare {type:"image",attachment:{mediaType}} part (no attachmentId) is still correctly reported as dropped (negative assertion present in the host test).

Two findings (minor, non-blocking):

  1. Drop-detector over-suppression (theoretical): wire-drop-warn.ts skips isDshAttachmentPart for all non-user roles, but the codec only preserves DSH attachment parts on tool results. If an assistant message ever carried the shape, the codec would drop it (assistant branch reduces to text-only) but the detector would no longer warn. The DSH attachment shape is a tool-result-only shape, so this is theoretical — but the detector's skip should ideally match the codec's preservation exactly (tool role only).

  2. Upstream acceptance unverified: coreToOpenai now re-emits the DSH attachment part to the upstream (DeepSeek). On master, the proxy dropped all non-text parts in tool results (text-only reduction), so the upstream never saw this shape. The re-emitted part is a non-standard {type:"image"} (not image_url) carrying a DSH-local blob reference (attachmentId: sha256:...) that DeepSeek cannot resolve. The unit tests verify the round-trip but not upstream acceptance. The DSH e2e lane is skipped in this PR's CI, so there's no e2e verification either. This needs a real DSH session to confirm DeepSeek accepts (or at least ignores) the re-emitted part. If DeepSeek rejects it (400), the fix would be a regression.

Open question (does not block the review, but worth confirming): the PR's test header states the maintainer's triage that the tool branch dropped the part at parse time. If the part never reached the CoreMessage on the unpatched code, the classifier would never have seen it, and the message should have been foldable as plain text — yet the reporter observed BLOCKED. The exact historical pinning path is not fully resolved from the available evidence (the reporter's reconstructed log shows core messages with no sidecar). The fix is correct regardless (both halves are needed: retention without recognition would newly pin), but the "why was it BLOCKED" question is worth a one-line confirmation from the reporter.


八问:

  1. 是什么问题:DSH read_image/screenshot 的 tool result 携带 {type:"image",attachment:{attachmentId,…}} 形态的图片,bili 的 codec 在 tool 分支把它丢掉(只留文本),classifier 又不认识这个形态——两层叠加导致消息被永久 pin 成 BLOCKED,~160K token 卡死无法压缩。
  2. 什么原因导致的:两层缺陷叠加——① openaiToCore tool 分支对所有 tool result 做 text-only reduction,attachment part 从未进入 rawOpenaiContentParts sidecar(与 user 分支 [Bug] OpenAI 线解析/重建无条件丢弃非 text/image_url 的 content part(如 DeepSeek Files API file part)——不压缩也丢图 #1205 的 opaque-part 保留不对称);② extractMediaRefs 不枚举 attachment 形态,即使 part 被保留也会判为 unrecoverable media → pin。根因是 DSH 自定义 attachment 形态在 codec 和 classifier 两层都未被识别。
  3. 影响范围与严重程度:DSH 客户端 + read_image/screenshot 工具 + 默认配置。严重程度 p1——消息永久 BLOCKED,上下文只增不减,用户无法恢复(重启/升级均无效),直到本 PR 落地。
  4. 怎么修复的:两半同时修——① codec:tool 分支保留 attachment-carrying image part 进 sidecar,coreToOpenai 在 text part 后重发;② classifier:extractMediaRefs 把 attachmentId 当作 durable content-addressed handle(与 DeepSeek file_id 同类),使消息 ref-recoverable → 可折叠,id 记入 block summary 的 MEDIA REFS 段。已 BLOCKED 的历史消息在下次 compress 时经 建议:compress.stripImages 默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 迁移自动 mint 新 ref。
  5. 是否有回归问题:有一个需要确认的回归风险——coreToOpenai 现在把 DSH attachment part 重发到上游(DeepSeek)。master 上 proxy 对 tool result 做 text-only reduction,上游从未见过这个形态。重发的 part 是非标准 {type:"image"}(非 image_url),携带 DSH 本地 blob 引用,DeepSeek 无法解析。单测只验证 round-trip,未验证上游接受;DSH e2e lane 在本 PR CI 中被 skip。需要真实 DSH 会话确认 DeepSeek 接受(或至少忽略)重发的 part。 若 DeepSeek 拒绝(400),则本 PR 是回归。其余既有行为(plain tool result 的 string shape、非 attachment opaque part 的 legacy reduction、no-id/empty-id attachment 仍 pin)均有测试钉住,未变。
  6. 是否破坏缓存:不涉及。修复不改缓存/重试/增量游标/去重键。attachmentId 作为 MEDIA REFS 段的内容,与 remote-URL media([Bug] Config save rejects valid mitm:// provider lanes as "invalid recipe on named provider" | 整文件保存把 mitm:// 路由误判为命名配方 #5620)同类,不影响 prefix cache。
  7. 是否改了设计方向:不涉及。修复在既有 codec + classifier 框架内,不引入新架构/边界/数据流。DSH attachment 形态被纳入既有的「recoverable media」分类,与 fix: count custom-shape media parts in context-size decisions (images no longer invisible to folding) #3412(counting 半)互补,不冲突。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值。

判定:代码质量良好,两半修复逻辑正确,测试有效(含负向断言),verif 守卫全过。有一个需要确认的回归风险(上游是否接受重发的 attachment part)和一个理论性小缺陷(drop detector 过度抑制)。建议:① 等 CI 全绿;② 请 reporter 在真实 DSH 会话上确认 DeepSeek 接受重发的 part(或提供日志);③ 确认后可合入。kernel 变更属 human-only review tier,不 auto-merge。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI 全绿。 16 success / 14 skipped / 0 failed。11 个 test shard(ubuntu/windows × node 22/24)全过,static-gates ×2、mysql-contract、gate ×2 全过。14 个 skipped 全是 e2e lane(含 real dsh headless profile lane)——与上一条评论指出的一致:DSH e2e lane 被 skip,所以上游接受性仍无 e2e 验证。

最终判定不变:代码质量良好,两半修复逻辑正确,测试有效,verif 守卫全过,CI 全绿。合入前唯一需要确认的事项:

  1. 上游接受性(回归风险):coreToOpenai 现在把 DSH attachment part 重发到 DeepSeek。请 reporter 在真实 DSH 会话上确认 DeepSeek 接受(或至少忽略)重发的 {type:"image",attachment:{…}} part——若 400 拒绝,则本 PR 是回归。
  2. 理论性小缺陷(非阻塞):wire-drop-warn.ts 的 isDshAttachmentPart skip 应用于所有非 user role,但 codec 只在 tool result 上保留 DSH attachment part。若 assistant 消息携带该形态,codec 会 drop 但 detector 不再 warn。DSH attachment 是 tool-result-only 形态,所以是理论性的。

kernel 变更属 human-only review tier,不 auto-merge。等 reporter 确认上游接受性后,可由 owner 合入。

Re-bump kernel 0.0.200 -> 0.0.201; both lockfiles synced.

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

Projects

None yet

2 participants