Repository navigation
fix: 让压缩图片历史先减量,再检查发送字节预算 - #2613
Merged
ranxianglei merged 1 commit intoOct 10, 2026
Merged
Conversation
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.237-master.ae7d9c0 # this exact build
npm install -g billion-context@master # always the newest merged build
|
This was referenced Oct 10, 2026
Merged
YunzhouLi-hub
pushed a commit
to YunzhouLi-hub/billion-context
that referenced
this pull request
Oct 11, 2026
…-request-budget test ranxianglei#2688 removed compress.stripImages/stripImagesKeepRecent from CompressSettings, but ranxianglei#2613's image-request-budget test (merged after ranxianglei#2688) still referenced them, breaking master typecheck. Drop the dead keys from the fixture config and the inert stripImages=false toggle line; keep every assertion intact (over-budget rebuilt request -> forward-stage 413, no upstream contact). Zero behavioral change.
This was referenced Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
实际使用背景
这个问题来自 macOS 上通过 bili 代理 Codex Desktop agent 请求的一次多轮界面设计会话。图片、设计稿和工具截图不断进入历史,旧图片中的 data URL/base64 随请求携带,使 JSON 正文字节量逐渐增大。实际请求遇到了
413 decompressed request exceeds 104857600 bytes,拒绝发生在 JSON 解析、历史折叠和显式图片减量之前。离线按历史结构近似重建,得到以下量级:
这些是离线近似值,不是完整 HTTP 抓包的精确大小;没有导出真实聊天或图片。它们说明了触发机制:压缩正文可以通过 100 MiB 接收上限,解压后却略超同一上限,于是在已有减量策略有机会执行之前就被拒绝。即使操作者显式启用了
stripImages,也无法到达该处理阶段。去掉 data URL 的对照仅用于理解字节来源,不代表本 PR 会默认丢弃图片。用户需要的是受限处理空间,而非无限放大请求上限:在保留原始接收与最终发送 100 MiB 边界的前提下,让已识别的压缩请求在有硬上限、并发限制和取消处理的空间内进入现有减量流程。只有显式减量或历史折叠能将最终正文降到发送预算内时才允许转发;否则仍明确拒绝。此处的 413 属于请求字节预算层,与 #2594 的模型 token 窗口对齐是不同约束,不承诺任意历史或原会话已经恢复。
问题与改动
压缩的图片历史解压后略超 100 MiB 时,旧入口在 JSON 解析和已有图片减量之前就返回 413;即使操作者已启用
stripImages,也到不了该策略。本 PR 将接收、解压处理和重建发送分开设限,让显式减量有机会执行,同时保持原始接收与最终发送的 100 MiB 边界。Fixes #2606
行为和实现
request_body_busy/stage: decode/Retry-After: 1stage: forwardrequest-body-budget.ts集中内部字节预算和大请求名额;普通请求不占名额。fetchWithTimeout在 fetch 和 watchdog 分配前检查 string/Buffer,防止后续重发绕过发送预算。回归证据
新增 10 个测试,使用合成数据和隔离状态目录;未导出真实聊天/图片,未调用外部模型。
红绿对照:从未修复上游
e1cd9e11c618fd4376803a415144f4a35d6ad057的 archive 运行同一个 gzip 历史 HTTP 回归。旧 HTTP/解码路径保持原样,只复制测试及其引用的未接入旧运行路径的预算 helper。断言在旧版明确失败:413 !== 200,错误为decompressed request exceeds 104857600 bytes;修复版通过。不是 import/依赖失败,也不是逐字节真实聊天抓包。最终验证
9ab9d400aa01d648966cf2b5d920caf96476823b;最终 head:92fb3d08c47eeaf0b53763d4fd4a7c764f33e6b5。npm run typecheck:通过。npm test:5358 项,5330 通过,0 失败,28 跳过。npm run build:通过;dist-import-annotations:OK;构建产物标记为92fb3d08。git diff --check通过。E2E_CHECK=1:CLI/dist 可用,但http://127.0.0.1:8199/v1的 models 接口不可达;真实外部模型ACP_TEST_E2E四阶段未执行。059d67c7e9c5b3e7f9f9c03bfe99ce73c6f5fb0a(6 个提交),变更是模型发现/窗口对齐及文档;handle 中的对齐变更不触及本 PR 的解码预算区域。git merge-tree --write-tree upstream/master HEAD无冲突。以上本地验证对应固定基线/head,不冒充后续合并树的验证。实际限制