You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
当仅图片就超过窗口时,fail-fast 错误信息会明确写出:Images alone account for ~N tokens (≥ window M); compression cannot remove them — shrink or remove the images, or raise the window.(你的场景:7 图 ~1.39M > 1.05M → 立刻得到可操作结论,而不是卡死。)
Activity
ranxianglei commentedon Sep 3, 2026
[bot] 🏷 开始处理 #488。两个问题都已核实存在,根因层次已定位,先报结论:
B. preflight 摘要调用 400(store:false)— 确认,修复明确
src/preflight.ts:148的summaryPayload()responses 分支构造的是{model, max_output_tokens, instructions, input, stream:false}—— 没有store字段。codex relay 要求 Responses 调用带store:false→ 400 → 摘要拿不到 → fail-fast 502。修复:preflight 的摘要请求加
store:false(仅 responses 协议;chat completions 没有该参数,加了反而可能破坏其他 provider)。主转发路径不受影响(codex 原始 body 原样透传,自带 store:false);compress-loop 重发复用客户端原始 body(spread),同样不受影响。所以改动面只有 preflight 这一处合成请求。A. 多模态 token 统计失真 — 确认,但根因比「usage 只统计文本」深一层
分层分析:
usage.input_tokens(含图片),只是滞后一轮——你看到的 9% 是图片加入前的基线,不是「从不触发」。estimateCoreMessages(src/preflight.ts:90)只数消息文本;而图片字节实际是完整转发的(wire codec 把图片放进 sidecar:imageBase64/rawResponsesItem/rawAnthropicBlock,转发时原样还原)。于是 preflight 的 fit 判定(result.payloadEstimate < limit,server.ts:2248)系统性低估 ~15×:误判「已低于窗口」→ 把超窗 payload 当安全放行 → 上游 400 → 死循环。这才是「上下文控制失效」的准确含义——不是压缩不触发,而是触发后判断失真、甚至假成功。修复方案(host 侧,不动 acp-kernel)
base64长度/4(与 bili 文本估算同一 chars/4 规则;也与你这个 relay 的实际计费吻合——7 张截图 ≈ 1.4M tokens 正是 base64 字符量级;若按 OpenAI 官方像素 tile 算法,7 张图最多 ~11K tokens,对不上你看到的 1.49M,可佐证该 relay 按字节计费);远程 URL(看不到字节)→ 固定保守值 4096。BILI_IMAGE_TOKEN_CAP(单图上限)供此类用户调低。若你认为默认方向应反过来(tile 优先 + 字节兜底),merge 前告诉我即可调整。正在实现,PR 链接稍后更新在本 issue。
ranxianglei commentedon Sep 3, 2026
[bot] 🏷 修复已完成,PR 已开:**https://github.com/ranxianglei/billion-context/pull/489**(分支
2026-09-03_multimodal-image-tokens-store-false,commitacd9dce)两个根因的落地修法
src/preflight.ts的summaryPayloadresponses 分支补上store: false。只影响 preflight 自己合成的摘要调用——主转发路径透传 codex 原始 body(自带 store:false)、compress-loop 重发是{...requestBody}展开,均不受影响。src/image-tokens.ts,从原始 wire body 直接统计图片份额(不依赖 kernel sidecar,也绕开了 kernel 对远程 URL 图片不捕获的既有缺陷),加进三处尺寸决策:preflight 触发判断、preflight 循环内每轮 fit 判断(新增imageFloor,折叠文本永远无法把图片字节"折没",杜绝"假成功→转发→400→死循环")、超窗自学习窗口。已知 base64 按ceil(b64长度/4)计(与 defaultCountTokens 的 chars/4 同规则,且符合你 relay 的实际计费——7 张截图 ≈1.4M tokens 排除了像素 tile 计费,后者上限只有 ~11K);无法测尺寸的远程 URL 按固定 4096 计。无图片的请求走字符串嗅探门,连 JSON.parse 都不会执行,纯文本会话零开销、零行为变化。Images alone account for ~N tokens (≥ window M); compression cannot remove them — shrink or remove the images, or raise the window.(你的场景:7 图 ~1.39M > 1.05M → 立刻得到可操作结论,而不是卡死。)验证
npm run typecheck✅npm test✅ 952/953 —— 唯一失败是launcher.test.ts的 codex 路径解析用例,在干净 master 上同样失败(本沙箱装了/usr/bin/codex),环境依赖,与本改动无关npm run build✅tests/fix-488-multimodal.test.ts):估算器单测 ×4(三协议 data URL / 远程 URL / 多图求和 / 解析门 / cap 钳制)+ e2e 回归 ×2:(B) 超窗恢复会话的 preflight 摘要请求确实带store:false且成功转发 200;(A) 7×15K token 图片 vs 10K 窗口 → 502preflight_compress_failed+ 上述 actionable 提示,上游零转发合并前留给你拍板的一点:默认计费模型取 b64 长度/4(匹配你报告里 relay 的行为)。如果你的上游是按像素 tile 计费(官方 Anthropic/OpenAI 那种),请设环境变量
BILI_IMAGE_TOKEN_CAP=<每图上限>钳制每图成本——不设的话这类上游会偏早触发压缩,但方向安全(宁早勿漏)。如无异议即可合并;按仓库规则我不会自行 merge。fix: count image bytes in payload-size decisions; keep store:false in…
Merge pull request #489 from ranxianglei/2026-09-03_multimodal-image-…
ranxianglei commentedon Sep 3, 2026
收尾:#489 已合并,随 v0.1.77 发布(release PR #497,合并后 CI 自动 publish)。两个根因(store:false、图片计入尺寸决策)均经第三方独立 review + 全量 codex e2e 鐘452s)验证。残留设计风险(b64/4 默认计费对像素 tile 计费上游的硬 502 误杀)已立案 #496 跟进。
fix: forward-once-then-learn for image-dominated payloads (ranxiangle…
docs: BILI_IMAGE_TOKEN_CAP env entries + ranxianglei#488/ranxianglei#489
fix: hold the client through long preflight compression (#568)
fix: judge anonymous zero-baseline forks by the char-count upper bound (
fix: hold the client through long preflight compression (#568)
fix: hold the client through long preflight compression (#568)
fix: hold the client through long preflight compression (#568)
feat: opt-in strip of historical image payloads (compress.stripImages)
fix: render explicit image placeholders in preflight summary input (r…
docs(#2011): correct fractional-source attribution in clampOutputBudg…
fix: stop double-counting image tokens in the output-budget clamp (#2558
fix: price codec-carried opaque media parts in size decisions (#3398)
fix: price codec-carried opaque media parts in size decisions (#3398)