Repository navigation
[PR] fix: freeze avoided-token accrual when a fold's kernel block dies - #5651
ranxianglei wants to merge 3 commits into
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 独立检索了 open+closed 的 issue/PR(grossSaved / dead fold / savings accrual 等失败签名):触及该机制的在途工作只有本 PR;相关的历史条目 #2202(wire-coverage 冻结)、#2695/#2707(zombie 块收割)均为已关闭的前置机制,不是并行重复。与 #5646 是同一缺陷的修复 PR,方向对应。 开始独立审核(不复用 PR 描述结论):先核「嵌套层不重复计数」的 telescoping 论断是否成立(对着 kernel 源码验证),再走回归清点 + 代码 + 测试有效性。另发现分支落后 master 806 个提交且 mergeable_state=dirty——这是无决策依赖的机械步骤,我会先把分支 rebase 到当前 master、跑定向测试(cache-ledger / issue5646 / issue2202 / web-sessions / billing-web),然后给完整八问结论。 |
ecb470e to
69a62ff
Compare
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8112-pr.5651.e7602b4This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5651.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 合并冲突已解决并 force-push,PR #5651 恢复可合并(mergeable=true,head=69a62ff6a)。 七问:
判定:冲突已收敛,PR 恢复可合并;全量绿由远程 CI test 分片最终把关(当前 0 失败、进行中)。 |
) grossSaved/netSaved/savedUsd multiplied-counted reaped, host-dropped or orphaned folds: led.folds is append-only and every elapsed fold accrued on every later usage sample forever, so long plugin-mode sessions reported savings past any physical bound (issue: one session at 15.5x its own input, the fleet total at 8.9x all input tokens). Nested tiers were never the double count — the kernel telescopes child summaries into the parent's S — the leak was blocks that LEFT the compression state keeping their ledger terms alive. - cache-ledger: liveBlockIds() liveness snapshot (active roots plus anchored descendants); the accrual loop freezes requestsAfter for folds whose block is no longer alive, with one warn per death and self-heal when the block returns to state; absent block lists stay unverifiable → status quo (same discipline as #2202) - web payloads: per-session blockDeadFolds/blockDeadFrozenTokens, overview blockDeadFoldTotal/blockDeadFrozenTotal, savingsEstimated flag whenever the gross totals carry values; panel annotates both lines - tests: issue5646-dead-fold-freeze (nested freeze / orphaned child / self-heal / legacy no-bid / marathon compounding shape + display reconciliation); cache-ledger fixtures now mirror the production invariant that a fold's block sits in state before the ledger records it
…havior; fix i18n indent (review fixup) The DEAD_LOGGED_KEY comment claimed re-logging happens when a block dies twice within one boot, but no restore-entry deletion exists in the code: the map persists with session metadata and a recovered-then-re-died block stays quiet after its first warn. Reworded to state what actually holds. Also aligned the two new ov.* i18n entries to the surrounding 8-space indent.
69a62ff to
d6ac77e
Compare
(ai: vllm-qwen/qwen3.8-27b) 进度更新——机械步骤已完成,等 CI 后给最终八问结论。
CI 跑完后补最终结构化结论。 |
… verdict, only absent is unverifiable (review fixup)
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
审查判定:可合(approve 级) — reviewed end-to-end at head d6ac77eb(本账号即 PR 属主,GitHub 禁止自批,故以评论形式提交审查结论) (plus my comment-only fixup a422aaf, see below).
查重: 不重复。本 PR 是 #5646 的修复;机制上区别于 #2202(wire-coverage 证据,插件模式结构性失明)与 #2695(zombie-streak reap,仅 proxy 模式)——本 PR 补的正是插件模式下唯一可验证的存活信号:kernel block 是否在 state.blocks 里活着。
方向关(①原 issue): 作者的根因分层是对的——嵌套层级本身不是重复计费(telescoping 恒等式把子摘要折进父摘要,Σ(S_f−σ_f) 每字节只计一次),真正的泄漏是死块永生:led.folds append-only,每个 fold 在块死掉后仍在每次 usage sample 上继续累计 avoided tokens。修法命中生产者(累计循环的入口判定),不是在展示层遮掩。物理上限论证成立:单请求 avoided ≤ 窗口大小,7993 请求 × 1M 窗口 ≈ 7.99B < 报告的 26.53B。
回归审查(②既有行为清点,逐项结论):
- 无 bid 的 legacy fold(打点前旧数据):
dead要求f.bid !== undefined→ 状态不变,status quo 保持 ✓ - #2202 coverage-lost 路径:live 块的覆盖门逐字节未动;dead 仅在块确已死亡时经 else-if 优先接管 ✓
- state/块列表缺失(absent):
aliveBlocks = null→ 不可验证 → status quo,不误冻 ✓ - 空块列表:两个调用方都按真实「无活块」判决冻结全部 bid fold——这是修复要的行为(宿主侧压缩清空历史后 syncBlocks 摘除块),不是误伤 ✓
- web 概览/会话 payload:纯增量字段(blockDeadFolds/blockDeadFrozenTokens/blockDeadFoldTotal/blockDeadFrozenTotal/savingsEstimated),存量字段零改动;client.ts 只在字段存在时追加渲染 ✓
- i18n:仅新增 ov.blockdead_note / ov.est_mark 两键(zh+en),存量键未动 ✓
- tests/cache-ledger.test.ts 两处 fixture 改为先把块推入
session.state.blocks再记账——与生产顺序一致(src/stream.ts:1418 applyRanges 在 kernel 写入 res.state.blocks 之后才调 recordCacheFoldsFromBlocks),不改被测行为,是必要对齐 ✓ - 高危模式逐项:无 fail-fast 变吞错、无阈值/时序/输出格式漂移、无缓存/重试策略变化、无默认值变化 ✓
代码审查(③): liveBlockIds 种子集(active!==false 且有 string blockId)+ directBlockIds 下探 DFS、cycle-safe,正确实现「被活祖先锚定的被取代子块仍活着」(telescoping)而「reap/host-drop/孤儿子树」判死。dead 分支跳过 frac 与 requestsAfter 递增、hPct 不受影响、warn-once 用 metadata 持久化(跨重启静默,注释现已如实描述)。web 侧对「非空但全无 string blockId」的 sparse 行判 UNVERIFIABLE 是对 unified-index 合成行的正确防御。
测试有效性(④): 新测试是真测试——marathon 复现形态(S=1M fold,10 样本后清块再 20 样本 → requestsAfter 钉死在 10 而非 30)在移除 dead 检查时会直接红;负向行齐备(legacy 无 bid、state 清空、id-less 合成行不误标);self-heal(块恢复后继续累计、warn 总数 1);展示层走 hermetic SessionStore 真读路径。断言有牙。
行为变更披露核对: PR 正文已按规范披露——旧值:块死后 avoided tokens 无限累计 → 新值:死于首次观测到的死态即冻结;仅前向生效,不回溯削减已持久化的虚高总量(账本无逐请求历史可回溯,诚实边界)。savingsEstimated 恒 true(gross 有值即估算)是 issue 第 3 问的直接落实。均接受。
本地验证: typecheck 干净;定向套件 87/87 过(cache-ledger、issue5646-dead-fold-freeze、issue2202-coverage-accrual、web-sessions、billing-web)。CI 镜像缓存(d6ac77eb):30 checks,0 failed,其余 success/skipped,10 个 test shard 运行中——我随后推的 a422aaf 为纯注释提交,会触发重跑。
顺手小修(均已落分支,不降级判定):
- 作者 fixup
d6ac77eb已修:DEAD_LOGGED_KEY 注释「per boot」与实现不符(实际跨重启持久)、i18n 新增两行缩进 4→8 空格。✓ - 我再修一处同族问题:
liveBlockIds文档注释声称「空/缺失列表皆 UNVERIFIABLE」,但两个调用方都把空列表当作真实的 all-dead 判决(只有 absent 才 UNVERIFIABLE)——注释与代码事实不符,已改正。commita422aaf。 - 非阻塞备注(不动代码):ledger 侧没有 web 侧那条「非空但无 string blockId → UNVERIFIABLE」守卫;recordCacheSample 只见真实 kernel state(非空必有 string blockId),该形状在该路径不可达,无需处理。
判定: 可合。无 kernel/ 触碰、无配置面变更、纯 fix + 增量 payload + 有牙回归测试。
|
(ai: vllm-qwen/qwen3.8-27b) 已顺手修:liveBlockIds 文档注释与代码事实不符(声称空列表 UNVERIFIABLE,实际两个调用方都把空列表判为 all-dead,仅 absent 才 UNVERIFIABLE)+ commit a422aaf |
(ai: vllm-qwen/qwen3.8-27b) 审查完成——判定:可合(approve 级;本账号即 PR 属主,GitHub 禁止自批,完整审查结论已以评论形式提交在 PR #5651)。 八问:
验证:本地 typecheck 干净;定向套件 87/87 绿(cache-ledger / issue5646-dead-fold-freeze / issue2202-coverage-accrual / web-sessions / billing-web);CI 镜像缓存(head 收尾状态:审查结论已发(PR 评论)、顺手小修已落分支并各留一行说明、无需决策项(无 kernel/ 触碰)。等 CI 全绿后由人合并。 |
(ai: vllm-qwen/qwen3.8-27b) 最终审核结论(独立复核,未照抄 PR 描述) ① 是什么问题:面板概览/会话详情的「累计节省」(grossSaved / netSaved / savedUsd)对压缩块已离开会话状态的折叠(僵尸连击被收割 #2695、宿主丢弃块、父块死后孤立的子树)继续记账。fold 账本 append-only,每个已发生的折叠在之后的每一次用量采样上永久累积 → 长跑插件会话的累计节省超出物理上限(报告者会话 grossSaved = 自身输入 token 的 15.5 倍;全舰队 8.9 倍)。 ② 什么原因导致的:记账循环只看「折叠是否发生过」,不看「该块是否还活着」。issue 里的嵌套层双计假设不成立——我对过 kernel 源码( ③ 影响范围与严重程度:p2。只影响展示/计费估算面(面板、/acp-cache 报告、USD 换算);模型流量、压缩决策、数据完整性不受影响。触发条件 = 插件模式且存在死块的长跑会话;健康/短会话零变化。严重度 = 报表虚高(与真实值可差一个数量级),用户会高估节省。 ④ 怎么修复的:在记账路径引入存活快照—— ⑤ 是否有回归问题:逐项清点 diff 触碰路径的既有行为——
⑥ 是否破坏缓存:不涉及。纯记账/展示面;压缩、前缀缓存、重试策略、增量游标、去重键均未触碰。 ⑦ 是否改了设计方向:不涉及。架构/边界/数据流不变;cache-ledger 模块内新增一个导出纯函数 + 展示侧增量字段。 ⑧ 是否引入了新的配置:不涉及。无新 env / config key / CLI flag。 测试有效性:新套件是真测试——marathon 形状测试钉住「冻结在 M×t_mid 而非 M×N」(回归时该断言必炸);self-heal、一次一 warn、legacy status quo、显示对账(buildSessionList/buildOverview + hermetic store)均有覆盖。旧套件两个 fixture 对齐生产不变式(kernel 先把块写入 state,ledger 才记录)——是修正测试保真度,不是放宽断言。CI 全矩阵绿(head= 非阻塞小问题(记录在案,不拦合并):
判定:可合。 方向打中根因(死块账目项永生,而非表面的嵌套双计)、回归清点干净、测试有牙、CI 全绿。注意:此改动改变已持久化记账值的语义(无界累积 → 死亡冻结),属产品决策域,按 auto-merge gate 第 8 条需人工合并:#5651 |
Closes #5646
查重: 无(open+closed issue/PR 检索 grossSaved/savings/overview/multiply-count,无既有条目)
What was wrong
Overview
grossSavedTotal/netSavedTotal/savedUsdTotalkept booking requests against folds whose kernel block had LEFT the session's compression state (reaped zombie substrates #2695, host-dropped blocks, subtrees orphaned under a dead ancestor).led.foldsis append-only and every elapsed fold accrues on every later usage sample forever, so marathon plugin-mode sessions reported savings beyond any physical bound — the reporter's session: 435 folds,grossSaved26.5B = 15.5× its own input; fleet total 8.9× all input tokens.Nested tiers were NOT the double count (the issue's hypothesis): the kernel telescopes child SUMMARIES into the parent's S, so Σ_f (S_f−σ_f) = raw ever folded − root summaries and healthy nesting counts exactly once. The leak was dead blocks keeping their terms alive indefinitely — plus #2202's wire-coverage gate being structurally blind in plugin mode (resends never carry raw originals → unverifiable → status-quo accrual).
Fix
src/cache-ledger.ts: new exportedliveBlockIds()— liveness snapshot = active roots plus everything anchored beneath them throughdirectBlockIds. The accrual loop freezesrequestsAfterfor folds whose block is no longer alive; one warn per death; self-heals when the block returns to state (host resync). Absent block lists stay UNVERIFIABLE → status quo (same discipline as [cache-ledger] netSaved 面板在 fold 覆盖坍缩后继续累计虚增——ledger 与实际重发行为无交叉校验 #2202 legacy entries). No interface change; every consumer reads stored values, so the freeze propagates to the panel, the /acp-cache report and the billing USD faces.src/web/sessions-data.ts(+ i18n/client): additive payload fields — per-sessionblockDeadFolds/blockDeadFrozenTokens, overviewblockDeadFoldTotal/blockDeadFrozenTotal, andsavingsEstimated: truewhenever the gross totals carry values (kernel defines those figures as "estimate, not part of the closure" — the issue's ask Use kernel renderTags:"text-only" + forbid tag echoing in prompt #3). The panel annotates both lines.Behavior change (old → new)
Tests
tests/issue5646-dead-fold-freeze.test.ts: nested-tier accrual while alive (telescoping intact), root-reap freezing root AND orphaned child, one warn per death, legacy no-bid folds + absent state stay status quo, self-heal on block return, marathon compounding shape (frozen at M×t_mid, not M×N), display reconciliation through buildSessionList/buildOverview (dead share, id-less synthetic rows stay unmarked,savingsEstimated).tests/cache-ledger.test.ts: two fixtures now push the fold's block intosession.state.blocksbefore recording it — mirroring the production invariant (the kernel writes the block into state before the ledger records it); they passed before only because absent state carried no meaning.