Repository navigation
fix(web): derive tokensSaved from active blocks; label frozen context/ledger windows - #2734
Merged
Merged
Conversation
…/ledger windows
Three web-detail numbers lied after a session restore or idle gap:
1. stats.tokensSaved is a dead counter (no incrementer since the kernel
import; restored sessions carry a stale stamp, newer ones 0) — the page
showed 'saved 0' next to four real blocks. The web summary now derives
the value from active blocks (sum of compressedTokens, live and
disk-scan paths — SummarySource widened through the record normalizer)
with the stored stat as a floor; list, detail and dashboard agree.
2. The context bar number freezes at the last measure/estimate (kind=upper
stamps only go up, never refresh on restore/idle) — add a 'snap {age}
ago' chip sourced from contextMeasuredAt so an old bound cannot read as
the current sent view.
3. The cache ledger only covers requests since its last (re)build — after a
multi-instance converge (#405/#2401) the window starts mid-session and
folds inside the gap vanish from economics. The hit-rate subline now
states 'ledger misses N reqs' (requests minus ledger.totals.requests)
and badges restart drops from ledger.restartDrops.
Tests: tests/web-sessions.test.ts derivation case (dead stat 0 -> 1500
from 2 active blocks, inactive excluded, list/detail agree, larger legacy
stat wins as floor).
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2978-pr.2734.fc860d6This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2734.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Owner
Author
[bot] 🏷 收到,这是 agent 已备好的 PR(分支 |
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.260-master.aad0fee # this exact build
npm install -g billion-context@master # always the newest merged build
|
Merged
antclt
pushed a commit
to antclt/billion-context
that referenced
this pull request
Oct 18, 2026
logColdLoad printed session.stats.tokensSaved, but since ranxianglei#2734 nothing in the tree increments that counter, so the line always showed a stale zero (tests hand-set 42000 to fake it). Read the kernel's live counter state.stats.compressionCount instead — it starts at 0, is bumped on every fold, and round-trips with the persisted state.
ranxianglei
pushed a commit
that referenced
this pull request
Oct 25, 2026
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).
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.
Problem (diagnosed live on a DSH/qwen session)
After a session restore or an idle gap, three numbers on the web session detail page were wrong or misleading, while the compression engine itself worked fine (4 real blocks, 69% shrink):
tokensSaved: 0—stats.tokensSavedis a dead counter: nothing increments it since the kernel import (only init=0, persist hydration, and web reads exist;git log -S tokensSavedshows the incrementer was refactored away). The page showed "saved 0" next to four real blocks (~63K folded).contextTokens: 271,902frozen at 118% — akind=upperestimate stamp from the restore moment (includes compressed originals, only goes up, calibration 1.24×) that never refreshes on idle/restore, so the page reads permanently over-limit while the real sent view is 33%.ledger.economics.folds = 0— the cache-ledger window starts at the ledger (re)build point; after a multi-instance converge (#405/#2401stale-snapshot guard) the window began mid-session, so 35 requests recorded only 14 and the fold event fell outside the window.Fix
tokensSavedis now derived from active blocks (Σ compressedTokens) insummaryOf(), with the stored stat as a floor (pre-tagging sessions with a real accumulated value never regress). TheSummarySourcetype is widened so the disk-scan normalizer (summaryFromRecord) carriesactive/compressedTokensthrough — list rows, detail rows, and dashboard totals all use the derived value.快照 {age}前 / snap {age} agochip sourced fromcontextMeasuredAt, so a frozen estimate self-labels instead of reading as the current sent view.账本未覆盖 N 请求 / ledger misses N reqs(requests − ledger.totals.requests) plus a⟳ 重启丢窗 / restart drop ×Nbadge fromledger.restartDrops, making the ledger window explicit.Tests
tests/web-sessions.test.ts: new derivation case — dead stat 0 → 1500 from 2 active blocks (inactive excluded), list/detail agree (disk-scan path), larger legacy stat (9999) wins as floor. 20/20 green.tests/web-i18n.test.ts10/10 (new zh/en keys).tsc --noEmitclean; unused-export gate clean.No config or env surface. Engine behavior untouched (display layer only).
prepared by an agent under the local git identity (ranxianglei), human merge required