diff --git a/src/runaway-guard.ts b/src/runaway-guard.ts index 0b08e349c3..06612e5171 100644 --- a/src/runaway-guard.ts +++ b/src/runaway-guard.ts @@ -110,9 +110,16 @@ const TEXT_LEAF_KEYS: ReadonlySet = new Set([ "content", "text", "thinking", "reasoning", "reasoning_content", "delta", ]); // Branches whose strings are NEVER model output. Tool-call arguments are user intent -// (#1039): a write-tool payload of 300 '=' must not abort the turn. +// (#1039): a write-tool payload of 300 '=' must not abort the turn. The exclusion is +// key-propagated, so every wire's argument container needs its own key here: openai +// chat tool_calls[].function.arguments ("arguments"), anthropic tool_use.input +// ("input"), responses function_call_arguments (skipped by event type in processParsed). +// Google has NEITHER a type field NOR an excluded container key — its calls ride +// parts[].functionCall.args with payload leaves named content/text (#3358: the #3946- +// class incident shape on the one wire the original list missed). const EXCLUDED_BRANCHES: ReadonlySet = new Set([ - "arguments", "input", "partial_json", "tool_calls", "tools", "functions", "system", + "arguments", "args", "parameters", "functionCall", "input", "partial_json", + "tool_calls", "tools", "functions", "system", "instructions", "metadata", "usage", "usageMetadata", "logprobs", "annotations", "error", "id", "url", ]); diff --git a/tests/runaway-guard.test.ts b/tests/runaway-guard.test.ts index 5c05027fa0..d8468e9428 100644 --- a/tests/runaway-guard.test.ts +++ b/tests/runaway-guard.test.ts @@ -195,3 +195,28 @@ test("wrapStreamWithRunawayGuard aborts on runaway: onTrip once, clean early EOF const forwarded = out.toString("utf8"); assert.match(forwarded, /^\x3cacp tokens="0" type="text">m02040\x3c\/acp$/m); }); + +// #3358 regression: Google-wire tool calls ride parts[].functionCall.args with payload +// leaves named content/text — argument bytes are user intent (#1039) and must never be +// counted by the text-run lane, exactly like openai arguments / anthropic input. +test("google functionCall.args with 300 identical chars does NOT trip the text-run lane", async () => { + const argRun = "=".repeat(300); + const body = JSON.stringify({ candidates: [{ content: { parts: [{ functionCall: { name: "write_file", args: { path: "/tmp/x", content: argRun } } }] } }] }); + const frame = `data: ${body}\n\n`; + const src = new ReadableStream({ start(c) { c.enqueue(enc.encode(frame)); c.close(); } }); + let tripped = false; + const out = await collect(wrapStreamWithRunawayGuard(src, () => (tripped = true))); + assert.equal(tripped, false, "tool-call argument run must not abort the turn"); + assert.equal(out.toString("utf8"), frame, "byte-exact forward"); +}); + +// Control for #3358: the SAME wire's genuine model output (parts[].text) must still trip. +test("google parts[].text with 250 identical chars still trips as text-run", async () => { + const textRun = "-".repeat(250); + const body = JSON.stringify({ candidates: [{ content: { parts: [{ text: textRun }] } }] }); + const frame = `data: ${body}\n\n`; + const src = new ReadableStream({ start(c) { c.enqueue(enc.encode(frame)); c.close(); } }); + let tripReason: string | undefined; + await collect(wrapStreamWithRunawayGuard(src, (v) => (tripReason = v.reason))); + assert.equal(tripReason, "text-run", "real model-output runs must still be caught"); +});