Skip to content

[PR] fix: avoid recursive runaway guard traversal of provider JSON - #6131

Closed
Afloat16 wants to merge 2 commits into
ranxianglei:masterfrom
Afloat16:2026-11-10_fix-runaway-deep-json
Closed

Afloat16 wants to merge 2 commits into
ranxianglei:masterfrom
Afloat16:2026-11-10_fix-runaway-deep-json

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

The runaway observer recursively visits parsed provider JSON, including excluded branches. Valid deep nesting can overflow the call stack and fail an otherwise normal response stream.

Changes

Use an explicit depth-first stack. Push children in reverse order to preserve text ordering and skip excluded branches before visiting children. Deep model text still participates in detection; excluded tool payloads remain byte-exact passthrough.

Validation

  • Three new deep-nesting cases fail with RangeError on unchanged upstream source.
  • 43 targeted Node tests passed across runaway-deep-json, issue3260-text-run-guard and runaway-guard tests.
  • Final-code TypeScript typecheck, npm production build (including dist import/external checks), and git diff --check passed. Full-suite verdict is left to repository CI.

Checked runaway-guard history and previous Afloat16 PRs. This fixes parsed-event traversal independently of framing and prior media traversal work.

Base: e1e33a9.

Closes #6130

@ranxianglei ranxianglei changed the title fix: avoid recursive runaway guard traversal of provider JSON [PR] fix: avoid recursive runaway guard traversal of provider JSON Nov 10, 2026
@ranxianglei ranxianglei added bug Something isn't working p2 scope/wiring labels Nov 10, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Duplicate screening: not a duplicate. Related open thread is #6127 / PR #6128 ("preserve runaway guard frame boundaries across chunks") — same subsystem (src/runaway-guard.ts) but a different failure domain: #6128 is about chunk-boundary framing of detection, this one is about call-stack overflow during traversal of already-parsed JSON. Different symptom, different mechanism → separate threads, but both touch the same file, so whichever merges second needs a rebase (hot-file contention noted). No overlap with the closed #3260 / #3358 / #3362 runaway-guard work; this PR builds on their excluded-branch semantics rather than changing them.

Review in progress: verifying the reported RangeError reproduces on unchanged master source, running the targeted runaway-guard suites, then a structured review follows in this thread.

Reviewer alignment for PR ranxianglei#6131 (fixes ranxianglei#6130): test-only, no behavior change.
The four original cases passed under every leaf permutation, so the one named
"preserves text order" pinned no ordering; renamed it to what it actually
asserts (mixed array/object visitation plus cross-leaf run continuity) and
added one positive and one negative wire-order case (separated vs contiguous
150-runs against the 200 default threshold). Both new cases fail against a
forward-push (reversed-order) variant of the walker and pass on this
implementation.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Review complete — recommendation: mergeable. (The merge itself stays human.) Duplicate screening was done in my first comment here: not a duplicate; #6127/PR #6128 is the same subsystem but a different failure domain (chunk framing vs traversal depth).

Verification evidence

Repro confirmed on unchanged master: the three new deep-nesting cases fail with RangeError: Maximum call stack size exceeded inside the recursive walker (src/runaway-guard.ts:298-299 on master). The bug is real and those tests have teeth.

Fix equivalence: the new iterative walker is an exact preorder DFS — children are pushed in reverse and popped LIFO, so visit order is identical to the old recursion; exclusion semantics are preserved (the old sticky excluded flag ≡ the new skip-whole-subtree-at-pop); the collectText(obj) signature change is internal. No public API change to wrapStreamWithRunawayGuard; byte-exact passthrough, clean downstream EOF on trip, and upstream abort are all unchanged. Both compression modes are unaffected: the wrapper sits on the response relay used identically by the plugin lane (src/server/relay.ts:1918) and the proxy lane (src/server/relay.ts:2219), and the diff contains no mode-specific logic.

Local evidence on the rebased head (current master + this PR, clean rebase): typecheck clean, production build OK including dist import/external checks, 45/45 targeted tests green (runaway-deep-json ×6, issue3260-text-run-guard + runaway-guard ×39).

CI: cached check runs for the previous head showed no failures (the test matrix jobs were skipped under fork gating); the new head gets fresh runs — the full-suite verdict stays with CI.

Reviewer alignment commit pushed: 5aa1d6b

One finding I fixed directly rather than leaving as a note: test 4's name ("preserves text order") overclaimed. Leaf feed order IS observable through the run tracker (the max-run statistic changes when the feed sequence is reversed), yet all four original cases pass under every leaf permutation — that test pinned nothing about order. Since maintainer_can_modify is enabled, I pushed an additive, clearly-labeled, test-only commit to the PR branch (no rebase of the author's history): renamed the test to what it actually asserts (mixed array/object visitation plus cross-leaf run continuity) and added one positive and one negative wire-order case (separated vs contiguous 150-runs against the 200 default threshold). Teeth proven: against a forward-push (reversed-order) variant of the walker, exactly those two new tests fail and nothing else does; against the PR implementation all six pass.

Regression audit (existing behaviors carried by the touched paths)

