Skip to content

fix: runaway text guard no longer reads Google tool-call arguments as model output - #3357

Merged
ranxianglei merged 2 commits into
masterfrom
fix/runaway-guard-google-args-exclusion
Oct 16, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
fix/runaway-guard-google-args-exclusion

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

ai: zhipuai-lb/glm-5.3

什么坏了

模型在 Google(Gemini)线路上调用写文件类工具、参数里带 200 个以上连续相同字符(比如生成文件时的一排 = 或 - 分隔线)时,整个回答会被流式熔断器中途掐断——用户看到回复突然截断,工具调用没执行完。这是 #3260 引入 text-run 熔断时漏掉的线束。

根本原因

src/runaway-guard.ts 的 EXCLUDED_BRANCHES 缺 args/functionCall 两个分支名:

  • OpenAI 线束的工具参数在 delta.tool_calls[].function.arguments(arguments 已排除)、Responses 线束在 partial_json(已排除)且有 `type: "function_call" 帧门;
  • Google 线束的工具调用长在 candidates[].content.parts[].functionCall.args 下,事件没有顶层 type 字段,帧门帮不上忙;参数载荷字段又常叫 content,恰好命中 TEXT_LEAF_KEYS → 被当成模型文本喂给 200 阈值的单字符 run 计数 → 合法 turn 被当失控输出掐掉。

src/server/relay.ts 给所有流式响应包了这个守卫,默认开、无开关,所以 Google 线路全部用户都会踩。

这也修正了 #3344 里「runaway 200 码点阈值理论误伤(工具参数已豁免,不建议动)」的结论:豁免只对 OpenAI 线束成立,Google 线束没有豁免,是实际会发生的误杀,不是理论项。

修复

EXCLUDED_BRANCHES 增加 args、functionCall、parameters(与既有 arguments/input/partial_json 同类)。

测试

tests/issue3260-text-run-guard.test.ts 补两个方向:

  1. Google 线 functionCall.args 内 300 个 = 不熔断、字节原样转发;
  2. 同一线束 parts[].text(真正的模型文本)300 个 = 仍熔断——证明排除范围没有吞掉模型正文。

本地:tests/issue3260-text-run-guard.test.ts 19/19、tests/runaway-guard.test.ts 11/11、tsc --noEmit 干净。

Refs #3331 (E-1), #3344


(ai: vllm-qwen/qwen3.8-27b) 审核更新: 后到的重复 PR #3375(~1 小时后的同一修复)已按先来后到关闭为重复;其独有的两个回归用例(args.text 第二叶子拼写、混合 prose+arg 帧字节原样)已移植为本分支的附加 commit(d686c80)。分支已 rebase 到当前 master(745be9f)。

Closes #3358

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/runaway-guard-google-args-exclusion (d686c80)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3982-pr.3357.bd4e290

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3357.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复。 同机制家族的相关条目:#3289(引入 text-run 熔断车道,已合并)、#3317(#3289 误伤测试夹具导致 CI 红,已合并)、#3260/#3331(E-1)/#3344(需求与结论来源)。本 PR 是该护栏机制上一处独立的缺陷修复(Google 线束豁免缺失),症状、机制、根因均与上述条目不同,无重复。

审核结论:可合(等剩余两个 CI 车道跑完)

以下结论是我独立复核产出的,不是照抄 issue 分析:

机制验证:src/runaway-guard.ts 的 collectText 排除逻辑按「键名逐层向下传播」生效。Google 流式块 candidates[].content.parts[].functionCall.args.content 修复前的走查:functionCall/args 不在排除表 → 叶子键 content 命中 TEXT_LEAF_KEYS → 300 个 = 喂进 200 阈值计数 → 误杀;且 Google 事件无顶层 type,Responses 线束依赖的 function_call 帧门确实拦不到它。issue 描述与代码事实一致。

A/B 实测(worktree @ 2dc86eaca):

  • 回退到 master 版 src/runaway-guard.ts:新加的 Google args 用例失败(复现原 bug),对照组 parts[].text 用例通过(如预期);
  • 恢复 PR head:tests/issue3260-text-run-guard.test.ts 19/19、tests/runaway-guard.test.ts 14/14 全绿。
    测试有牙:回退即红,不是恒真断言;对照组同时钉住「排除范围不能吞掉模型正文」。

回归清点(diff 触碰路径的既有行为逐项过):acp-enumeration / tool-xml-flood 两条原始字节车道未触碰;OpenAI/Anthropic/Responses 线束既有豁免路径全部保持(既有 33 用例全过);字节原样转发契约由新用例的 deepEqual(out, Buffer.concat(parts)) 钉住。三条新排除键(args/functionCall/parameters)在 bili 会讲的所有响应流里都不承载模型正文,失败方向是漏报而非误杀,无真实检测覆盖损失。master 领先分支 9 个提交,但 src/runaway-guard.ts 与两个测试文件自分支点起零改动,GitHub mergeable=True,无需 rebase。

CI:ubuntu 22 三个 shard + static-gates 已绿,windows 22 / ubuntu 24 各一车道仍在跑,目前无红。

八问

  1. 是什么问题:Google(Gemini)线路模型调写文件类工具、参数里带 ≥200 个连续相同字符(如一排 = 分隔线)时,流式输出护栏把工具参数当成失控文本,把整个回答中途掐断、工具没执行完。
  2. 什么原因导致的:Add single-codepoint repetition lane to the output-side runaway guard (Closes #3260) #3289 引入 text-run 熔断时,「工具参数豁免」表(EXCLUDED_BRANCHES)只覆盖了 OpenAI 线束的键名(arguments/partial_json);Google 线束的工具调用长在 functionCall.args 下、载荷字段常叫 content(恰好是文本叶键名),又因 Google 事件无顶层 type 而绕过帧门——豁免在该线束上整体缺席。
  3. 影响范围与严重程度:所有走 Google 原生线路(bili gemini / antigravity 等)且触发写文件类工具、参数含长连续相同字符的用户;触发时该轮回答被截断——特定条件下的功能性故障,非全量不可用。
  4. 怎么修复的:把 args、functionCall、parameters 加入既有分支排除表,与 arguments/input/partial_json 同类处理——在判定源头(哪些子树算模型文本)补齐,不是在传输路上过滤字节,符合 [bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039「工具参数是用户意图」不变量。
  5. 是否有回归问题:无。两条原始字节车道未动;既有 33 用例全绿证明其余线束行为不变;对照组用例证明 parts[].text 模型正文仍会被熔断捕获;高危模式(语义漂移、fail-fast 变吞错、阈值漂移)逐项核对均不涉及。
  6. 是否破坏缓存:不涉及——纯响应侧检测器内部豁免表变更,不动请求、会话状态、压缩或缓存策略。
  7. 是否改了设计方向:不涉及。只把既有豁免纪律补到漏掉的线束,架构与数据流不变。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值。

行为变更披露:text-run 熔断的豁免范围从「OpenAI/Responses 线束的工具参数」扩大到「+Google 线束的 functionCall/args/parameters 子树」——这正是本 PR 的目的(消除误杀);200 阈值与其余行为不变。

判定:可合。 代码、测试、已完成 CI 车道均无问题,剩余两车道跑完即可由人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

补一条:剩余 CI 车道已全部跑完——test 六个 shard(ubuntu 22×3、ubuntu 24×1、windows 22×2)+ 全部 guard(static-gates / config-surface-guard / lane-guard / docs-sync / kernel-guard / lock-sync / build-artifact 等)全绿,门控 e2e 车道按预期 skip,无红。PR 现在可以合并了(人工操作):#3357

ranxianglei and others added 2 commits October 16, 2026 15:38
… model output

The #3260 text-run lane fed candidates[].content.parts[].functionCall.args
string leaves to the run tracker: the Google wire has no top-level "type"
field, so the function_call frame gate could not exempt it, and the payload
leaf is usually named "content" — a TEXT_LEAF_KEYS name. A write-tool
argument of >= 200 identical characters (e.g. a divider or padding run in a
generated file) aborted the whole turn mid-stream via relay's stream guard.

Add args/functionCall/parameters to EXCLUDED_BRANCHES (the openai
arguments/partial_json keys were already excluded) and pin both directions:
300 '=' in functionCall.args must not trip, 300 '=' in parts[].text must.
…3358)

The closed duplicate covered the args.text leaf-key spelling and the
mixed prose+arg frame shape; absorb both so the keeper PR pins them too.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.487-master.06a1f30 (rolling master tag).

npm install -g billion-context@0.0.487-master.06a1f30  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant