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
{{ message }}
Repository navigation
[Bug] Account for deeply nested media without recursive stack growth #6038
Passed against exact fork commit 01e42ad79402ea62220e7ac60c2d54075da8c4ef in an isolated GitHub Actions checkout: validation job. The targeted regression and related suites, npm run typecheck, and npm run build all passed on Node 22. This is targeted verification, not the full upstream CI matrix.
node --import ./tests/preload-storage-baseline.mjs --import ./tests/preload-test-env.mjs --import tsx --test tests/media-walk-depth.test.ts
npm run typecheck
npm run build
Related work checked
Related #4119, #4382 and #4923 address repricing/maximum-string handling, not traversal depth.
查重:不重复 — the mechanism (recursive walk over client-controlled request JSON overflowing the JS call stack) has no prior issue or PR. Your own PR #6048 already targets this exact thread, so per the one-fix-PR-per-thread rule I am reviewing and completing THAT PR rather than opening a parallel fix. No new issues opened.
Verified the bug locally (version-first): on master 4be21b08ed (= your reported base, bili 0.1.213), mediaBytesOfWireBody (src/agent/media-bytes.ts) throws RangeError: Maximum call stack size exceeded at 20,000 nesting levels on Node 22 (Linux) — the stack trace lands in the recursive walk at src/agent/media-bytes.ts:30. JSON.parse itself is iterative and survives arbitrarily deep input, so the overflow is purely the walk, not the parse. Your regression test fails 2/3 with exactly this RangeError against the old code and passes 3/3 against your fix — it has teeth.
Layer judgment: root cause is unbounded recursion over attacker-/client-controlled JSON in the shared doom-math helper — not a missing try/catch at some call site. Your direction (iterative traversal at the source, preserving the structural media-shape accounting) is the correct layer. Call-site exposure varies: wireBodyMediaBytes (opencode-native) already swallows the throw conservatively, while the dsh takeover arms and the shared direct-fallback arm route through bodyOverWindowDetail without a local guard — so fixing at the source is the only complete fix.
One adjacent instance of the SAME mechanism found during review (same symptom, same recursion-over-client-JSON pattern, different file — proxy side, not agent lane): estimateRawBodyTokens and estimateRawBodyBreakdown in src/preflight.ts:453/:487 also walk the parsed client body recursively, and both throw RangeError at 10,000 levels (verified locally). They sit on the proxy's MAIN request path (src/server/handle.ts:1688 stamps rawInputTokens for every proxy-mode request) plus the side-request guard (side-request.ts:740) and threads-lane. Leaving them recursive means this exact input class still crashes proxy-mode requests after #6048 merges. Per the one-mechanism-one-PR rule I am folding them into PR #6048 as a separately-labeled commit (same package, no kernel boundary involved) with matching depth regression coverage.
Status: full review of #6048 in progress (code/tests/regression sweep done, CI green so far: 0 failed / 6 pending). Structured conclusion follows in-thread once the preflight commit lands and CI re-runs.
Review complete — your PR #6048 is merge-ready. CI on the pushed head: 0 failed, 12 shards in progress, remaining lanes skipped by env gate (normal). One reviewer-added complement commit landed on your branch (details below); nothing parallel was opened.
Verified before touching anything
Reproduced on master 4be21b08ed: a valid 20,000-level body throws RangeError: Maximum call stack size exceeded inside the recursive walk in src/agent/media-bytes.ts. JSON.parse itself is iterative and survives 200k levels — the overflow is purely the hand-written recursive walks, exactly as you diagnosed.
Exposure varies by call site: the opencode-native lane wraps the call in try/catch (degrades to 0, conservative-safe); the dsh takeover arms and the shared direct-fallback arm (bodyOverWindowDetail, src/agent/native-intercept.ts) call it unguarded.
Independent review of your commit
Sound. The iterative explicit-stack DFS visits exactly the node set the recursive version did; the byte sum is order-independent; all seven media-shape checks are unchanged; naming/style matches the file; no dead code; coverage is two-directional (deep hit, deep miss, malformed JSON, shallow sibling matrix). Your depth test has real teeth: run against the old code it fails 2/3 with RangeError.
Reviewer-added complement — commit ab67515c59, pushed to your branch
The same mechanism existed in two more walks: estimateRawBodyTokens and estimateRawBodyBreakdown in src/preflight.ts enumerate every string leaf of the parsed client body on the proxy MAIN path (handle.ts rawInputTokens stamping), the side-request guard, and threads-lane — and both overflow identically at ~10–20k depth. Without them, proxy-mode users still crash on the same input class this issue describes. Both converted to the same iterative pattern, preserving key inheritance, the NON_TEXT_BODY_KEYS exclusion set, top-level bucketing and the total invariant byte-for-byte. New suite tests/raw-body-walk-depth.test.ts: 20k-level object and array chains with media-shaped bottoms (verified to fail with RangeError against master's preflight.ts, pass on the fix), plus shallow plumbing pins (exclusion set, key inheritance through arrays, bucket split, non-object top-level).
Verification on the pushed head
Targeted suites covering all three walks: 141/141 pass (media-walk-depth, raw-body-walk-depth, dsh-native, session-gc, side-request-isolation)
npm run typecheck clean, npm run build OK
The platform's ci-check cherry-pick applied cleanly onto current master ⇒ the branch rebases conflict-free (drift commits touch unrelated files)
Behavior-change disclosure: none beyond removing the crash — token counts, buckets and byte accounting are identical for every body that previously worked; no config/env/wire changes.
标签: issue = bug, scope/wiring, p2(边缘健壮性缺陷:仅 ≥1 万层病态嵌套触发,真实流量 2–4 层,p1 标准不满足);PR #6048 already carried the same three labels.
One adjacent instance sits outside this PR's package boundary — flagged in my next comment for owner direction.
八问(结构化结论)
是什么问题: bili 用递归遍历客户端可控的请求 JSON(媒体字节统计 + raw-body token 估算),嵌套超过约 1 万层的合法请求栈溢出崩溃(RangeError),该请求被拒。
Activity
ranxianglei commentedon Nov 9, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
查重:不重复 — the mechanism (recursive walk over client-controlled request JSON overflowing the JS call stack) has no prior issue or PR. Your own PR #6048 already targets this exact thread, so per the one-fix-PR-per-thread rule I am reviewing and completing THAT PR rather than opening a parallel fix. No new issues opened.
Verified the bug locally (version-first): on master
4be21b08ed(= your reported base, bili 0.1.213),mediaBytesOfWireBody(src/agent/media-bytes.ts) throwsRangeError: Maximum call stack size exceededat 20,000 nesting levels on Node 22 (Linux) — the stack trace lands in the recursivewalkatsrc/agent/media-bytes.ts:30.JSON.parseitself is iterative and survives arbitrarily deep input, so the overflow is purely the walk, not the parse. Your regression test fails 2/3 with exactly this RangeError against the old code and passes 3/3 against your fix — it has teeth.Layer judgment: root cause is unbounded recursion over attacker-/client-controlled JSON in the shared doom-math helper — not a missing try/catch at some call site. Your direction (iterative traversal at the source, preserving the structural media-shape accounting) is the correct layer. Call-site exposure varies:
wireBodyMediaBytes(opencode-native) already swallows the throw conservatively, while the dsh takeover arms and the shared direct-fallback arm route throughbodyOverWindowDetailwithout a local guard — so fixing at the source is the only complete fix.One adjacent instance of the SAME mechanism found during review (same symptom, same recursion-over-client-JSON pattern, different file — proxy side, not agent lane):
estimateRawBodyTokensandestimateRawBodyBreakdowninsrc/preflight.ts:453/:487also walk the parsed client body recursively, and both throw RangeError at 10,000 levels (verified locally). They sit on the proxy's MAIN request path (src/server/handle.ts:1688stampsrawInputTokensfor every proxy-mode request) plus the side-request guard (side-request.ts:740) and threads-lane. Leaving them recursive means this exact input class still crashes proxy-mode requests after #6048 merges. Per the one-mechanism-one-PR rule I am folding them into PR #6048 as a separately-labeled commit (same package, no kernel boundary involved) with matching depth regression coverage.Status: full review of #6048 in progress (code/tests/regression sweep done, CI green so far: 0 failed / 6 pending). Structured conclusion follows in-thread once the preflight commit lands and CI re-runs.
fix: traverse raw-body token estimates iteratively as well (ranxiangl…
ranxianglei commentedon Nov 9, 2026
(ai: vllm-qwen/qwen3.8-27b)
Review complete — your PR #6048 is merge-ready. CI on the pushed head: 0 failed, 12 shards in progress, remaining lanes skipped by env gate (normal). One reviewer-added complement commit landed on your branch (details below); nothing parallel was opened.
Verified before touching anything
4be21b08ed: a valid 20,000-level body throwsRangeError: Maximum call stack size exceededinside the recursive walk insrc/agent/media-bytes.ts.JSON.parseitself is iterative and survives 200k levels — the overflow is purely the hand-written recursive walks, exactly as you diagnosed.bodyOverWindowDetail,src/agent/native-intercept.ts) call it unguarded.Independent review of your commit
Sound. The iterative explicit-stack DFS visits exactly the node set the recursive version did; the byte sum is order-independent; all seven media-shape checks are unchanged; naming/style matches the file; no dead code; coverage is two-directional (deep hit, deep miss, malformed JSON, shallow sibling matrix). Your depth test has real teeth: run against the old code it fails 2/3 with RangeError.
Reviewer-added complement — commit
ab67515c59, pushed to your branchThe same mechanism existed in two more walks:
estimateRawBodyTokensandestimateRawBodyBreakdowninsrc/preflight.tsenumerate every string leaf of the parsed client body on the proxy MAIN path (handle.tsrawInputTokens stamping), the side-request guard, and threads-lane — and both overflow identically at ~10–20k depth. Without them, proxy-mode users still crash on the same input class this issue describes. Both converted to the same iterative pattern, preserving key inheritance, theNON_TEXT_BODY_KEYSexclusion set, top-level bucketing and the total invariant byte-for-byte. New suitetests/raw-body-walk-depth.test.ts: 20k-level object and array chains with media-shaped bottoms (verified to fail with RangeError against master's preflight.ts, pass on the fix), plus shallow plumbing pins (exclusion set, key inheritance through arrays, bucket split, non-object top-level).Verification on the pushed head
npm run typecheckclean,npm run buildOKBehavior-change disclosure: none beyond removing the crash — token counts, buckets and byte accounting are identical for every body that previously worked; no config/env/wire changes.
标签: issue = bug, scope/wiring, p2(边缘健壮性缺陷:仅 ≥1 万层病态嵌套触发,真实流量 2–4 层,p1 标准不满足);PR #6048 already carried the same three labels.
One adjacent instance sits outside this PR's package boundary — flagged in my next comment for owner direction.
八问(结构化结论)
判定: 可合(待 CI 全绿后由人工合并;按规矩我不执行合并)。
ranxianglei commentedon Nov 9, 2026
🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)
背景一句话: 分析 #6038 时发现内核侧还有一处同机制实例(对客户端可控 JSON 的无界递归遍历),不在 PR #6048 的包边界内,未动。
待决问题: 是否修复
kernel/src/media-refs.ts:159——extractMediaRefs()内的walk(parts)沿 google-wire 嵌套functionResponse.parts无限递归,经collectFoldMediaRefs←kernel/src/compress.ts:44可达;20k 层嵌套的 functionResponse 链会同样栈溢出。旁证:kernel/src/protected.ts:715-728的同形 Google 分支只下探一层(安全),说明这里是漏改而非有意设计。选项(各带代价):
kernel-change:声明+版本 bump),人审仍 gating 合并。代价:多一个 kernel PR、走 kernel 版本节奏。推荐: A——修法已在本线程被实证安全(同一转换模式、同一测试配方),无设计取舍成分,符合豁免条款"显而易见机械性缺陷"。
不决定的默认行为: 保持搁置(B),本条记录留在本线程,不动
kernel/。