Repository navigation
[PR] fix: tool-driven folds leave SAVED at 0 — restore the tokensSaved writer (#4700) - #4723
Open
ranxianglei wants to merge 5 commits into
Open
ranxianglei wants to merge 5 commits into
ranxianglei wants to merge 5 commits into
Conversation
The cumulative savings counter lost its writer with the kernel import: every fold lane stamps per-block compressedTokens, but nothing ever credited session.stats.tokensSaved again. The web SAVED column derives max(counter, sum over ACTIVE blocks' compressedTokens) since #2734, so whenever folded blocks deactivate (client-side /compact archive, orphan-GC, tier distillation, host expand) the column collapses to 0 even though real folds happened — tool-driven ACP folds are most exposed because that path runs right next to native compaction. Credit the gross r.tokensCompressed at the single applyRanges success point shared by all lanes (tool-driven proxy/plugin folds AND preflight): refused paths return earlier, partial folds count only successful ranges, in-place refolds report tokens 0 — no double counting. The counter persists across restarts (stats round-trip). Also correct two stale comments that claimed #2734 removed the last writer (the counter died at the kernel import; #2734 was web-only).
Owner
Author
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复 — 这是 #4700 的实现 PR(Closes #4700),open/closed 里没有第二个同主题条目(失败签名:web SAVED 列在折叠块失活后归零;机制:fold 提交点从不写 标签: bug + scope/kernel + p3(纯展示面缺陷——SAVED 列显示 0 而非累计值,无功能影响)。 收到。按 [PR] 流程不重做,只做核对:拉分支对代码、查 CI、处理分支落后问题。已用工具核实的事实:
接下来:rebase 到最新 master → 解冲突 → 本地 typecheck + 定向测试 → push → 等 CI 全局判定。完成后按八问回复结论。 |
ranxianglei
force-pushed
the
2026-10-25_4700-tokens-saved
branch
from
October 25, 2026 14:43
a45eb8e to
ca67657
Compare
Owner
Author
Contributor
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6151-pr.4723.c2df808This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4723.tgz
npm install -g packageInstall instructions are refreshed on each push. |
added 4 commits
October 26, 2026 10:15
master window commits 293ae65/de5e03659 bumped kernel/package.json to 0.0.165 without regenerating the lockfiles; lock-sync re-resolution then rewrites the stale recorded versions (root 0.0.163, kernel 0.0.164) and fails. Pure recorded-version sync via npm install --package-lock-only; no dependency or semantic change.
This was referenced Oct 31, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4700
Root cause
session.stats.tokensSavedlost its writer at the kernel import: every fold lane stamps per-blockcompressedTokens, but nothing ever credited the session counter again (grep-verified: no incrementer anywhere insrc/). Since #2734 the web SAVED column ismax(counter, sum over ACTIVE blocks' compressedTokens)— so whenever folded blocks deactivate (client-side/compactarchive, orphan-GC, tier distillation, host expand) both terms are 0 and the column collapses to 0 even though real folds happened. Tool-driven ACP folds are most exposed because that path runs right next to native compaction.One correction to the issue report: on both v0.1.202 and master the kernel DOES stamp
compressedTokenson the blocks it creates (kernel/src/compress.tsapplySingleRange — identical code at the tag). The field lives insideblocks.payload_json; a plain SELECT over the table's top-level columns won't show it. Confirm with:SELECT block_id, json_extract(payload_json,'$.compressedTokens') FROM blocks WHERE session_id='…'. The actual defect is exactly what the issue's "Why" section says: neither term of the max() ever gets written by the fold path.Fix
Credit the gross
r.tokensCompressedat the singleapplyRangessuccess point insrc/stream.tsshared by ALL lanes (tool-driven proxy folds, plugin-lane/__bili/plugin/toolfolds, and preflight):r.tokensCompressedcounts only successful ranges;tokens: 0from the kernel → no double count;Web derivation unchanged:
Math.max(counter, activeSum)keeps pre-tagging sessions from regressing, and now the floor also covers folds whose blocks deactivated afterwards. Two stale comments claiming "#2734 removed the last writer" corrected (the counter died at the kernel import; #2734 was web-only).Behavior change (old → new)
/compactdeactivates both blocks.Config surface
None — no new/renamed/re-semantics config fields, env vars, or CLI flags.
Tests
tests/issue4700-tokens-saved.test.ts: successful fold credits the counter with exactly the block's gross; consecutive folds accumulate (the 12789+8214 shape); refused fold credits nothing; repeat call over an already-folded range credits nothing again; SAVED survives full deactivation mirroring the web derivation.tests/web-sessions.test.ts: new case — credited counter + all blocks inactive → detail AND list row keep showing the total (guards the floor semantics end-to-end).