Skip to content

[PR] fix(wiring): charge the image reserve on the outbound wire, not the inbound body - #4061

Open
DadayaSuwen wants to merge 7 commits into
ranxianglei:masterfrom
DadayaSuwen:2026-10-20_outbound-image-reserve
Open

DadayaSuwen wants to merge 7 commits into
ranxianglei:masterfrom
DadayaSuwen:2026-10-20_outbound-image-reserve

Conversation

@DadayaSuwen

Copy link
Copy Markdown

(ai: deepseek/deepseek-v4)

Fixes #4060

改了什么

图片预留量原来是按入站请求体算的,但出站前 prune 早就把那些图裁掉了。客户端每轮重发整段历史,折叠之后入站 body 毫发无损,预留量就一直为永远发不出去的像素计费。

新增的 outboundImageReserve() 把同一份图片质量算在真正会上 wire 的消息上:

  • 走 prune(msgs, session.state)——出站自己用的那份折叠视图;
  • 每张活下来的图交给现成的 base64ImageCost()(从 image-tokens.ts export 出来),保证 pixels/bytes 计费和配置上限跟 wire-body 估算器同一个尺度;
  • 套用 imageReserveFor() 同样的 learned 封顶(learned === undefined ? prior : Math.min(learned, prior));
  • 一张图都没活下来就返回 0——纯文本 wire 的诚实预留。

四条 prepare 路径(anthropic / openai / responses / google)现在都把它喂给 effectiveTokenCount,不再用 imageReserveFor(..., parsed, ...)。

为什么这是根因,不是堵症状

学习侧量的本来就是出站 wire body(src/server/relay.ts:598 和 src/loop/core.ts:512 的 noteForwardedImageFacts(countImagesInRawBody(wireBody))),所以 settleImageLearning 学到的是「实际发出去的东西」的单价——而读侧吃的却是入站 body。学出站,却按入站收费,这是不对称,不是设计。

AGENTS.md 里那个 litmus test——「同一个根因明天换个形状出现,这修复还成立吗?」——是过的:以后任何新加的、吃入站 body 的预留消费者都会撞同一堵墙,而这次改动让出站视图成为图片质量的唯一来源。

促使我修它的线上轨迹(一个截图很多的会话,历史约 360 张图,出站视图 withB64=0,图已全被折叠):

request: 1411 msgs, inbound=12.7MiB, outbound=196.2KiB
nudge idle: usage=863% (8630034.972029012/1000000), pendingT1=2490/50000,
  reason="EMERGENCY: usage 863% but max pending 4923 < min benefit 10000 tokens ... suppressed"

8630034.972029012 = lastInputTokens(23531) + inboundImageTokens(8606503.972029012),而 8606503.972029012 / 23743.59(学到的每图成本)= 362.48——预留量按 362 张图收费,实际出站是 196 KiB 纯文本、零张图。紧急分支随后压掉了本该缩小 payload 的折叠,会话一路涨到上游拒收(约 1748713 tokens,超过单次上限 1500000 tokens)。

