From 990cbe86fd049b23d8718bce1c7bfbc14d4c4e63 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sun, 11 Oct 2026 01:03:51 +0800 Subject: [PATCH 1/2] fix(#2699): remove stale stripImages references from image-request-budget test #2688 removed compress.stripImages/stripImagesKeepRecent from CompressSettings, but #2613's image-request-budget test (merged after #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. --- tests/image-request-budget.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/image-request-budget.test.ts b/tests/image-request-budget.test.ts index 20735351eb..a77a1e5485 100644 --- a/tests/image-request-budget.test.ts +++ b/tests/image-request-budget.test.ts @@ -46,7 +46,7 @@ async function fixture(run: (base: string, opts: ProxyOptions, calls: Buffer[]) }, modelContextLimit: 400_000, kernelConfig: defaultConfig(400_000), - compress: { injectTool: true, injectNudge: true, stripImages: true, stripImagesKeepRecent: 1 }, + compress: { injectTool: true, injectNudge: true }, promptCache: { routing: "auto" }, sessionHeader: "x-acp-session", log: false, @@ -106,10 +106,9 @@ test("gzip history above 100 MiB reaches explicit image reduction and preserves }); }); -test("disabled stripping never silently drops images: rebuilt over-budget requests stop with a forward-stage 413", async () => { - await fixture(async (base, opts, calls) => { - opts.compress.stripImages = false; - const r = await send(base, largeBody(false), "large-no-strip"); +test("rebuilt over-budget requests stop with a forward-stage 413 without contacting upstream", async () => { + await fixture(async (base, _opts, calls) => { + const r = await send(base, largeBody(false), "large-over-budget"); assert.equal(r.status, 413); const error = await r.json() as { error: { stage: string; type: string } }; assert.equal(error.error.stage, "forward"); From b0d5119874e19f42cabd2688df351d6f8619b3de Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sun, 11 Oct 2026 01:18:32 +0800 Subject: [PATCH 2/2] fix(#2698): adapt the two runtime-red budget tests + doc to post-#2688 semantics Supplement to 990cbe86f (which fixed only the tsc errors): under post-#2688 semantics there is no wire-side image reduction left, so the two tests that asserted the removed stripImages recovery path (200 + reduced rebuilt body) fail at runtime with the forward-stage 413. Adapt them to assert the actual contract: over-budget rebuilt bodies stop at stage=forward / request_too_large without touching upstream, whether images sit in messages or tool outputs; the admission-slot flow ends at the same forward guard once a slot is released. Also fix reference/request-body-budget.md (en+zh), which still told users to configure the removed compress.stripImages. Verified locally: tsc --noEmit clean; node --import tsx --test --test-concurrency=1 tests/image-request-budget.test.ts tests/request-body-budget.test.ts -> 10/10 pass. --- reference/request-body-budget.md | 6 +++--- tests/image-request-budget.test.ts | 31 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/reference/request-body-budget.md b/reference/request-body-budget.md index 27044216a5..8ae55d1934 100644 --- a/reference/request-body-budget.md +++ b/reference/request-body-budget.md @@ -10,10 +10,10 @@ HTTP model requests have three separate byte boundaries: Only two requests whose decoded body crosses 100 MiB may be active in one proxy process. A third receives 503 `request_body_busy`, `stage: decode`, `Retry-After: 1`, without being forwarded. Its slot is released on completion or cancellation. Ordinary requests do not use these slots. The limit bounds the **additional large decoded payloads**, not total process RSS: buffers, JSON parsing, session state and ordinary concurrent requests also consume memory. Streaming codecs stop on cancellation and enforce the cap while decoding; synchronous zstd can only observe cancellation at its synchronous checkpoints. -This permits a gzip / zstd / Brotli-compressed history slightly above 100 MiB to reach existing explicit reductions. It does not enable `compress.stripImages` or image compression. If the rebuilt body remains over 100 MiB, it is refused; retries cannot bypass the send guard. Already-started SSE responses deliver the failure through the existing error channel instead of changing committed headers. Budget diagnostics report sizes/stages, without request text or pixels. +This permits a gzip / zstd / Brotli-compressed history slightly above 100 MiB to cross the receive boundary and reach the rebuild pipeline. The byte budget itself performs no reduction: `stripImages` was removed (#2688) — image mass is now reduced by default media folding (#2640), which replaces large image payloads with placeholders the model can restore via `decompress({imageRef})`. If the rebuilt body is still over 100 MiB, the forward-stage 413 tells the user to fold image-bearing history first; retries cannot bypass the send guard. Already-started SSE responses deliver the failure through the existing error channel instead of changing committed headers. Budget diagnostics report sizes/stages, without request text or pixels. -Configure the existing `compress.stripImages` / `compress.stripImagesKeepRecent` policy only when historical-image removal is appropriate. The recent setting counts **messages**, not individual images. Existing image-archive / retrieval behavior, including its failure limitations, is unchanged; this is not a lossless-image lifecycle repair. Passthrough-marked or unrecognized compressed requests keep their original bytes and the raw 100 MiB limit. Uncompressed HTTP bodies above 100 MiB and WebSocket limits are unchanged. Byte limits do not replace model token-window checks or establish an upstream's accepted maximum. +There is no byte-budget policy knob left to configure for historical-image removal. Existing image-archive / retrieval behavior, including its failure limitations, is unchanged; this is not a lossless-image lifecycle repair. Passthrough-marked or unrecognized compressed requests keep their original bytes and the raw 100 MiB limit. Uncompressed HTTP bodies above 100 MiB and WebSocket limits are unchanged. Byte limits do not replace model token-window checks or establish an upstream's accepted maximum. HTTP 请求分成三道字节边界:原始接收 100 MiB;已识别模型协议每层解压最多 200 MiB;重建后发送正文最多 100 MiB。只有两个超过旧解压上限的请求能同时占用名额,第三个在解压阶段返回可重试的 503,完成或取消后释放。该名额限制额外超大正文,不是整个进程的 RSS 上限。 -此修复让略超旧限制的压缩历史进入已有、显式开启的减量流程,不会自动删除图片或开启缩图。减量后仍过大时,在正式上游发送前拒绝;流已经开始时使用现有错误事件。历史图片保留策略仍由 `stripImages` 与 `stripImagesKeepRecent` 决定,后者计数单位是消息。原图归档失败等既有生命周期问题另行处理,不能把本修复视为无损恢复保证。未压缩大正文、WebSocket、透传行为和模型 token 窗口保持原有边界。 +此修复让略超旧限制的压缩历史越过接收边界进入重建管线。字节预算本身不做任何减量:`stripImages` 已移除(#2688),图片体量改由默认媒体折叠(#2640)处理——大图片被替换为占位符,模型可用 `decompress({imageRef})` 取回原图。重建后仍超限时,forward 阶段返回 413,提示先折叠含图历史;重试不能绕过发送守卫。流已经开始时使用现有错误事件。原图归档失败等既有生命周期问题另行处理,不能把本修复视为无损恢复保证。未压缩大正文、WebSocket、透传行为和模型 token 窗口保持原有边界。 diff --git a/tests/image-request-budget.test.ts b/tests/image-request-budget.test.ts index a77a1e5485..fd4b5c88e4 100644 --- a/tests/image-request-budget.test.ts +++ b/tests/image-request-budget.test.ts @@ -90,19 +90,17 @@ async function send(base: string, body: Buffer, session: string, headers: Record return fetch(`${base}/responses`, { method: "POST", headers: { "content-type": "application/json", "content-encoding": "gzip", "session-id": session, ...headers }, body: new Uint8Array(body) }); } -test("gzip history above 100 MiB reaches explicit image reduction and preserves recent images, including tool screenshots", async () => { +test("over-budget rebuilt bodies stop at the forward-stage byte budget without touching upstream, whether images sit in messages or tool outputs", async () => { await fixture(async (base, _opts, calls) => { for (const tool of [false, true]) { - const r = await send(base, largeBody(tool), `large-strip-${tool}`); - assert.equal(r.status, 200, await r.text()); - const body = JSON.parse(calls.at(-1)!.toString("utf8")) as { input: unknown[] }; - const text = JSON.stringify(body.input); - assert.equal(text.split('"input_image"').length - 1, 1); - assert.ok(text.includes("old screenshot")); - assert.ok(text.includes(recentImage.image_url)); - assert.ok(calls.at(-1)!.length < MAX_REQUEST_BYTES); + const r = await send(base, largeBody(tool), `large-forward-${tool}`); + assert.equal(r.status, 413); + const error = await r.json() as { error: { stage: string; type: string; message: string } }; + assert.equal(error.error.stage, "forward"); + assert.equal(error.error.type, "request_too_large"); + assert.match(error.error.message, /reduce historical images or content before retrying/); } - assert.equal(calls.length, 2); + assert.equal(calls.length, 0); }); }); @@ -117,13 +115,13 @@ test("rebuilt over-budget requests stop with a forward-stage 413 without contact }); }); -test("third large decode gets retryable admission error, then succeeds after a slot is released", async () => { +test("third large decode gets retryable admission error, then hits the forward-stage budget once a slot is released", async () => { await fixture(async (base, _opts, calls) => { const a = new DecodedRequestAdmission(), b = new DecodedRequestAdmission(); const compressed = largeBody(false); a.observe(MAX_REQUEST_BYTES + 1); b.observe(MAX_REQUEST_BYTES + 1); try { - const r = await send(base, compressed, "busy-strip"); + const r = await send(base, compressed, "busy-large"); assert.equal(r.status, 503); assert.equal(r.headers.get("retry-after"), "1"); assert.equal((await r.json() as { error: { stage: string } }).error.stage, "decode"); @@ -132,9 +130,12 @@ test("third large decode gets retryable admission error, then succeeds after a s assert.equal(small.status, 200, await small.text()); assert.equal(calls.length, 1, "normal traffic must not use the large-body slots"); a.release(); - const ok = await send(base, compressed, "busy-strip-retry"); - assert.equal(ok.status, 200, await ok.text()); - assert.equal(calls.length, 2); + const again = await send(base, compressed, "busy-large-retry"); + assert.equal(again.status, 413); + const error = await again.json() as { error: { stage: string; type: string } }; + assert.equal(error.error.stage, "forward"); + assert.equal(error.error.type, "request_too_large"); + assert.equal(calls.length, 1, "the over-budget retry must not reach upstream either"); } finally { a.release(); b.release(); } }); });