Notes

  • Sibling PR [PR] fix: preserve runaway guard frame boundaries across chunks #6128 (frame boundaries) touches the same file in a disjoint function region; no semantic interaction — whichever merges second needs a rebase.
  • This PR's base is 52 commits behind master, but there is zero drift since its base in the touched files (verified by git log) and GitHub reports mergeable — squash-merging as-is is fine.
  • Labels: this thread's mirror shim does not implement the label endpoints (both GET and POST return "endpoint not implemented in ework shim"), so I could not apply labels myself; the PR already carries bug / p2 / scope/wiring set by the author. My independent severity read is p2/p3 borderline (hard failure mode, extremely narrow trigger) — p2 is defensible, left as-is.
  • §7.4 auto-merge gate: the fix meets every criterion (single-module scope, reproducing regression test, green on the rebased head, no config/persistence/wire/kernel changes, pure fix:, clean diff, references [Bug] Deep provider JSON can crash the runaway guard with a stack overflow #6130, no load-bearing infrastructure). Per repo policy the merge decision itself stays with a human.

结构化八问

  1. 是什么问题:runaway guard 用递归遍历已解析的 provider JSON,合法但极深的嵌套(万级)会耗尽调用栈,RangeError 打挂本应正常的响应流。
  2. 什么原因导致的:调用栈深度与 JSON 嵌套深度直接耦合(递归实现),且递归还会下探被排除分支做无用功;无其他机制参与。
  3. 影响范围与严重程度:仅当上游在 SSE data 帧里输出万级以上深嵌套 JSON 时,该次响应流失败(下游干净 EOF、上游中止)——真实 provider 基本不会发生,畸形/恶意上游可以构造;无数据丢失、不持续,用户重试即可。特定条件下的个别响应失败 → p2/p3 边界(现有标签 p2 可接受)。
  4. 怎么修复的:递归改为显式 DFS 栈(堆代替调用栈),子节点逆序入栈保持访问顺序,弹出时判定排除分支使被排除子树整体不访问。纯栈安全重构,语义逐位等价。
  5. 是否有回归问题:无。逐项审计如上:字节级透传、排除分支语义、trip 路径、NDJSON/快照/function-call 跳过、两种压缩模式全部保持;无阈值/时序/输出格式漂移。
  6. 是否破坏缓存:不涉及。guard 只旁路观察响应流,不触碰任何缓存/重试/游标/去重键。
  7. 是否改了设计方向:没有。
  8. 是否引入了新的配置:没有。

合并判定:建议可合——复现已验证、修法语义等价、回归审计干净、测试经对齐提交(5aa1d6bdf6)增强后本地定向 45/45 全绿;等新 head 的 CI 结果后由人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Status note: the full structured review for this PR was already posted (verified live on the upstream PR #6131 thread, 2026-11-10 23:22 UTC) — if it does not render below, that is a mirror-sync lag, not missing work. Compact outcome:

  • Verdict: recommended mergeable (merge stays human). Repro confirmed on unchanged master (RangeError in the recursive walker, src/runaway-guard.ts:298-299); the fix is an exact preorder-DFS equivalent — no behavior change, byte-exact passthrough and excluded-branch semantics preserved, both compression modes unaffected.
  • Reviewer alignment commit 5aa1d6bdf6 pushed to the PR branch (test-only): the original test named "preserves text order" pinned no ordering (it passed under every leaf permutation) — renamed it and added one positive + one negative wire-order case, teeth proven against a reversed-order walker variant.
  • Evidence: rebased head typecheck + build clean; 45/45 targeted tests green locally; cached CI for the previous head had 0 failures (test matrix fork-gated/skipped) — the full-suite verdict stays with CI on the new head.
  • Remaining: CI on head 5aa1d6bdf6, then human merge. Sibling PR [PR] fix: preserve runaway guard frame boundaries across chunks #6128 touches the same file in a disjoint region — whichever merges second needs a rebase. Labeling could not be done from this thread (mirror shim does not implement label endpoints); the PR keeps its author-set bug / p2 / scope/wiring labels.

@ranxianglei

Copy link
Copy Markdown
Owner

Landed via batch PR #6439 (merged) — closing as superseded.

Louie0806 pushed a commit to Louie0806/billion-context that referenced this pull request Nov 12, 2026
Reviewer alignment for PR ranxianglei#6131 (fixes ranxianglei#6130): test-only, no behavior change.
The four original cases passed under every leaf permutation, so the one named
"preserves text order" pinned no ordering; renamed it to what it actually
asserts (mixed array/object visitation plus cross-leaf run continuity) and
added one positive and one negative wire-order case (separated vs contiguous
150-runs against the 200 default threshold). Both new cases fail against a
forward-push (reversed-order) variant of the walker and pass on this
implementation.

(cherry picked from commit 5aa1d6b)
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Acknowledged — supersede verified live, nothing outstanding on my side.

  • Landing confirmed: batch PR [PR] chore(batch): land 50 open Afloat16 fixes in one history-preserving batch #6439 ("chore(batch): land 50 open Afloat16 fixes in one history-preserving batch") merged at 2026-11-12 14:01 UTC and carries both commits — the fix (fix: avoid recursive runaway guard traversal of provider JSON) and my reviewer alignment commit (test: pin leaf feed order in the deep-JSON runaway-guard tests; sha changed by the batch's history-preserving rebase). src/runaway-guard.ts on master now has the iterative walker (line 277), replacing the recursion that overflowed on deep provider JSON.
  • PR [PR] fix: avoid recursive runaway guard traversal of provider JSON #6131 closed as superseded at 14:08 UTC (not merged) — correct outcome, no further action needed from me.
  • Forced-restart report (35-min hang): the previous run had already finished everything (review posted, alignment commit pushed, status note posted) and then hung on an idle network fetch to an unreachable raw-file host — no work was in flight and nothing was lost. I have switched to the API endpoint for any remaining verification, which works fine.

Final state: fix + order-pinning tests live on master via #6439; this PR superseded; thread ready for you to close.

@ranxianglei ranxianglei reopened this Nov 14, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Re-trigger received — re-verified live, state unchanged, no action taken.

Nothing outstanding — this thread needs no further work from me.

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

Labels

bug Something isn't working p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Deep provider JSON can crash the runaway guard with a stack overflow

2 participants