From 9477a0d275280c4bd8db70233c5e2dd1ba7d6b3d Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 18 Nov 2026 14:03:58 +0800 Subject: [PATCH 1/2] fix: classify proxy tool results by structured outcome, not just the FAILED keyword MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first-line "FAILED" classifier misclassifies both directions: a successful compression summary that quotes an earlier FAILED result is read as a failure (false positive), and a genuine tool failure whose first line lacks the keyword — e.g. decompress not-found returning "[Block X not found]" with outcome:"failure" — is read as success (false negative). The latter makes a failed-only round re-request until the loop limit (10 upstream calls). The dispatcher already computes a structured outcome (applied/partial/refused for compress, success/failure for every other tool) but dropped it when pushing to proxyResults. Carry the outcome through and make it authoritative at the five control-flow sites: a compress is failed iff refused, every other tool iff failure. The first-line FAILED check remains only as the legacy fallback when no outcome is present. Behavior change: tool failures without "FAILED" on the first line (e.g. decompress not-found) now classify as failed. A failed-only round ends the turn when visibility markers are off (instead of re-requesting) and splices a recovery receipt when they are on — consistent with how a failed compress is already handled. compress applied/partial + decompress/absorb success/failure map identically to the first-line behavior; no other change. Fixes #5383 --- src/loop/core.ts | 33 +++++++++++++++++------------ tests/plugin-protocol.test.ts | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/loop/core.ts b/src/loop/core.ts index 269bb7a600..a82c50a705 100644 --- a/src/loop/core.ts +++ b/src/loop/core.ts @@ -33,7 +33,7 @@ import { applyRanges } from "../stream.js"; import { applyConfiguredCompression } from "../external-summary-compress.js"; import { executeAcpRetire, executeAcpRestore, executeAcpRewrite, effectiveBlockOpsConfig } from "../acp-block-ops.js"; import { executeSearchContextTarget, resolveDecompress } from "../decompress-shared.js"; -import { toolFail, toolOk, type ProxyToolResult } from "../proxy-tool-result.js"; +import { toolFail, toolOk, type ProxyToolResult, type ToolOutcomeKind } from "../proxy-tool-result.js"; import { fetchWithRetry, UpstreamHttpError } from "../fetch-util.js"; import { noteUpstreamThrottle429, noteUpstreamThrottleResolved, throttle429ModelScope } from "../upstream-throttle.js"; import { classifyUpstreamFailure, type SkippedProxyInfo, type UpstreamFailureKind } from "../upstream-fail.js"; @@ -195,11 +195,18 @@ function isReasoningRequiredError(e: unknown): boolean { return e instanceof UpstreamHttpError && /must be passed back/i.test(e.body); } -function proxyToolResultFailed(result: string): boolean { - // A successful compression receipt embeds the model-authored summary in later fingerprint - // lines. That summary may legitimately quote an earlier FAILED tool result; only the status - // line is authoritative for whether this tool call itself failed. - return (result.trimStart().split("\n", 1)[0] ?? "").includes("FAILED"); +function proxyToolResultFailed(pr: { name: string; outcome?: ToolOutcomeKind; result: string }): boolean { + // #5383: the structured outcome is authoritative when the dispatcher carries + // it — a compress is "failed" only when refused (applied/partial both folded + // something); every other tool fails on "failure". Only when no outcome is + // present do we fall back to the first status line: a successful compression + // receipt embeds the model-authored summary in later fingerprint lines, which + // may legitimately quote an earlier FAILED result, so the whole body is not + // authoritative for whether this call itself failed. + if (pr.outcome !== undefined) { + return pr.name === "compress" ? pr.outcome === "refused" : pr.outcome === "failure"; + } + return (pr.result.trimStart().split("\n", 1)[0] ?? "").includes("FAILED"); } // #1453 client-facing labels for transport failures that end the turn in-band. @@ -1426,7 +1433,7 @@ export async function* runCompressLoop( let realCalls = 0; const realToolCalls: ToolCallEmit[] = []; - const proxyResults: { name: string; callId: string; result: string; arguments: string; wireArguments: string; signature?: string; image?: { base64: string; mediaType: string } }[] = []; + const proxyResults: { name: string; callId: string; result: string; outcome?: ToolOutcomeKind; arguments: string; wireArguments: string; signature?: string; image?: { base64: string; mediaType: string } }[] = []; // #5220: the marker lines ACTUALLY streamed to the client this round // (deduped, same order as the stream). On a failed-only round this IS // the recovery receipt the retry body must carry — reconstructing it @@ -1457,7 +1464,7 @@ export async function* runCompressLoop( parsedArgs = {}; } const result = await withSessionLock(ctx.session, () => executeProxyToolAsync(call.name, parsedArgs, ctx, call.callId, rawArgs, signal)); - proxyResults.push({ name: call.name, callId: call.callId, result: result.text, arguments: call.arguments, wireArguments: rawArgs === undefined ? call.arguments : MALFORMED_PROXY_TOOL_ARGS_REPLAY, signature: call.signature, ...(result.image ? { image: result.image } : {}) }); + proxyResults.push({ name: call.name, callId: call.callId, result: result.text, outcome: result.outcome, arguments: call.arguments, wireArguments: rawArgs === undefined ? call.arguments : MALFORMED_PROXY_TOOL_ARGS_REPLAY, signature: call.signature, ...(result.image ? { image: result.image } : {}) }); if (ctx.visibilityMarkers !== false) { const markerKey = `${call.name}\u0000${result.text}`; if (seenMarkers.has(markerKey)) { @@ -1650,7 +1657,7 @@ export async function* runCompressLoop( if (threadContinue) threadDelta.push(injection); } const anyCompressFailed = proxyResults.some( - (pr) => (pr.name === "compress" || pr.name === "decompress") && proxyToolResultFailed(pr.result), + (pr) => (pr.name === "compress" || pr.name === "decompress") && proxyToolResultFailed(pr), ); if (!ctx.textProtocol && !anyCompressFailed) { const hidden = hideConsumedCompressCalls(ctx.session.state, coreMessages, ctx.config.isCompressTool); @@ -1670,7 +1677,7 @@ export async function* runCompressLoop( const absorbName = activeAbsorbToolName(ctx.session, ctx.config); if ( ctx.refreshFolded && - proxyResults.some((pr) => (pr.name === "compress" || pr.name === absorbName) && !proxyToolResultFailed(pr.result)) + proxyResults.some((pr) => (pr.name === "compress" || pr.name === absorbName) && !proxyToolResultFailed(pr)) ) { try { const refreshed = await ctx.refreshFolded(coreMessages); @@ -1759,7 +1766,7 @@ export async function* runCompressLoop( // carry server-invisible bytes upstream — exactly the seam #4186 // forbids. const failedMutating = proxyResults.filter( - (pr) => (pr.name === "compress" || pr.name === "decompress") && proxyToolResultFailed(pr.result), + (pr) => (pr.name === "compress" || pr.name === "decompress") && proxyToolResultFailed(pr), ); if (!probeWarned) { @@ -1880,14 +1887,14 @@ export async function* runCompressLoop( let committedTokens = 0; let committedBlocks = 0; for (const pr of proxyResults) { - if (pr.name === "compress" && !proxyToolResultFailed(pr.result)) { + if (pr.name === "compress" && !proxyToolResultFailed(pr)) { const saved = /~(\d[\d,]*) tokens saved/.exec(pr.result); if (saved) committedTokens += Number(saved[1]!.replace(/,/g, "")); const blocks = /(\d+) block\(s\)/.exec(pr.result); if (blocks) committedBlocks += Number(blocks[1]); } } - const absorbed = proxyResults.some((pr) => pr.name === activeAbsorbToolName(ctx.session, ctx.config) && !proxyToolResultFailed(pr.result)); + const absorbed = proxyResults.some((pr) => pr.name === activeAbsorbToolName(ctx.session, ctx.config) && !proxyToolResultFailed(pr)); const note = committedTokens > 0 ? `compression committed (~${committedTokens.toLocaleString("en-US")} tokens saved${committedBlocks > 0 ? ` in ${committedBlocks} block(s)` : ""}); ` : absorbed ? "context work committed; " : ""; diff --git a/tests/plugin-protocol.test.ts b/tests/plugin-protocol.test.ts index ead40e5411..cb19813278 100644 --- a/tests/plugin-protocol.test.ts +++ b/tests/plugin-protocol.test.ts @@ -84,6 +84,25 @@ function compressToolScript(summary = "plugin e2e compress summary with enough c ]; } +function decompressToolScript(blockId = "synthetic-missing-block"): string[] { + const decompressArgs = JSON.stringify({ blockId }); + return [ + anthropicSse("message_start", { + type: "message_start", + message: { id: "msg_plug_3", role: "assistant", usage: { input_tokens: 55 } }, + }), + anthropicSse("content_block_start", { + type: "content_block_start", + index: 0, + content_block: { type: "tool_use", id: "toolu_d_1", name: "decompress", input: {} }, + }), + anthropicSse("content_block_delta", { type: "content_block_delta", index: 0, delta: { type: "input_json_delta", partial_json: decompressArgs } }), + anthropicSse("content_block_stop", { type: "content_block_stop", index: 0 }), + anthropicSse("message_delta", { type: "message_delta", delta: { stop_reason: "tool_use", stop_sequence: null }, usage: { output_tokens: 12 } }), + anthropicSse("message_stop", { type: "message_stop" }), + ]; +} + async function startHarness( scripts: string[][], kernelConfig?: Config, @@ -901,6 +920,27 @@ test("a successful compression summary containing FAILED still continues with ma } }); +test("a genuine decompress failure without the FAILED keyword is classified as failed", async () => { + const h = await startHarness([decompressToolScript("synthetic-missing-block")], undefined, { visibilityMarkers: false }); + try { + const { raw } = await callPluginAnthropic(h, "plug-conv-decompress-notfound", sizedPluginHistory(), { + agent: "hermes", + tools: ["tool_search", "tool_describe", "tool_call"].map((name) => ({ + name, description: `Hermes ${name}`, input_schema: { type: "object", properties: {} }, + })), + compressionProxy: true, + }); + + // A not-found decompress returns outcome:"failure" with no "FAILED" on the first + // line. With the structured outcome it is classified as failed, so a failed-only + // round with visibility markers off ends the turn instead of re-requesting (the + // pre-fix first-line classifier saw no FAILED and re-requested a second time). + assert.equal(h.captured.length, 1, `a genuine decompress failure must be classified as failed and end the turn; raw=${raw}`); + } finally { + await h.close(); + } +}); + // Hermes defers plugin toolsets through tool_search, so a healthy plugin session sends requests // whose tools array carries NONE of the ACP names. Those requests must still bind the plugin // identity and budget (that is exactly what /acp reads) while compression falls back to the proxy — From 0757ec1bd6e6ff04125c8d6dd609cf77f483acd8 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 18 Nov 2026 23:03:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(test):=20#564=20path=202=20=E2=80=94=20?= =?UTF-8?q?shorten=20the=20summary=20so=20the=20compress=20actually=20shri?= =?UTF-8?q?nks=20(#7124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test compresses m00004-m00005 (~6 tokens) with a 24-char summary (~6 tokens); the no-net-shrink gate (src/stream.ts) refuses a compress whose summary is not strictly smaller than the range (net delta <= 0), so the compress was refused (outcome:refused). Pre-#7124 the first-line FAILED classifier missed it (the refused receipt's first line says 'refused', not 'FAILED'), so the test passed; #7124 makes the structured outcome authoritative, so the refused compress is now correctly failed and refreshFolded no longer runs. Shorten the summary to 'ok' (1 token) so the compress succeeds and the test exercises the post-compress re-request view it was written for. --- tests/issue564-responses-ordering.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/issue564-responses-ordering.test.ts b/tests/issue564-responses-ordering.test.ts index 25ba088981..c90a970aab 100644 --- a/tests/issue564-responses-ordering.test.ts +++ b/tests/issue564-responses-ordering.test.ts @@ -160,7 +160,7 @@ test("#564 path 2: compress re-request keeps Responses assistant run ordering va const endRef = refOf(fcoA!); assert.ok(startRef && endRef, "refs resolved for the bash_a interaction"); - const args = JSON.stringify({ content: [{ startId: startRef!, endId: endRef!, summary: "Inspected files A and B." }] }); + const args = JSON.stringify({ content: [{ startId: startRef!, endId: endRef!, summary: "ok" }] }); const round1 = [ sse("response.created", { response: { id: "resp_1", status: "in_progress" } }), fcEvents(0, "call_c", "compress", args),