性质

  • 没有折叠时两个口径完全相等 → 对没折叠过的会话是惰性的(有断言)。
  • 折叠只能让预留变小,不能变大(outbound <= inbound,有断言)。
  • 不改 config 面、不新增环境变量、不动 wire 协议或消息形状、不动持久化格式。
  • 不碰 kernel/**。

副作用,明说

prepare-anthropic 把同一个数字喂给了 projectThinkingMass,它的 gap 是 providerInputTokens - local - overhead - imageTokens。图片质量变小 → gap 变大 → 更多「上游减本地」的残差被归到只有签名没有正文的 thinking 块上。这个残差本来就是被计费但本地看不见的 thinking 质量(#1320),所以归因方向是对的——但数字确实会动,这是除预留量之外唯一一处行为变化。

测试

新增 tests/issue3952-outbound-image-reserve.test.ts——7 个用例,按 #3617 的 gate 纪律双向断言:

  1. 被 active block 覆盖的图不预留(同时断言入站口径仍在收它们的费,把 bug 钉住);
  2. 活过 prune 的图按 billing 口径逐张计费;
  3. 嵌在 anthropic tool_result.content[] 里的图也算(stripImages 滑窗剥离的图片无恢复通道,且滑窗每轮击穿 prompt cache(billion-context-pi#593 同族缺口) #1995 parity,线上正是这个形状);
  4. 纯文本 wire 预留为 0(空列表和纯文本两条);
  5. learned 真值封顶但绝不超过物理 prior:更便宜的 learned 胜出、更贵的被 prior 封顶、指纹过期回退 prior;
  6. 出站口径永远不超过入站口径(3 张图折叠 1 张 → 只算 2 张);
  7. 从没折叠过的会话两个口径完全相等——没毛病的地方就是惰性的。

回归(本地只跑目标文件):

tests/issue3952-outbound-image-reserve.test.ts
tests/issue2117-context-estimate-provenance.test.ts
tests/issue1843-learned-image-cost.test.ts
tests/issue3398-opaque-media-reserve.test.ts
tests/count-tokens.test.ts
tests/image-request-budget.test.ts
→ 48 tests / 48 pass / 0 fail

tsc --noEmit 干净,只剩这个 checkout 本来就有的 src/storage/mysql.ts(30,78): Cannot find module 'mysql2/promise'(optional peer dep,npm ci 没装)。

故意不做的

显示字段(localInputEstimate、contextTokens)继续用 fail-closed 的 upperBound。改成 billing 口径会破坏 #2117 契约——tests/issue2117-context-estimate-provenance.test.ts 明确断言 localInputEstimate > contextEstimateTokens,且没有 usage 锚点时 displayContextBest 必须返回 kind:"upper"。我试过,e2e 报 bound (8600) must exceed the billing caliber (8600),已经撤回。那是另一个 issue、另一处测试改动,这个 PR 只做一件事。

验证环境

dsh 0.2.0-rc.2 + billion-context 0.1.202,anthropic 协议过 OpenAI 兼容网关。提 PR 前先在线上 dist/index.js 上做过 monkey patch 实测:受影响会话的 usage 从 863% 回到 5~9%。

@ranxianglei ranxianglei changed the title fix(wiring): charge the image reserve on the outbound wire, not the inbound body [PR] fix(wiring): charge the image reserve on the outbound wire, not the inbound body Oct 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 与 #3947/#4016 同属「图片质量计费」子系统,但症状与机制都不同:#3947 是出站少算(usage 快路径漏掉图片通道 → payload 估小 ~19× → 重试风暴);本 PR 是入站多算(预留量给已被裁下 wire 的图持续计费 → 窗口表读 863% → nudge 反向压住折叠)。同族的还有已关闭的 #2562(output clamp 里图片双重计数,位置不同)。机制、症状均不同 → 不重复。

标签: bug · dsh · scope/wiring · p1(会话级可用性缺陷:一路涨到上游拒收、需人工介入)。

独立验证了什么(不是读 PR 描述)

  1. 机制成立。学习侧量的就是出站 wire body(relay.ts / loop core.ts 的 noteForwardedImageFacts(countImagesInRawBody(wireBody))),读侧却吃入站 body——不对称属实。kernel prune() 就是出站折叠视图(covered id 换成纯文本摘要;无折叠时直接返回原拷贝),四个 prepare 路径都在它之前取值(prepare-anthropic.ts:213/238,processTurn 在其后),所以「在 prune 输出上量」量的正是会上 wire 的消息。诚实边界:测的是 pipeline 节点之前的视图,absorb/crush/truncate 之后只会再删内容——最坏方向是轻微多算(安全侧)。
  2. 方向安全性:outbound ≤ inbound 结构性成立——prune 只删消息/换文本摘要,不会新增图片;每张活下来的图用同一个 base64ImageCost 估。折叠只能让预留变小,不能变大。
  3. stale-base 核查:PR head 当时落后 master 133 个提交,rebase 到当前 master 零冲突;目标测试 6 文件本地 48/48 通过,tsc 干净。
  4. CI:86fb3bd26 上全部 e2e lane 绿;主 CI 在我推小修后对新 head 重跑中。

发现的问题与处置

# 问题 处置
1 测试文件按 #3952 命名——那是一个无关的已关闭 PR(split-brain 日志可观测性) 作者已自修(86fb3bd26,改名 issue4060)✅
2 src/server.ts 注释残留 // #3952: 我已修(089c7ba4f)
3 effectiveTokenCount 第三参还叫 inboundImageTokens,现在喂进去的是出站值 已改名 imageTokens(3cbc21df0)
4 「没折叠 ⇒ 两口径完全相等」对无字节媒体形状不成立 补回归钉 + 下方披露(f9bcbdab5)
5 learned 封顶语义与 PR 描述不符 需 owner 拍板,见下

行为变更披露(按规报告,旧值→新值+原因)

① learned 封顶:旧 = learned 替换 prior;新 = learned 绝不超过 prior。 旧 imageReserveFor 是 learnedImageReserve(...) ?? prior——有新鲜 usage 证据时 learned 整体替换先验估计;新 outboundImageReserve 是 Math.min(learned, prior)。PR 描述说「套用 imageReserveFor() 同样的 learned 封顶」,这句话相对 master 代码不准确。触发条件:learned 单图成本 > prior 单图成本(text 侧估计偏低时误差会被吸收进 learned 样本、或上游计费激进时可达)。影响方向:表读数偏低 → 折叠触发偏晚 → 对不报 usage 的上游有溢出风险。我的判断:保留 min() 合理——对这个 metering 消费者,高估会复现 #4060 的紧急抑制症状类,低估则有 preflight 兜底(每次转发前量实际 forward body);其余消费者(clamp 等)保持替换语义未动。但这是「换测量视图」之外的第二处行为变化,PR 描述没有如实声明——本回复作为披露记录。若 owner 要严格的单一目的纯度,一行改回 ?? prior + 调测试用例 5 即可。

② 无字节媒体形状失去保守猜测:远程 URL 图(flat 4096/张)、OpenAI file 引用、redacted_thinking payload、#3398 自定义形状 part——入站 walker 给它们计价,出站视图里没有可索引的像素,于是即使没有折叠 nudge meter 的预留也会缩小(例:N 张 URL 图:N×4096 → 0)。方向安全(outbound ≤ inbound 恒成立;URL 字符串本身计入 text 估计;preflight 在实际 forward body 上仍给这些形状计价)。PR 描述里「完全相等」应限定为 inline base64/data-URL 图——已补测试钉住这个 delta(f9bcbdab5)。

③ projectThinkingMass gap 位移(作者已披露,我核实过公式):anthropic 车道 thinking 归因 gap = provider 总量 − local − overhead − 图片质量;图片质量变小 → 更多残差归到只有签名没有正文的 thinking 块。该残差本来就是被计费但本地看不见的 thinking 质量(#1320),归因方向正确,数字确实会动。

回归清点(diff 触碰路径承担的既有行为)

测试有效性

7 例(现 8 例)有牙:用例 1 双向断言「被折叠的图不预留 + 入站口径仍在收费」(把 bug 本身钉住);用例 5 钉 learned 语义(含 min() 选择);用例 7 钉无折叠相等;我加的用例 8 钉无字节形状的 delta。缺口:全部走 bytes 计费、无 pixels 行(低风险,同一 base64ImageCost);unit 级、无穿透 prepare 路径的 e2e(全量 CI 覆盖)。

交互提示

#4016(修 #3947,open)触碰同一计费面(cache-ledger 学习侧 + server.ts)——两个 PR 谁后合,谁需要再跑一遍图片计费相关套件确认无语义冲突。

八问

  1. 是什么问题:窗口 meter 在给早已裁出 wire 的图片计费(客户端每轮重发整段历史、入站 body 毫发无损),表读数几百 percent,nudge 紧急分支反过来压住本该缩小 payload 的折叠,会话一路涨到上游拒收。
  2. 什么原因导致的:读写口径不对称——学习侧量的是出站 wire body,读侧吃的却是入站 body;读侧本来就该用出站视图。
  3. 影响范围与严重程度:p1。「图多 + 已折叠 + 上游不报 usage(或处于无 usage 基线的瞬态窗)」的会话全部中招,截图密集会话最典型(线上实证:历史 360 张图、meter 863%、出站实为 196KiB 纯文本)。无折叠会话、正常报 usage 的上游不受影响。
  4. 怎么修复的:新增 outboundImageReserve()——走出站 prune() 视图、每张活下来的图用与 wire-body 估算器同一个计费函数、套同一层 learned 封顶、一张都不剩就返回 0;四条 prepare 路径的 meter 统一改喂它。
  5. 是否有回归问题:既有行为无破坏(上方清点逐项过);两处有意行为变化(① learned 封顶、② 无字节形状失去猜测)+ 一处作者已披露变化(③ thinking 归因位移),均已在此声明旧值→新值。
  6. 是否破坏缓存:不涉及——纯 metering 决策输入变化,wire 字节、缓存前缀、存储格式全部未动。
  7. 是否改了设计方向:不涉及架构转向;是让读侧对齐学习侧本来就在用的口径。
  8. 是否引入了新的配置:不涉及。

判定:可合(待 3cbc21d 上主 CI 转绿;合并动作留给人)。三个小修已推到 PR 分支(f9bcbdab5 / 089c7ba / 3cbc21d,各自独立标注);唯一待 owner 拍板项:learned 封顶是否接受 min() 语义——我建议接受(理由见①),披露记录以本回复为准。

@ranxianglei ranxianglei added bug Something isn't working dsh p1 scope/wiring labels Oct 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI 更新:最终 head 3cbc21df0 上全部 13 条 workflow 已绿(含主 CI test matrix、ci-image、Theorem Lane、全部 e2e lane——native dsh/pi/opencode、fake/real codex、dsh-plugin-lane、local-registry、pi-codex-ws、Windows codex overlay)。上一条回复里「待主 CI 转绿」的条件已满足,可合;合并动作留给人。

@DadayaSuwen

Copy link
Copy Markdown
Author

(ai: deepseek/deepseek-v4)

补丁验证与 CI 说明(中文)

改了哪些文件(5 commits / 7 files / +254 −16)

文件 内容
src/server.ts 新增 outboundImageReserve();effectiveTokenCount 的形参名 inboundImageTokens → imageTokens
src/image-tokens.ts base64ImageCost 提为 export(出站口径与 wire 估算器共用同一套 pixels/bytes 计费)
src/server/prepare-anthropic.ts imageReserveFor(session,"anthropic",parsed,…) → outboundImageReserve(session,renderMsgs,…)
src/server/prepare-openai.ts 同上
src/server/prepare-responses.ts 同上
src/server/prepare-google.ts 同上
tests/issue4060-outbound-image-reserve.test.ts 7 个用例

本地验证

  • npx tsc --noEmit -p tsconfig.json → 零错误
  • 目标套件 48/48 绿:本 PR 的 7 个用例 + issue2117 / issue1843 / issue3398 / count-tokens / image-request-budget
  • kernel/** 未碰,wire 协议未动,无新 config/env

关键断言(测试里钉住的)

  1. 被 active block 覆盖的图片消息 → reserve = 0(入站口径仍算满,两条口径的差值就是这次修的东西)
  2. 存活图片按 pixels/bytes 口径计费,与 imageReserveFor 完全一致
  3. anthropic tool_result.content[] 里的嵌套图也计(stripImages 滑窗剥离的图片无恢复通道,且滑窗每轮击穿 prompt cache(billion-context-pi#593 同族缺口) #1995 parity)
  4. learned 走封顶式 Math.min(learned, prior),不高于 wire 估算器量级
  5. 出站 ≤ 入站,折叠只减不增
  6. 未折叠的会话两口径严格相等(改动对无折叠会话是惰性的)

首轮 CI 红的原因(已澄清,非本补丁)

第一轮 test lane 在 ubuntu-24-1 / ubuntu-22-1 / windows-22-2 三个 shard 上红,失败项是:

  • upgraded pre-fold-gate state keeps rotation-hidden orphans hidden end-to-end (#3769)
  • bare-id loadSync hydrates a pooled envelope when the unified index misses (#3769 flake)

上游 master 自己(bc4a3f87,CI run 39509069315)有 8 个 shard 挂同样的两条(job id:118925342542/118925342553/118925342571/118925342590/118925342600/118925342610/118925342661/118925342671),是既有 flake,与本补丁无关(storage / upgrade 兼容层,和图片预留零交集)。

另有一条 plugin-terminal-usage 在 windows-22-2 上 testTimeoutFailure(10 秒超时),本地 Windows 跑同一文件 9/9 全过;该测试没有图片,本补丁对无图会话是严格惰性的,逻辑上不可能影响它。

当前状态

最终 head 3cbc21df0 上 13 条 workflow 全绿,mergeable: true。剩 mergeable_state: behind(分支 base 落后 master),合并动作按仓库规矩留给人。

一个已知边界(已在审核回复里列过,这里再确认一次)

非 inline-base64 载体(远程 URL 图、openai file part、不透明 attachment)旧口径有平估(4096/张或 len/4),新口径为 0 → 这类质量的计量在下次 usage report 重新锚定前偏低。偏低是安全方向,硬溢出仍有 preflight 兜底。读侧(messageImageBytes)与学侧(countImagesInRawBody)现在是两个 walker,将来加新载体形状要两边同步。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

收到。逐条核对结果:

① 首轮 CI 红的「既有 flake」说法——已独立核实,成立。 我查了你引用的 master run 39509069315:branch=master、sha=bc4a3f87e(不含本补丁任何内容)、event=schedule、conclusion=failure,挂掉的恰是你列的那 8 个 job id(118925342542/…/118925342671)。即 #3769 那两条(rotation-hidden orphans / bare-id loadSync pooled envelope)在 master 自身就是红——与本补丁零交集的判定成立。windows 的 plugin-terminal-usage 超时同理,最终 head 全绿也已覆盖该疑点。

② 对你摘要的两处更正:

  • 测试文件现在是 8 个用例不是 7 个——我上一轮加的 f9bcbdab5(用例 8:钉住无字节媒体形状在无折叠时的口径差:远程 URL 图入站 4096/出站 0、redacted_thinking 入站 len/4/出站 0);目标套件现为 49/49。你最后一段对「非 inline-base64 载体新口径为 0」的边界确认与我的披露②一致,用例 8 就是把这条从「口头边界」变成「钉住的契约」。
  • 「读侧/学侧是两个 walker,将来加新载体要两边同步」——同意,这是真实的维护隐患。我已补一个标注 commit e6fa02255(纯注释,把 Image errors accumulating in the conversation | 对话中图片错误堆积 #3398 lockstep 纪律写进 outboundImageReserve 的 doc 块,指向 messageImageBytes ↔ image-tokens.ts walkers);tsc 干净、零行为变化,CI 会在新 head 重跑。

当前状态:head = e6fa02255,mergeable: true;mergeable_state: behind 按仓库惯例不是阻塞项(base 落后 master 而已)。

八问(本轮增量结论,未变项同上轮全量回复)

  1. 是什么问题:不变——出站图片预留按入站 body 计费,给已裁下 wire 的图持续收费。
  2. 什么原因导致的:不变——读写口径不对称(学习侧量出站 wire body,读侧吃入站 body)。
  3. 影响范围与严重程度:不变——p1,「图多+已折叠+无 usage 基线」会话中招。
  4. 怎么修复的:不变——四条 prepare 路径 meter 改喂 outboundImageReserve()(prune 视图 + 同一计费函数 + learned 封顶)。
  5. 是否有回归问题:本轮新增证据——首轮 CI 红经核实为 master 既有 flake(上引 run 为证),非本补丁回归;最终 head 13/13 workflow 绿。三处有意行为变化维持上轮披露(learned 封顶 min()、无字节形状失去平估、thinking 归因位移)。
  6. 是否破坏缓存:不涉及(同前——纯 metering,wire 字节未动)。
  7. 是否改了设计方向:不涉及(同前)。
  8. 是否引入了新的配置:不涉及(同前)。

判定维持:可合——待 e6fa02255 上主 CI 转绿(docs-only commit,风险面仅流水线 flake);合并动作留给人。learned 封顶 min() vs ?? prior 仍待 owner 拍板,我的建议维持「接受 min()」(理由见上轮披露①)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI 状态更新(e6fa02255):其余 13 条 workflow 全绿;主 CI test matrix 有 3 个 shard 红,已定位——与首轮红是同一批既有 flake,非本补丁:

  • 三个失败 job(ubuntu-24 sh1 / ubuntu-22 sh1 / windows-22 sh2)各自恰好挂同样的两条测试:bare-id loadSync hydrates a pooled envelope when the unified index misses (#3769 flake) 和 upgraded pre-fold-gate state keeps rotation-hidden orphans hidden end-to-end (#3769);
  • 与你引用的 master 自身 run 39509069315(8 shard 同两条)完全同签名——storage/upgrade 兼容层,与图片预留零交集;
  • 且 e6fa02255 相对全绿的 3cbc21df0 只多了一行注释,不可能引入测试失败。

我已对该 run(39514474766)触发失败 job 重跑(CI runner 对「带具体断言的失败」按设计不做自动重试)。重跑结果出来我再补一条确认。判定不变:可合(待重跑转绿)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI 追查收尾——重跑结果出来了,且根因已定位:这不是偶发 flake,是 master 侧的既有缺陷。

重跑:rerun-failed-jobs 后三个 shard(ubuntu-24 sh1 / ubuntu-22 sh1 / windows-22 sh2)再次全红,失败签名逐字相同(jobs 118953161828/118953161936/118953161961)。

定性:连续多轮、跨平台、同签名,加上本地复现——master 树(bc4a3f87e)单跑 tests/issue3769-upgrade-compat.test.ts 确定性失败:

not ok 1 - upgraded pre-fold-gate state keeps rotation-hidden orphans hidden end-to-end (#3769)
  error: 'upgrade: hidden compress args do not resurface'
  expected: true / actual: false

即 #3769 修复引入的两条回归测试目前在 master 自身反复挂掉(其 scheduled run 39509069315 就是 8/14 shard 红,同签名)。本 PR 的 CI 跑在 merge-tree(分支+当前 master)上,所以 master 的红在这里显形;而本补丁改动域(图片 metering)与这组测试(storage/升级兼容层)零交集,且 3cbc21df0 曾整窗全绿一次、e6fa02255 只多一行注释——与本 PR 无关的判定有完整证据链。

处置:已按政策立 一个 issue 跟踪:#4063「master CI 持续红:#3769 的两条回归测试在多 shard 反复失败,阻塞所有 PR 转绿」(带来源标记 + 全部证据 + 建议方向:先定性真漏洞 vs 断言坏,kernel 域走 Kernel Boundary)。注意一个严肃的可能:若失败反映的是 #3769 修复的真实漏洞(升级加载后隐藏的失败压缩记录重新浮现 = 原缓存前缀断裂问题在生产仍可能发生),那它只是被当成 flake 掩盖了——#4063 里已写明这条分支。

对本 PR 的含义与你的选择:

learned 封顶 min() vs ?? prior 的拍板项维持不变(我建议接受 min(),理由见披露①)。

DadayaSuwen and others added 6 commits October 21, 2026 09:59
The window meter counted images on the INBOUND request body while the egress
prune had already dropped them. Clients resend their whole history every turn,
folded images included, so a fold that removed hundreds of screenshots from the
wire left the inbound body untouched: the reserve kept charging for pixels
nobody would be billed for, the meter read several hundred percent of the
window, and the nudge emergency-suppressed the very folds that would have
shrunk the payload. Production trace (a screenshot-heavy session): usage=863%
with a 196KiB outbound body, and three consecutive upstream 400s at ~1.75M
tokens against a 1.5M ceiling.

Learning already measures the OUTBOUND body — noteForwardedImageFacts is fed
countImagesInRawBody(wireBody) in relay.ts and loop/core.ts — so consuming the
inbound body on the read side was an asymmetry, not a design.

outboundImageReserve() walks prune(msgs, session.state) and charges each
surviving image through the same base64ImageCost() the wire-body estimators use
(now exported), then applies the same learned-truth cap imageReserveFor does.
It returns 0 when no image survives — the honest reserve for a text-only wire.
All four prepare paths (anthropic, openai, responses, google) now feed it to
effectiveTokenCount instead of imageReserveFor(parsed).

The two calibers agree exactly when nothing is folded, so the change is inert
on unfurled sessions; a fold can only shrink the reserve, never grow it.

Side effect worth noting: prepare-anthropic feeds the same number to
projectThinkingMass, whose gap is providerInputTokens - local - overhead -
imageTokens. A smaller image mass widens that gap, so more of the residual is
attributed to signature-only thinking blocks. That residual is genuinely the
billed-but-invisible thinking mass, so the attribution moves in the correct
direction.
…ranxianglei#3952 was an unrelated closed PR)

Review-side fix on this branch: the suite pins ranxianglei#4060's outbound image-reserve
caliber, so it is named issue4060-outbound-image-reserve.test.ts (repo
convention: tests/<issueNNNN>-*.test.ts). No behavior change.
…edia shapes

Remote-URL images and redacted_thinking payloads are priced by the
inbound body walker but carry no indexable image bytes in the pruned
outbound view, so the metering reserve shrinks for them even without a
fold. Pins the documented scope of the no-fold equality claim (inline
base64/data-URL images); overflow stays backstopped by preflight, which
prices these shapes through the body walker on the actual forward body.
…erve comment

ranxianglei#3952 is an unrelated closed PR (split-brain log observability); the
regression this code implements is named after its own issue.
…e parameter

The third argument now receives the OUTBOUND image reserve
(outboundImageReserve) from all four prepare paths, not an inbound-body
measurement — the old inboundImageTokens name describes the value this
PR stops passing.
@ranxianglei
ranxianglei force-pushed the 2026-10-20_outbound-image-reserve branch from e6fa022 to 2406d42 Compare October 21, 2026 02:05
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI 红了不是这个 PR 的代码问题,是分支基线太旧(stale-base)。我已把 PR 干净地变基到当前 master 并推回,本地定向验证全绿,等你这边 CI 跑完确认即可。

发生了什么:三个 test 分片全挂在同一对 #3769 存储测试上——tests/issue3769-pooled-bare-load.test.ts 和 tests/issue3769-upgrade-compat.test.ts——跟本 PR 改的图片预留计费完全无关。关键点:这对测试文件在 PR 的原始 head 里根本不存在,是 master 后来才加的;CI 按「PR head 合入 master」跑,所以 master 上的新测试会跑到这个 PR 上。失败那次 run(UTC 10-20 23:53)时,master 刚加了这些测试和源码修复(765abe369 seed pooled-envelope walk),但专门给这俩套件修 CI hermeticity 的那笔 602996bc2 还没进 master(它 UTC 10-21 01:37 才落)。所以那次 run 正好撞进「测试已加、hermeticity 未落」的窗口。现在 master 已含全部 4 笔 #3769 修复。

我做的:把 PR 变基到当前 master tip 56a0f5a46,零冲突,PR 自己的 6 个提交原样线性叠在最上面。本地过门:build ✓、typecheck ✓、定向跑 tests/issue4060-outbound-image-reserve.test.ts + 那两对 #3769 套件 = 10/10 pass。用 force-with-lease(锁死原 head e6fa02255 才推,没覆盖任何新东西)推回 fork 分支,PR head 现在是 2406d4286,CI 已重新触发。

结构化结论(八问):

  1. 是什么问题:PR 的 CI 三个分片红,但红的是 master 上与本 PR 无关的 #3769 存储水合测试,不是图片预留改动本身。
  2. 什么原因导致:分支基线停在 150 个提交之前;master 其后陆续落了 4 笔 #3769 修复(含一笔专门修 CI hermeticity 的),而失败那次 run 恰好落在「测试已加、hermeticity 未落」的时间窗内。属 stale-base,非本 PR 回归。
  3. 影响范围与严重程度:仅这一个 PR 的 CI 状态受影响;对用户/运行时无任何影响(本 PR 代码本就正确)。严重度=CI 误报红,不是功能缺陷。
  4. 怎么修复的:把 PR 变基到当前 master,让 PR 站在已含全部 #3769 修复的最新基线上;不改本 PR 任何一行逻辑。
  5. 是否有回归:无。变基零冲突;本 PR 只动 src/server/prepare-*、src/server.ts、src/image-tokens.ts + 新增一个测试文件,与存储/持久化路径正交;build+typecheck+定向测试全绿。高危模式逐项过:无语义漂移、无 fail-fast→吞错、无阈值/时序/输出格式变化。
  6. 是否破坏缓存:不涉及(纯基线更新,未触碰任何缓存/重试/游标/去重键逻辑)。
  7. 是否改了设计方向:不涉及(无架构/边界/数据流转向)。
  8. 是否引入新配置:不涉及(无新 env/config/默认值)。

判定:可以等 CI 转绿后合并。若你希望我顺带做点别的(补说明、拆 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 dsh p1 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(wiring): the image reserve is charged on the inbound body, so folds never lower the meter and the nudge suppresses them

2 participants