Skip to content

fix(web): derive tokensSaved from active blocks; label frozen context/ledger windows - #2734

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-11_web-session-stats
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-11_web-session-stats

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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):

  1. tokensSaved: 0 — stats.tokensSaved is a dead counter: nothing increments it since the kernel import (only init=0, persist hydration, and web reads exist; git log -S tokensSaved shows the incrementer was refactored away). The page showed "saved 0" next to four real blocks (~63K folded).
  2. contextTokens: 271,902 frozen at 118% — a kind=upper estimate 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%.
  3. ledger.economics.folds = 0 — the cache-ledger window starts at the ledger (re)build point; after a multi-instance converge (#405/#2401 stale-snapshot guard) the window began mid-session, so 35 requests recorded only 14 and the fold event fell outside the window.

Fix

  • tokensSaved is now derived from active blocks (Σ compressedTokens) in summaryOf(), with the stored stat as a floor (pre-tagging sessions with a real accumulated value never regress). The SummarySource type is widened so the disk-scan normalizer (summaryFromRecord) carries active/compressedTokens through — list rows, detail rows, and dashboard totals all use the derived value.
  • The context bar gains a 快照 {age}前 / snap {age} ago chip sourced from contextMeasuredAt, so a frozen estimate self-labels instead of reading as the current sent view.
  • The hit-rate subline gains 账本未覆盖 N 请求 / ledger misses N reqs (requests − ledger.totals.requests) plus a ⟳ 重启丢窗 / restart drop ×N badge from ledger.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.ts 10/10 (new zh/en keys).
  • Full touched-surface set re-run green; tsc --noEmit clean; 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

…/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).
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_web-session-stats (b69b7d3)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2978-pr.2734.fc860d6

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

Option B — Download artifact

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

[bot] 🏷 收到,这是 agent 已备好的 PR(分支 2026-10-11_web-session-stats,单 commit,+77/-2)。正在按规范做结构化 review:核对 PR 声称的三个缺陷是否属实、回归面、测试有效性、diff 整洁度与 CI 状态。结论稍后以八问体例回复。

…not #2731

#2731 is the unrelated dsh-google-persona PR; this work has no separate
diagnostic issue, so #2734 (the [PR] tracking issue) is the correct ref.
@ranxianglei
ranxianglei merged commit aad0fee into master Oct 11, 2026
14 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.260-master.aad0fee (rolling master tag).

npm install -g billion-context@0.0.260-master.aad0fee  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
@ranxianglei
ranxianglei deleted the 2026-10-11_web-session-stats branch October 15, 2026 05:33
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant