Repository navigation
fix: keep the full per-request cache ledger history (#1489) - #1490
Conversation
The ledger arrays (lines/folds) were capped at write time — SAMPLE_CAP 512 / FOLD_CAP 256 spliced off the OLDEST entries, permanently destroying per-point history: the web trajectory chart could only draw from the earliest retained sample, silently truncating long sessions. - Remove both caps: every sample and fold is now retained for the whole session lifetime. Aggregates were already exact; linesOmitted stays a field so sessions trimmed before this fix keep their historical deficit honestly recorded (it is 0 for everything recorded after the upgrade). - handleAcpCache detail:"full": window the TEXT view to the newest 512 lines (kernel's own maxLines rendering, "older outside window" note) so an unbounded ledger cannot flood the caller's context. Data layer and JSON endpoints (/__bili/cache-report) remain complete. - Tests: replace the ring-eviction test (which pinned the truncation) with unbounded-retention tests past the old caps + text-windowing test.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1416-pr.1490.5a44b6aThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1490.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review of PR #1490(针对 issue #1489) ① 方向关(原 issue):方向成立。已对照 master 验证: ② 回归清单(diff 触碰的既有行为,逐项结论):
③ 代码审查:
④ 测试有效性:
⑤ diff 整洁度:2 文件 +51/-14,无跑题改动、无空白噪音。干净。 验证证据(本地于 PR head 6ae3e71 实跑):
#1426 协调:仍 open(head 结论:方向正确、根因命中、回归清单完整(含一处新披露的 summary 扫描范围行为差异)、测试有牙并补了一处缺失覆盖、diff 干净、CI 全绿。可以合并(合并操作留给人)。 中文一句话总结:审了 PR #1490(移除缓存台账 512/256 上限、全量保留会话历史)——方向正确、根因命中,直接在 PR 分支补了 legacy 缺口交互测试(cd0bbcd)、并在 PR 描述里披露了 summary 模式扫描范围的行为差异,本地三项检查与 CI 全绿,可以合并。 |
[bot] 🏷 补充:补测 commit |
What & why
Per-session cache ledger arrays were capped at write time (
SAMPLE_CAP = 512,FOLD_CAP = 256insrc/cache-ledger.ts): past the cap the OLDEST entries were spliced away at record time and are unrecoverable. Aggregates stayed exact, but all per-point history after the cap was silently destroyed — the web trajectory chart could only draw from the earliest retained sample (issue repro: session started 09-25, ~1483 requests, chart showed only 09-26+).The mitigation already shipped in #1426/a0fc322a (cap 512→4096) only postpones this: "one session per month, billions of tokens" is the core selling point. Per owner direction in the issue (「所有数据都应该能留下来」), this removes the caps entirely.
Changes
src/cache-ledger.ts): every sample and every fold is retained for the whole session lifetime. Same root cause for both arrays (capped array splicing oldest), so both go in one fix — fold markers/economics now also cover the full span, which the trajectory chart overlays.handleAcpCachedetail:"full" gets a render window: the text listing shows the newest 512 lines with the kernel's ownLINE ITEMS (last N of M)header marking the windowed view (the kernel's existingmaxLinesrendering semantics). The data layer, aggregates, and the JSON endpoint/__bili/cache-reportremain complete. Rationale: with an unbounded ledger, an uncappeddetail:"full"dump would flood the calling model's context (a 10k-request session ≈ ~700KB of line text); summary mode's output stays bounded (same digest caps); its anomaly/TTL-spike scan now spans the full history instead of the retained tail for sessions past 512 samples — more accurate diagnostics, same output size.tests/cache-ledger.test.ts): replaced "ring eviction keeps aggregates exact" — which pinned the truncation itself (520 samples → 512 kept,linesOmitted: 8) — with unbounded-retention tests past the old caps (600 samples / 260 folds, seq starts at 1,linesOmitted: 0, aggregates exact) plus a text-windowing test fordetail:"full"and a legacy-deficit test pinning that pre-upgrade trimmed sessions keep their historicallinesOmittedhonest through the window.No config surface added (option 4 from the issue deliberately not taken — nothing new to configure once there is no cap). No kernel changes needed:
linesOmittedis already a first-class report field.Behavior changes (old → new)
acp_cache detail:"full"text outputLINE ITEMS (last N of M)header when more existacp_cachesummary digest scan rangelinesOmittedSessions ≤512 samples: byte-identical behavior everywhere.
Coordination note: PR #1426 (issue #1420 web UI rewrite)
#1426's commit a0fc322 (branch
wt-1420-ework-daemon) raises the SAME constants (512→4096) and adds i18n strings hardcoding "4096". If #1426 merges first, rebase this PR onto it — resolution is union of intent: keep the removal, drop the now-stale "4096" strings. If this merges first, #1426 rebases onto the removed lines. Either way the conflict is one hunk. Also for #1426's authors:trajectorySvgrenders every received line as an SVG point with no client-side decimation — designed around ≤4096 points; with unbounded ledgers please decimate client-side for display (data stays complete server-side).Pre-flight
npm run typecheck: cleannpm test: 2909 pass / 0 fail (12 skipped = gated e2e suites)npm run build: successFixes #1489