Repository navigation
[PR] fix(kernel): reclaim stranded reasoning residue — context growth leak on strict-thinking lanes (#5531) - #5535
Conversation
…#5531) A turn whose tool call+result live inside an active fold block while its reasoning+text stayed visible (#564 reverse split) was permanently withdrawn from the compressible set: the global screen judged the covered call as "kept visible", so INV1 stranded [reasoning,text] forever — recommend never advertised them and apply refused direct folds of them. On strict-thinking lanes (DeepSeek et al.) the residue ratcheted monotonically with every growth fold (post-fold floor 33k->154k over 14 measured folds in the #5533 session; 165 reasoning cores resident at 371k billed input) until pending mass stalled below the T1 nudge threshold — nudge idle despite 73k of growth debt, context running toward the window cap. computeIntegrityWithdrawals gains an optional invisibleIds set (ids neither visible nor folding — covered by an active block). Only the INV1 kept-side test consults it; the folded side and the INV2 pair check are unchanged. Recommend passes coveredMessageIds(state); projectUnit's fresh-fold gate passes preExistingCoverage (the merge path already models coverage via foldedRef union survivingCoverage). Stranded [reasoning,text] becomes foldable again; folding removes reasoning and response together, so no orphaned reasoning reaches a strict-echo backend. Regression suite kernel/tests/issue5531-stranded-reasoning-residue.test.ts: fails 3 positive pins pre-fix, 8/8 post-fix; negative pins hold the #684 visible-call doctrine.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.7874-pr.5535.7068cd1This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5535.tgz
npm install -g packageInstall instructions are refreshed on each push. |
The bump commit updated kernel/package.json + kernel/package-lock.json but left the root lockfile recording the file:./kernel link at 0.0.177 — the lock-sync gate regenerates and fails on exactly this line.
(ai: vllm-qwen/qwen3.8-27b) 查重结论:不重复。检索了 open+closed issue 与 PR(按失败签名:covered-call 误读 / stranded reasoning / reverse-split 残留),无并行修复在途;PR 正文点名的相邻线程机制不同——#4733/#4383 是 stale usage anchor 导致的零折叠停摆(nudge 计量侧),#651/#5470 是 compress 调用挂载的 reasoning(摘要载体侧),与本 PR 的 turn-integrity 判定缺陷(折叠资格侧)症状与机制均不同,独立核实过。 标签:bug + dsh + scope/kernel + p1 —— 源 issue #5531 的日志来自 dsh 车道 DeepSeek thinking 模式;缺陷在内核共享判定核;上下文只增不减、nudge 永久空转属缓存泄露类,按 owner 修订一律 p1。 审核做了什么(证据)
八问
结论:代码、测试、版本纪律、CI 协调均过审,lock-sync 自伤已当场修掉(9b640b2),等重跑全绿即可交 owner 合并(kernel 改动按 Kernel Boundary 人审,批准记录已在源 issue 线程)。我不执行合并:#5535 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Findings-only review — NOT an approval. This PR changes kernel/ and carries a kernel-change: declaration, so it sits at the human-only kernel gate (Kernel Boundary); I am not approving it. See the separate 🔶 需要决策 comment for the owner authorization request. Below is my independent pass over the diff against current master (not derived from the issue's analysis).
Verdict: technically sound, no blocking code findings. Held solely on the kernel gate.
What it does (traced in source). Adds an optional 4th param invisibleIds?: ReadonlySet<string> to computeIntegrityWithdrawals (kernel/src/turn-integrity.ts:198). In the INV1 kept-call test (kernel/src/turn-integrity.ts:226-231) a call present in invisibleIds no longer counts as kept-visible:
group.some((id) => !remaining.has(id) && callIds.has(id) && !invisibleIds?.has(id))
Omitting the param is byte-identical to legacy (!undefined?.has(id) ≡ true), so every existing caller keeps its old verdict. An id already covered by an active block is now neither folded nor kept — it reads as hidden, so a #564 reverse split (call+result inside an existing block, reasoning+text left visible) no longer strands its reasoning.
KDD#12 / #3236 single-projection discipline (the load-bearing check). Recommend and apply share one foldability verdict:
- recommend global screen (
kernel/src/recommend.ts:438-443) passescovered=coveredMessageIds(state)(kernel/src/recommend.ts:295); - apply fresh-fold gate (
kernel/src/unit-projection.ts:415-420, fed bykernel/src/compress.ts:346→applySingleRange→projectUnit) passesisMerge ? undefined : input.preExistingCoverage, wherepreExistingCoverage = collectCoverage(state)captured once per applyCompression call (kernel/src/compress.ts:346).
coveredMessageIds (kernel/src/state.ts:57) and collectCoverage (kernel/src/unit-projection.ts:619) both compute the union of effectiveMessageIds over active blocks (activeBlocks === blocks.filter(b => b.active), kernel/src/state.ts:53) — identical sets ⇒ no new advertise→reject loop class. Confirmed.
Merge recheck left untouched — correct, not a gap. kernel/src/unit-projection.ts:471 omits the set deliberately: on a merge, sibling-block coverage is folded into foldedRef = effectiveMessageIds ∪ survivingCoverage (kernel/src/unit-projection.ts:405-409), so a covered id lands in remaining and already reads as "not kept" through the existing mechanism. Fresh folds need the separate invisibleIds precisely because there a covered id is neither in remaining nor kept. Both routes reach the same "covered ≠ kept-visible" outcome.
Negative direction preserved (#684). A genuinely visible (uncovered) call still guards its reasoning run: empty/undefined set ⇒ legacy withdrawal ⇒ projectUnit fatals split, recommend suppresses, applyCompression refuses with the canonical error. Pinned by 3 negative tests.
Reachability edge considered, not a blocker. A covered-call-but-visible-result (orphaned result) is unreachable: pair-boundary widening (applyPairBoundaryAdjustments, kernel/src/unit-projection.ts:627) always widens a range to keep a call with its result, so the kernel never produces a block covering the call alone.
Tests (real teeth). kernel/tests/issue5531-stranded-reasoning-residue.test.ts (8 tests) drive the real core (createCore().processTurn / applyCompression), not mocks: positive pins reproduce the bug at the gate / recommend / projectUnit / apply layers and fail pre-fix; negative pins lock the visible-call doctrine.
Conventions & house rules. kernel-change declared ✓; owner approved in-thread (#5531 「动内核吧」) ✓. Version discipline: acp-kernel 0.0.177→0.0.178 (kernel/package.json + kernel/package-lock.json), root package-lock.json file-link synced to 0.0.178, billion-context's own root package.json version untouched ✓. No config-surface change (declared) ✓; no as any / @ts-ignore; why-comments well-referenced. CI (mirror cache): 0 failed / 0 pending; kernel-guard, version-guard, lock-sync, static-gates, config-surface-guard green.
Behavior change (old → new) — disclosed in PR body, verified. OLD: a turn whose call/result sit in an active block while reasoning/text stay visible is permanently un-foldable (residue ratchets toward the window cap; nudge idles once pending mass < threshold). NEW: such residue is advertised again and folds with its response. Scope limited to turns already reverse-split by an existing fold; fresh whole-turn folds, visible-call protection, merge coverage model, and INV2 are unchanged. Cache: enables previously-impossible folds (each rewrites its prefix once, bounded by folded size) — net reclaim, no invalidation-strategy change. Availability strictly improves.
No small mechanical fixes to make on the branch — the diff is clean, and kernel/ changes are not mine to modify in a review pass.
|
🔶 需要决策 请求 owner 就本 PR 的 kernel/ 变更授权合并 —— 它带 引用: PR #5535 (Closes #5531),head 被门控的 diff(acp-kernel 0.0.177 → 0.0.178):
独立审核结论(非抄 issue):技术上成立、无阻断性代码问题;recommend/apply 共用同一覆盖集(KDD#12)已逐点核实、负向(#684)保留已钉、CI 0 红。仅因 kernel/ 人工门而停在此处等你拍板。 授权背景:owner 已在 #5531 线程内说「动内核吧」(选项 A:覆盖感知的资格判定)。本 PR 即该选项的实现,diff 与当时批准的方向一致。请就这份具体 diff 予以确认 / 批准。 结构化八问(本 PR)
建议:批准合并(人工 merge)。若需我补充某条路径的证据或补测,说明即可——但 kernel/ 的最终授权由你决定,我不替你做。 |
[bot] 🏷 审核完成 —— PR #5535(内部 #5537; 结论:技术上成立、无阻断性代码问题;因改动 kernel/ 触发人工门 → 不批准,转 needs-decision 等 owner 授权。
已做:findings-only review(非 approve)+ 🔶 需要决策 评论(含八问)+ needs-decision 标签(内部 #5537)+ #4599 一行完成报告。未开新 issue。owner 已在 #5531「动内核吧」批准该方向,请就这份具体 diff 拍板合并。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.999-master.00006b5 # this exact build
npm install -g billion-context@master # always the newest merged build
|
turn-integrity + kernel 0.0.178 Block-covered calls become invisible in turn-integrity (ranxianglei#5531); kernel unit-projection and recommend follow. Four kernel-side files, zero overlap with this lane's 16.
(ai: vllm-qwen/qwen3.8-27b)
kernel-change: the defect lives in the kernel turn-integrity judgment shared by recommend and apply (KDD#12 single projection) — no host-layer interception can restore foldability without duplicating that judgment. Owner approved the kernel change in-thread ("动内核吧").
Closes #5531
What breaks (user-visible)
On strict-thinking lanes (DeepSeek thinking mode), every compression round strands part of each folded turn: when a fold covers a turn's tool call+result but leaves its reasoning+text visible (the #564-permitted reverse split), the integrity screen reads the covered call as "still visible" and permanently withdraws the rest of the turn from the compressible set. The residue accumulates monotonically — in the reporter's session the post-fold floor climbed 33k→154k tokens over 14 measured folds (54 total), 165 reasoning cores resident at 371k billed input, and once pending mass stalled under the T1 nudge threshold the nudge went idle forever ("max compressible 26847 < threshold 50000") despite 73k of growth debt. Context runs toward the window cap; each growth fold reclaims only a sliver — the reported "每次增长压缩只回收一部分".
Behavior change (old → new)
Why safe
invisibleIds) oncomputeIntegrityWithdrawals; omitted = byte-identical legacy verdict. Callers: the recommend global screen (passescoveredMessageIds) and projectUnit's fresh-fold gate (passespreExistingCoverage). The merge recheck loop is untouched — merges already model coverage via foldedRef ∪ survivingCoverage.Tests
New
kernel/tests/issue5531-stranded-reasoning-residue.test.ts(8 tests): fails 3 positive pins on pre-fix code (bug reproduced), 8/8 post-fix. Full-suite verdict = CI lanes.Config surface
None.
Dedup
Distinct from #4733/#4383 (stale usage anchor → zero-fold stall — different symptom AND mechanism; fixed, demonstrably working in the reporter log) and from #651/#5470 (compress-call-attached reasoning only).