You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At upstream e1e33a9, pass two complete SSE events in one ReadableStream chunk to wrapStreamWithRunawayGuard. Each event has choices[0].delta.content containing 100 consecutive = characters. With the normal 200-character text-run threshold, the trip callback is never called; sending the same events separately does trip. Both LF and CRLF separators reproduce this.
An NDJSON case uses a complete JSON line with a 66 KB non-repeating prefix followed by the beginning of a 200-character repeated delta. Deliver its remainder and newline in the next chunk. The fallback drops the unfinished line and misses the repeated output.
Expected behavior
Inspect the same model text independently of network chunk boundaries, retain partial events, and forward ordinary bytes unchanged. Missing a trip allows unnecessary generation and token consumption.
Cause and verified fix
The global SSE separator regex retains lastIndex after the consumed prefix is sliced away. NDJSON fallback clears the unfinished tail and forgets its framing mode on subsequent small chunks. Resetting the cursor and preserving mode plus tail fixes both cases.
A prepared patch passes 46 targeted tests, typecheck and production build; three new regressions fail on the original source. Existing #3289 and tool-argument exclusions #3357/#3362/#3375 do not cover these framing failures. No kernel or configuration changes are required.
Duplicate screening: searched open+closed issues and PRs for this symptom/mechanism — the fix is already being delivered as PR #6128 ("fix: preserve runaway guard frame boundaries across chunks", closes #6127). Per the one-fix-PR-per-thread policy I did not open a parallel PR; instead I independently reproduced both reported failures, audited that patch, and pushed one hardening commit onto its branch.
Batched SSE: two complete events × 100 = chars in one ReadableStream chunk never trip; the same events in separate chunks do. LF and CRLF both affected. Root cause confirmed in source: the module-global /\r?\n\r?\n/g separator regex keeps its lastIndex after frameBuf is sliced — the next exec() resumes past the end of the shrunk string, so frames 2..N of a chunk are silently never scanned.
Split NDJSON: a ≥64 KB line split across chunks loses its incomplete tail (frameBuf = "") and the fallback mode is not sticky, so later small chunks are re-read as SSE where a lone \n never forms a separator — the repeated run is never counted. Matches the report exactly.
Patch direction is correct: cursor reset after each consumed frame; sticky NDJSON mode; retained partial tail; JSON opening-token gate so oversized split SSE events keep SSE framing.
One real gap, fixed directly (additive commit 3b150bff92 on the PR branch): the opening-token gate /^[{\[]/ rejects NDJSON streams whose first non-blank content follows leading blank lines — the fallback then never engages and the whole stream loses text-run detection. Widened to /^\s*[{\[]/; SSE field lines never start with whitespace, so the oversized-split-SSE protection stays intact. Added a regression test for that case (it fails on the pre-change gate).
Also documented the non-obvious invariants at their sites (cursor re-anchor, sticky mode, retained tail) so they don't read as removable dead code.
A companion review session had meanwhile pinned the token gate itself with a discriminating large multi-line data:-frame test (b8e6d9d873); the rebase kept both tests.
Local evidence: 23/23 targeted tests pass (new framing suite + existing runaway-guard suite); reverting src/runaway-guard.ts to the pre-fix source fails exactly the three positive-direction regressions (batched-SSE LF/CRLF, NDJSON partial tail) — the tests have teeth. Typecheck clean. Full-suite verdict comes from CI on the new head; the cached run for the previous head showed 0 failed checks (1 still pending at snapshot time).
Status: PR #6128 head is now 3b150bff92, mergeable, awaiting CI on the new head. Labels verified in place (bug / p2 / scope/wiring). No kernel or config changes required, as the report states.
Activity
fix: harden runaway guard NDJSON mode selection; document framing rules
ranxianglei commentedon Nov 11, 2026
(ai: opencode/qwen3.8-27b)
Duplicate screening: searched open+closed issues and PRs for this symptom/mechanism — the fix is already being delivered as PR #6128 ("fix: preserve runaway guard frame boundaries across chunks", closes #6127). Per the one-fix-PR-per-thread policy I did not open a parallel PR; instead I independently reproduced both reported failures, audited that patch, and pushed one hardening commit onto its branch.
Independent verification (at e1e33a9):
=chars in one ReadableStream chunk never trip; the same events in separate chunks do. LF and CRLF both affected. Root cause confirmed in source: the module-global/\r?\n\r?\n/gseparator regex keeps itslastIndexafterframeBufis sliced — the nextexec()resumes past the end of the shrunk string, so frames 2..N of a chunk are silently never scanned.frameBuf = "") and the fallback mode is not sticky, so later small chunks are re-read as SSE where a lone\nnever forms a separator — the repeated run is never counted. Matches the report exactly.Review outcome on PR #6128:
3b150bff92on the PR branch): the opening-token gate/^[{\[]/rejects NDJSON streams whose first non-blank content follows leading blank lines — the fallback then never engages and the whole stream loses text-run detection. Widened to/^\s*[{\[]/; SSE field lines never start with whitespace, so the oversized-split-SSE protection stays intact. Added a regression test for that case (it fails on the pre-change gate).data:-frame test (b8e6d9d873); the rebase kept both tests.Local evidence: 23/23 targeted tests pass (new framing suite + existing runaway-guard suite); reverting
src/runaway-guard.tsto the pre-fix source fails exactly the three positive-direction regressions (batched-SSE LF/CRLF, NDJSON partial tail) — the tests have teeth. Typecheck clean. Full-suite verdict comes from CI on the new head; the cached run for the previous head showed 0 failed checks (1 still pending at snapshot time).Status: PR #6128 head is now
3b150bff92, mergeable, awaiting CI on the new head. Labels verified in place (bug / p2 / scope/wiring). No kernel or config changes required, as the report states.八问
/\r?\n\r?\n/g在切片缩短缓冲后保留旧 lastIndex,下一次 exec 从已越界位置恢复,同块内第 2..N 帧全被跳过;(b) NDJSON 兜底清掉未完成的尾行且模式不粘滞,后续小块按 SSE 重读(单个 \n 永远不构成分隔符),重复段从未被计数。3b150bff92):token 门放宽为允许前导空白(/^\s*[{\[]/)——否则以空行开头的 NDJSON 流整个丢失检测(SSE 字段行绝不以空白开头,保护不受损)+ 注释钉住非显然不变量 + 该场景回归测试。结论:bug 属实,修复方向正确并已加固,交付收敛在 PR #6128 —— 等新 head 的 CI 结果后即可合并。
ranxianglei commentedon Nov 12, 2026
Fixed in batch PR #6439 (merged).
fix: harden runaway guard NDJSON mode selection; document framing rules