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
context ~696789 tokens exceeds the model window 272000 (model=gpt-6-astra)
Images alone account for ~584498 tokens (≥ window 272000); compression cannot remove them — shrink or remove the images, or raise the window.
The over-window payload was NOT forwarded.
Activity
ranxianglei commentedon Sep 14, 2026
[bot] 🏷 Triage 完成:问题已确认存在,根因分层已定位,开始实现,稍后开 PR。
验证(代码路径与你的复现一致):
src/server.ts:3104的 PR #489 后续: 默认图片计费 b64/4 在像素 tile 计费上游(官方 Anthropic/OpenAI)会硬 502 误杀多模态会话 #496 门控noOverflowEvidence = session.stats.lastInputTokens < limit && learnedLimit === undefined—— stale baseline 696789 > 窗口 272000 时,“让上游仲裁一次”的路径被关闭。payloadEstimate也推过窗口,fix: stitched-stream usage double-count after compress re-request (adapter-anthropic >0 guard) #300 的 stale-baseline 逃生口(src/server.ts:3132,payloadEstimate < limit时直接转发)同样不触发。层次判断:这里其实是两个独立缺陷叠加:
ceil(base64/4)对 pixel-tile 上游系统性高估数个量级——你的真实测量里两张原图上游只计费 2458 / 1910 tokens,而 base64/4 给出数十万。noOverflowEvidence——你要求保留的 PR #489 后续: 默认图片计费 b64/4 在像素 tile 计费上游(官方 Anthropic/OpenAI)会硬 502 误杀多模态会话 #496 “一次拒绝后阻断”保证原样保留。你的判断成立。方案(正在实现):
imageBilling: "auto" | "pixels" | "bytes":per-provider 配置 + 全局配置 + envBILI_IMAGE_BILLING(env 优先级最高)。auto:已知 first-party pixel-tile 上游(api.openai.com / chatgpt.com(含 backend-api/codex)/ api.anthropic.com 等)自动走 pixels;其他 relay 保持保守的 bytes 估算(多模态会话上下文控制失效 + preflight 救援 502(codex responses store:false) #488 行为不变)。pixels模式:解析 PNG/JPEG/WebP/GIF/BMP 头部拿真实尺寸(只解码前若干字节,不解全图),按 OpenAI high-detail tile 公式85 + 170×tiles估算(上限 2805/张);无法解析的格式回退到 16384 平值(即你验证过的值)。BILI_IMAGE_TOKEN_CAP继续作为全局 clamp 生效。lastInputTokens=696789/ 窗口 272000 + 两张大 base64 图 → 200、mock 上游收到 2 张图;usage 回报后 baseline 降回窗内,会话恢复)+ 各格式头部解析单测 + byte-relay 行为不变的断言(issue496 测试须继续通过)。你的临时修复(进程级
BILI_IMAGE_TOKEN_CAP=16384)可以保留到该版本发布;发布后官方 Codex 进程用默认auto(或显式"pixels")即可,不再需要 cap。ranxianglei commentedon Sep 14, 2026
[bot] 🏷 已修复,PR: #771
审核结论(先于实现):问题成立且已独立复现。层次判断——你定位的两条关闭路径都对,但根因在更上游一层:
noOverflowEvidence只是"旧 baseline 超窗"的症状传播器,真正的病因是src/image-tokens.ts对像素计费上游用 base64/4 计费,把 payloadEstimate 推过窗口,于是连 #300 的 stale-baseline 逃生口(要求payloadEstimate < limit)也一起失效。纯文本会话本来就能经 #300 自愈,只有带图请求被卡死——所以只修估算层就能同时恢复 stale-baseline 和 learned-limit-only 两个变体,无需动noOverflowEvidence,#496 对真实 byte-relay overflow 的"一次拒绝后阻断"保证原样保留(这正是你建议的方向)。改动:
imageBilling配置(全局 + 按 providerproviders.<url>.imageBilling),取值"auto" | "pixels" | "bytes";envBILI_IMAGE_BILLING覆盖两级、逐请求实时读取。优先级:env > per-provider > global > auto。pixels:只解析图片头(PNG/JPEG/WebP/GIF/BMP,有界解码,不解码整图)取真实尺寸,按 OpenAI high-detail tile 模型计费(512px tile、短边放大到 768、长边封顶 2048 → 每图 85+170×tiles = 765–2805 token);无法解析的格式回退固定 16384(高于两家第一方上限 OpenAI 2805 / Anthropic ~1534,又远低于任何 >64KB 内联图的 base64/4)。bytes保持默认,relay 保护不变;BILI_IMAGE_TOKEN_CAP仍在两种模式之上统一封顶;远程 URL 维持固定 4096。auto按上游 host 分类:openai.com/openai.azure.com/chatgpt.com/api.anthropic.com后缀 → pixels,其余 → bytes。官方 Codex 路由零配置即生效。验证:新增
tests/issue767-pixel-billing.test.ts(9 tests)——单测覆盖五种容器格式尺寸解析(含 JPEG SOF 跨 EXIF padding)、tile 公式边界、host 分类与显式覆盖、cap 交互;E2E 按你的复现步骤镜像(mock Responses upstream):stale baseline 696789 + 两张大 base64 截图,pixels下 200、两图原样转发、baseline 恢复到窗口内、后续轮次持续正常;同 payload 默认 bytes 下 502 fail-fast、0 张图到达上游(relay 保护钉死);另补了你提到未验证的 learned-limit-only 变体(同样关闭 forward-once)和 env 优先级。typecheck ✓ / 全量测试 1438 pass 0 fail ✓ / build ✓。文档已更新(CONFIGURATION.md + zh-CN + CHANGELOG)。发布后你可以把进程级的
BILI_IMAGE_TOKEN_CAP=16384去掉——官方 Codex 路由会自动按 tile 计费;想显式控制就设"imageBilling": "pixels"或BILI_IMAGE_BILLING=pixels。一句话总结:修复了像素计费上游上图片按字节高估导致旧 baseline 超窗后会话永久 502 的问题(新增 pixels/bytes 图片计费模式,auto 自动识别官方像素计费 host),已按你的复现步骤回归验证并保留 #496 阻断保证,PR #771 可合并。
fix(#767): resolve per-route imageBilling against the full upstream U…
Merge pull request #771 from ranxianglei/2026-09-14_pixel-image-billi…
fix(ranxianglei#767): image billing modes (pixels/bytes) end stale-ba…
fix: stop image estimates poisoning the usage baseline (ranxianglei#857)
feat(wire): protocol-stable canonical core identity (ranxianglei#3642)