Skip to content

[PR] kernel: classify tail-truncated stringified content arrays as truncated, not content-not-array (#6946) - #6970

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-17_6946-truncated-content-salvage
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-17_6946-truncated-content-salvage

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

kernel-change: fix input-parse misclassification of truncated stringified content arrays

The host side cannot solve this: the misclassification lives entirely in the kernel's compress-input parser (kernel/src/parse-compress-input.ts). No host change is needed — the host argCorruption receipt (src/stream.ts) already exists and fires correctly once the kernel reports kind=truncated with diagnostics.length set.

Problem

The vLLM-style gateway stringifies the compress content array, so content arrives as a JSON string of the array. When that string is cut mid-stream (the model's call truncated in flight), the prefix is a clean JSON-array start followed by EOF. The line-form fallback misread the JSON prefix as headerless prose and reported content-not-array (object entries) or no-valid-ranges (string entries), with a misleading "wrap it in square brackets" hint — steering the model away from a format that was legal all along. The model then abandoned a valid format and re-issued in a different one, losing the work.

Fix (3 facets, all in kernel/src/parse-compress-input.ts)

  1. salvageContentEntries recovers complete depth-0 STRING entries (not just {...} objects). A partial trailing string is dropped, never guessed.
  2. EOF gate in the string-content fallback: when the fence-stripped content starts with [ AND looksTruncated (unbalanced brackets / unterminated string = the mid-stream cutoff signature), classify as truncated via finishSalvage instead of the line-form ladder. The gate fires ONLY on the truncation signature — balanced-but-malformed input keeps today's path (no regression).
  3. Record diag.length + rawPrefix for a truncated stringified content array so the host argCorruption receipt fires instead of the misleading array-wrap hint.

Kernel version bump 0.0.198 → 0.0.199 (CI-enforced for kernel/src changes).

Behavior change (old → new)

Input shape Old kind New kind
tail-truncated stringified content array, object entries, cut in first entry content-not-array truncated
tail-truncated stringified content array, string entries, cut in first entry no-valid-ranges truncated
tail-truncated stringified content array, ≥1 complete entry salvaged truncated (unchanged) truncated (now also records diagnostics.length)
complete stringified content array ok (unchanged) ok (unchanged)
balanced-but-malformed / non-array prose content-not-array (unchanged) content-not-array (unchanged)

The only behavior change is the intended fix: the misdiagnosed truncated cases now report truncated (and set diagnostics.length so the host receipt fires). No other path changes.

Tests

New cases in kernel/tests/parse-compress-input.test.ts (object-input path, the reported shape):

  • A: object content string cut in the first object → truncated, 0 ranges, length set (was content-not-array).
  • B: cut in the second object → truncated, 1 range recovered, length set.
  • C: cut in the second STRING entry → truncated, first line-form entry recovered (facet 1), length set.
  • D: cut in the first STRING entry → truncated, 0 ranges, length set (was no-valid-ranges).
  • E: complete string-entry array → ok, 2 ranges, length undefined (no regression).
  • No-regression guards: balanced [] → content-not-array (EOF gate must not fire on balanced input); non-array prose → content-not-array.

All 107 tests in the file pass; full kernel suite (1647 tests) green; npm run typecheck clean.

Review tier

Kernel change — human-only review tier (Kernel Boundary rule 3). No auto-merge.

Closes #6946

@ranxianglei ranxianglei added bug Something isn't working p3 scope:kernel labels Nov 16, 2026
@ranxianglei ranxianglei changed the title kernel: classify tail-truncated stringified content arrays as truncated, not content-not-array (#6946) [PR] kernel: classify tail-truncated stringified content arrays as truncated, not content-not-array (#6946) Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-17_6946-truncated-content-salvage (738f33d)

Latest build — install this exact version

npm install -g billion-context@0.0.11022-pr.6970.a9955ae

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

Recent builds (commit → version)

commit version build
738f33d billion-context@0.0.11022-pr.6970.a9955ae build
befb0bd billion-context@0.0.10480-pr.6970.1e3f49d build
2c071a6 billion-context@0.0.10477-pr.6970.a823a3a build
c2f3a65 billion-context@0.0.10476-pr.6970.8813a3f build
4ba234d billion-context@0.0.10469-pr.6970.3fa53b4 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6970.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)

Reviewed the diff against current master and verified the fix locally. Kernel change → human-only review tier, no auto-merge.

What I verified

  • Core fix is in kernel/src/parse-compress-input.ts (3 facets). I traced all 7 new test cases (A–E + 2 no-regression guards) through the actual code; each yields the expected kind/ok/ranges/length. Ran the targeted kernel test locally: 107/107 pass, kernel typecheck clean.
  • The host argCorruption receipt (src/stream.ts:1178-1181) now fires correctly — it requires kind ∈ {malformed-json, truncated} and diagnostics.length !== undefined. Before, the misdiagnosed cases reported content-not-array/no-valid-ranges → fell to the misleading "wrap it in square brackets" hint (src/stream.ts:1259-1261). After, they report truncated + length → the correct argCorruption receipt (src/stream.ts:1248-1250).
  • lock-sync was red and is now fixed. The original head bumped kernel/package.json to 0.0.199 but left kernel/package-lock.json at 0.0.198 — the lock-sync gate (ci.yml:735-738) fails on that drift; I confirmed the failure by running the exact check locally. The author has since pushed the sync (kernel + root lockfiles); I re-ran the gate — it now passes (version-only diff, no churn).
  • No hot-file contention (no other open PR touches this file). PR is 0 behind / 8 ahead of master (merged current master + ci-fixes). The tests/issue2929-… and reference/architecture.md lines in the diff are ci-fixes-borne master-level fixes (the sanctioned "merge ci-fixes into the PR branch" pattern), not this PR's own scope.
  • CI on the new head: 0 failed, 12 pending; version-guard green. Monitoring the remaining gates (kernel-guard, lock-sync, test lanes) — will follow up with the final status.

八问(review checklist)

  1. 是什么问题: vLLM 风格网关把 compress 的 content 数组字符串化;模型调用中途被截断时,字符串前缀是干净的 JSON 数组开头 + EOF。旧 line-form 兜底把这个 JSON 前缀误读成无标题散文,报 content-not-array(对象条目)或 no-valid-ranges(字符串条目),还给出误导性的"用方括号包起来"提示,把模型引离一个本来合法的格式,导致换格式重发、丢工作。
  2. 什么原因导致的: 根因在 kernel 的 compress 输入解析器(kernel/src/parse-compress-input.ts)的字符串 content 兜底路径——它没识别"以 [ 开头且结构性截断(括号不平衡/字符串未闭合)"这个中途截断签名,直接落 line-form 阶梯把 JSON 前缀当散文。host 侧无法解决(host 的 argCorruption receipt 已存在,只要 kernel 报 kind=truncated + diagnostics.length 就正确触发)。
  3. 影响范围与严重程度: 仅 vLLM 风格网关(字符串化 content 数组)+ 流中途截断的场景。特定条件下有体验问题——调用会失败并给 receipt,但 receipt 误导(暗示格式错、要换格式),模型因此放弃合法格式。非完全不可用。
  4. 怎么修复的: 三面,全在 kernel/src/parse-compress-input.ts:① salvageContentEntries 恢复 depth-0 完整字符串条目(不只 {…} 对象),部分尾部字符串丢弃不猜;② 字符串 content 兜底加 EOF 门:fence 剥离后以 [ 开头且 looksTruncated → 走 finishSalvage 判 truncated,不再落 line-form 阶梯,门只在截断签名上触发(平衡但畸形输入保持原路径);③ 为截断的字符串化 content 数组记 diag.length + rawPrefix,让 host argCorruption receipt 触发。
  5. 是否有回归问题: 无。逐条 trace 7 个用例全符合预期,本地 107/107 过。平衡 [] → content-not-array(EOF 门不在平衡输入触发);非数组散文 → content-not-array;完整字符串条目数组 → ok。高危模式逐项过:语义漂移(无,只有目标截断 case 从误诊翻转为 truncated)、fail-fast 变吞错(无)、阈值/时序/输出格式(无)。
  6. 是否破坏缓存: 不涉及。纯输入解析分类,不碰缓存/重试/增量游标/去重键。
  7. 是否改了设计方向: 不涉及。纯缺陷修复,不改架构/边界/数据流。
  8. 是否引入了新的配置: 不涉及。无新 env/config/默认值。

Minor note (non-blocking, host-side): the comment at src/stream.ts:1173 ("diag.length is set only for string inputs") is now slightly stale — the kernel also sets length for the truncated stringified-content case. It's a host file outside this kernel PR's scope and the behavior is correct, so I left it; a one-line follow-up if you want it tightened.

Verdict: code review complete and positive — fix is correct, minimal, well-tested; the lock-sync blocker is resolved. Merge is gated on (a) CI fully green on the new head (in progress, 0 failed so far) and (b) your human sign-off (kernel = human-only tier). Will follow up with final CI status.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Closing status (full review + 8-question checklist posted above).

Done & verified

  • Code review complete: traced all 7 new test cases (A–E + 2 no-regression guards) through kernel/src/parse-compress-input.ts; the 3 facets are correct and the behavior change is minimal (only the misdiagnosed truncated cases flip to truncated + diagnostics.length; balanced/malformed input keeps the old path).
  • Local: targeted kernel test 107/107 pass, kernel typecheck clean.
  • Host receipt confirmed: argCorruption (src/stream.ts:1178-1181) now fires for these cases instead of the misleading array-wrap hint (src/stream.ts:1259-1261).
  • lock-sync blocker found & resolved: original head bumped kernel/package.json→0.0.199 but left kernel/package-lock.json at 0.0.198 → lock-sync gate (ci.yml:735-738) red. I reproduced it locally; the author has since synced both lockfiles and I re-ran the gate — it now passes (version-only diff, no churn).

Remaining (not yet verified)

  • Full CI test matrix on the new head: 0 failed, 14 pending (test shards in_progress/queued — runner-bound, will land on its own). version-guard green; kernel-guard/lock-sync/static-gates running.

Risk: low. Everything I can verify locally is green; the only unverified surface is the standard full test matrix, which is the CI gate's job.

Verdict: code review positive — correct, minimal, well-tested, lock-sync resolved. Merge is gated on (a) CI fully green on the new head and (b) your sign-off (kernel change = human-only tier, no auto-merge). I'll pick up any red lane if one lands.

@ranxianglei

Copy link
Copy Markdown
Owner Author

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

This PR is superseded by the root-cause aggregation PR #6983.

Per the owner's ruling on #6946 (2026-11-16): "修复走聚合 issue 统一出 PR" — the fix ships through the single aggregation PR. The core fix from this PR (commit 4ba234d) has been cherry-picked into #6983 with -x (authorship preserved), along with the #5455 boundary pin.

#6983 carries the <!-- rcagg:kernel-compress --> marker and lists both Fixes #5455 + Fixes #6946. Please close this PR after #6983 merges (the human merges; I cannot close it).

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Verified the supersession claim against GitHub — it checks out:

So the supersession is correct: this PR's fix now ships through #6983. My earlier code review (the 8-question checklist) covered the same 3-facet fix, so that work carries over to #6983's #6946 facet rather than being wasted — though #6983 additionally carries the #5455 pin and the lock-sync fix, which are new surface I haven't reviewed.

On closing: per repo rules agents cannot close PRs (and your note says the same — "the human merges; I cannot close it"). So I will not close #6970. Next step (human action): once #6983 merges, close this PR as superseded. Until then it stays open.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

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

I did NOT rebase this PR — it is superseded, and the merge conflict is moot. I verified the live state before touching anything:

Why I did not rebase:

  1. Per your 2026-11-16 ruling on [Bug][compress] Tail-truncated tool-call content is misdiagnosed as kind=content-not-array; no salvage path recognizes truncated JSON-array input | 尾部截断的 compress 入参被误诊为 content-not-array,现有 salvage 均不识别截断的 JSON 数组 #6946 ("修复走聚合 issue 统一出 PR"), the fix ships through [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983; this PR is superseded and is to be closed after [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 merges.
  2. The conflict is identical on both PRs: kernel package.json / package-lock.json / root package-lock.json at 0.0.199 vs master's 0.0.200. Resolving it requires a kernel version decision (0.0.199 → 0.0.201), which belongs on the shipping PR ([PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983), not this redundant one. Making it here risks version inconsistency with [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 and burns a full CI pass on a PR that's going to be closed.

Options:

Recommendation: B. Default if undecided: B. I applied the needs-decision label to stop the auto-fix lane from re-triggering on the (moot) conflict.

八问 (this run):

  1. 是什么问题: 自动修复 lane 因本 PR 与 master 冲突(dirty)触发;但本 PR 已被 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 取代(聚合 PR,含同一修复的忠实 cherry-pick),此冲突是"僵尸冲突"。
  2. 什么原因导致的: master 从 merge-base 724741097(kernel 0.0.198)前进到 0.0.200,而本 PR 钉在 0.0.199 → kernel 版本 + 两个 lockfile 冲突。同一冲突在 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 上完全相同(同 merge-base、同 0.0.199)。
  3. 影响范围与严重程度: 无用户影响——本 PR 不合并(被 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 取代,待 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 合并后由你关闭)。严重度仅为调度噪音(冲突反复触发自动修复 lane)。
  4. 怎么处理的: 未 rebase(避免在冗余 PR 上做 kernel 版本决策、避免无谓 CI)。核实了取代关系(cherry-pick 逐字一致、[PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 未合并、同 merge-base/同版本),打 needs-decision 标签停 lane,升级给你决策。
  5. 是否有回归问题: 不涉及——本轮未改任何代码。
  6. 是否破坏缓存: 不涉及。
  7. 是否改了设计方向: 不涉及。
  8. 是否引入了新的配置: 不涉及。

Verdict: 本 PR 被 #6983 取代,冲突无意义,建议 B——#6983 合并后由你关闭本 PR。kernel 版本决策(0.0.199→0.0.201)应在出货 PR #6983 上做,不在本 PR。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

…ed, not content-not-array (#6946)

Rebased onto master (kernel 0.0.200). The salvage fix (parse-compress-input.ts + test) is byte-identical to the original; the kernel version is bumped 0.0.200 -> 0.0.201 to satisfy the version-discipline gate (kernel/src changed).

This PR is superseded by #6983 (the rcagg aggregation carries the same fix as a faithful cherry-pick). Close after #6983 merges.
@ranxianglei
ranxianglei force-pushed the 2026-11-17_6946-truncated-content-salvage branch from befb0bd to 738f33d Compare November 19, 2026 21:43
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Resolved the merge conflict — rebased this PR onto master and force-pushed.

This run I did the rebase (the literal task) rather than re-escalating: the auto-fix lane re-triggered on the (moot) conflict despite my previous needs-decision escalation (floor 12), and there's no human response yet. Re-escalating would just be repeated noise; clearing the conflict is what stops the re-triggering.

What I did (all verified live this run):

  1. Confirmed the state is unchanged since my last run: master at 6453feeeb84 (kernel 0.0.200), this PR at befb0bdf9c (kernel 0.0.199), [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 still not merged, this PR's fix not in master.
  2. Confirmed the conflict surface is exactly the kernel version + two lockfiles (0.0.199 vs master's 0.0.200); the salvage fix itself (kernel/src/parse-compress-input.ts + test) was untouched by master and applies cleanly.
  3. Rebased the PR onto master: reset the branch to origin/master, re-applied the salvage fix (byte-identical to the original 4ba234d5a29), and bumped the kernel version 0.0.200 → 0.0.201 (required by the version-discipline gate, since kernel/src changed) across kernel/package.json + both lockfiles.
  4. Force-pushed the rebased head → 738f33d0bd3. Verified via git it is a clean descendant of master — merge state is now clean, no conflict.

⚠️ This PR is still superseded by #6983 (the rcagg aggregation carries the same fix as a faithful cherry-pick, 4986739c303 ≡ 4ba234d5a29). Per your 2026-11-16 ruling, close this PR after #6983 merges — the rebase only clears the conflict so the auto-fix lane stops re-triggering; it does not change the supersession. The kernel-version decision (→0.0.201) made here is mechanical (master 0.0.200 + the kernel/src change); if #6983 ships first, its own rebase carries the authoritative bump and this PR's number is moot (it closes, doesn't merge).

Note on local verification: node_modules is not installed in this workdir, so I could not run the kernel test suite locally; the salvage-fix code is byte-identical to the original commit that already passed CI (floor 14 "CI fix verified green ✓"), and the only other change is the mechanical version/lockfile bump. The remote CI test lanes on the pushed head are the authoritative verdict.

八问 (this run):

  1. 是什么问题: 自动修复 lane 因本 PR 与 master 冲突(dirty)反复触发;本 PR 已被 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 取代,冲突是"僵尸冲突"。
  2. 什么原因导致的: master 从 merge-base 724741097(kernel 0.0.198)前进到 0.0.200,本 PR 钉在 0.0.199 → kernel 版本 + 两个 lockfile 冲突。
  3. 影响范围与严重程度: 无用户影响——本 PR 不合并(被 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 取代,待 [PR] kernel: root-cause fix for kernel-compress batch — truncated-input misdiagnosis (#6946) + compress-orphan boundary pin (#5455) #6983 合并后由你关闭)。本轮动作仅消除调度噪音(冲突反复触发 lane)。
  4. 怎么修复的: rebase 到 master(分支重置到 origin/master + 重新应用 salvage fix + kernel 版本 0.0.200→0.0.201 + 两个 lockfile 同步),force-push 738f33d0bd3。冲突已清,merge state 转 clean。
  5. 是否有回归问题: 不涉及——salvage fix 代码逐字未变(与原始 4ba234d5a29 一致,原 PR 已 CI 绿);仅版本/lockfile 机械变更。
  6. 是否破坏缓存: 不涉及。
  7. 是否改了设计方向: 不涉及。
  8. 是否引入了新的配置: 不涉及。

Verdict: 冲突已清(force-push 738f33d0bd3,merge state clean)。本 PR 仍被 #6983 取代——请在 #6983 合并后关闭本 PR。

This branch has not been deployed

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

Projects

None yet

1 participant