Repository navigation
Add single-codepoint repetition lane to the output-side runaway guard (Closes #3260) - #3289
Conversation
…guard (#3260) Port pi's findDegenerateRuns minRun semantics (200) onto the existing intrinsic stream terminator: a model stuck in a symbol loop (#3946: one symbol string for ~22 minutes) now trips the stream mid-generation instead of running to max-output or manual abort. Detection runs on DECODED model text only — per-frame JSON walk over text-family keys (openai delta.content/reasoning_content, anthropic text_delta/thinking_delta, responses top-level delta, google parts[].text). Tool-call arguments are excluded (#1039 user intent), and Responses cumulative snapshot events (.done/.completed/ .incomplete) are skipped so runs are never double-counted. Every frame is parsed: token-granular streaming interleaves framing bytes between identical characters, so a raw run-length pre-gate would stay blind to the incident shape. NDJSON bodies (bare-newline events) are handled by a fallback splitter; byte-exact forwarding and the clean-EOF trip contract are unchanged. Always on, zero new config. Also neutralizes the trip log wording in relay.ts (two sites): it said 'runaway enumeration detected' even when the reason is now text-run.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3811-pr.3289.ca80c4dThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3289.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 这是 #3260 选项①(bili 加单 codepoint 连击 lane、默认打开)的唯一实现 PR;按主题/失败签名检索 open+closed issue 与近期 PR,无并列或重复条目。 审核独立性:以下结论由本 PR head 的 diff 独立重读产出(拉了 pr-3289,通读三处改动 + 本地定向验证),不是复述 #3260 侧的分析。 ⓪ 方向关(审原 issue):#3260 病灶是「正在生成中的模型单符号复读」(形态②/#3946:一个符号串刷约 22 分钟)在经 bili 路由的客户端上没有输出侧熔断——现有守卫只认 ACP 标签枚举与 tool XML 洪水两种形态,纯符号流里没有 ② 回归关(逐项清点既有行为,给证据):
结论:无回归。 唯一实质变化=新增一条始终开启的中止路径 + 每帧 JSON 解析开销(见 Q3)。 ③ 代码关(主关):
④ 测试关:17 例全是真测试(有牙)——byte-exact 前缀、threshold−1 边界(单元+跨帧)、#1039 工具参数排除(openai+responses 两处)、快照双重计数防护( ⑤/⑤b diff 整洁度 + 代码整洁硬标准:3 个文件(主体 relay 守卫 + relay.ts 两行日志 + 新增测试),每一行都与本 PR 目的相关,无跑题文件、无空行/重排噪音、无 lockfile 连带。命名达意、无死代码、无魔法数字、边界处理完整、风格一致——外部提交从严清单全过。 结构化八问:
判定:可合(待你批准合并)。 auto-merge 不适用——这是 feat(新增检测能力面)+ 共享 relay 热路径 + 行为变更(新增始终开启的中止路径),按 §7.4 需人审。本地定向证据:31/31 守卫测试绿 + typecheck 干净;全量以 CI 为准,红了我会定向跟进。(B) 插件层工作仍在 Tyan66666/billion-context-dsh#212 跟踪,dsh 源码按你的决定未动。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.469-master.6ee4a2a # this exact build
npm install -g billion-context@master # always the newest merged build
|
… guard The fake-model growth filler "x".repeat(360) emits a run of 360 identical codepoints per reply. Since #3289 merged the output-side runaway guard (#3260, src/runaway-guard.ts: textRun >= TEXT_RUN_THRESHOLD = 200), every synthetic reply is aborted mid-stream ("output-side runaway guard tripped (text-run; maxTextRun:200)") and the client sees an empty response, so T5's "every client turn must get a visible reply" fails deterministically on every shard-2 CI lane (run 38777578495: ubu22-s2 / ubu24-s2 / win22-s2 / win24-s2). Fix at the producer: "x ".repeat(180) — same 360 bytes per reply, max run of identical codepoints is 1, so the fixture stops emitting the degenerate symbol-loop shape the guard exists to catch (#3946). Guard untouched; no runtime code changed. Verified locally: tests/issue1086-chain-self-exemption.test.ts 21/21.
…-run lane (ranxianglei#3315 sub-defect 2) The T5 liveness fake upstream echoed "x".repeat(360) per turn. ranxianglei#3289's output-side runaway guard trips at TEXT_RUN_THRESHOLD=200 identical codepoints (src/runaway-guard.ts), aborting every such stream — so each turn lost its visible reply and the suite failed deterministically (25 !== 60) on every tree containing ranxianglei#3289: master push run 38767006158 and PR ranxianglei#3275 run 38776693851, plus local repro (35 guard trips). Mixed-char filler "xyz".repeat(120) keeps the identical 360-byte payload size (all assertions depend on length/byte count only) while maxTextRun drops to 1. Guard behavior itself is untouched — ranxianglei#3289 is intentional production behavior; the fixture simply must not emit pathological runs. Verified: node --import tsx --test tests/issue1086-chain-self-exemption.test.ts -> 21/21 pass, 0 guard trips (was 35).
Closes #3260
What
Adds a third detection lane to the existing output-side runaway guard (
src/runaway-guard.ts, #2346/#2347): single-codepoint repetition in decoded model text. A model stuck in a symbol loop (#3946: one symbol string for ~22 minutes — DSH form ②) now trips the stream mid-generation instead of running to max-output or manual abort. This is the bili-side landing for layer (A) of #3260 per owner decision (选项①, default on; dsh source untouched); layer (B) stays tracked at Tyan66666/billion-context-dsh#212.Semantics ported from pi's
findDegenerateRuns(minRun=200, production-tuned in billion-context-pi): ≥200 consecutive identical codepoints in assistant text/thinking → trip. Astral characters count as one unit (emoji ×200 trips).How it works
content/text/thinking/reasoning/reasoning_content/delta) into a stateful codepoint run counter. Covers every wire bili speaks: openai chat deltas, anthropic content_block_delta, responses output_text/reasoning_summary deltas, google parts[].text.function_call_arguments.*events..done/.completed/.incomplete) are skipped: they re-send finished payloads and would double-count runs already seen as deltas.onTrip(verdict)→ caller aborts upstream, downstream closes cleanly (EOF, not an error chunk), bytes forwarded up to the trip point byte-exact. New verdict reason"text-run"; detail carriesmaxTextRun+textRunChar.Behavior change (old → new)
bili dsh, whose model traffic rides the proxy envs).Known limitations
Tests
16 new tests in
tests/issue3260-text-run-guard.test.ts: core threshold / statefulness / reset / astral-codepoint / near-miss observability; wrap-level openai cross-frame trip with byte-exact prefix assertion; threshold−1 boundary; tool-argument exclusion (#1039); anthropic + responses lanes; snapshot skip; function_call_arguments exclusion; 3-byte-chunk boundary robustness; NDJSON fallback; 200KB legit-prose passthrough; 150-char separator margin; lane independence (acp flood still trips as acp-enumeration). All 15 pre-existingtests/runaway-guard.test.tscases green locally (targeted run); full-suite verdict comes from CI on this head.No config surface changes. No
kernel/orpi-subagents/changes.npm run typecheckclean locally.