Skip to content

fix: bound CCR content-store envelope with byte cap + oldest-ref eviction (#1282) - #1288

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-09-25_ccr-store-byte-cap
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-09-25_ccr-store-byte-cap

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Closing — the cap/eviction design was explicitly rejected by the owner (#1282, closed not_planned): lossless is an absolute commitment. "Not retrieved so far" is not "never needed"; evicting an unretrieved ref is delayed loss, which is the exact failure mode CCR exists to eliminate. The store is supposed to be as large as the conversation it serves, shares the session lifecycle (#1189 companion GC), and its growth is already observable via acp_status (stored bytes / wire saved / retrieve rate). No byte cap, no eviction, ever.

Opened after the #1282 closure landed — see the decision record there for the full rationale.

…tion (#1282)

Since #1207 every compress fold persists covered originals into the session's .content-store.json on top of arrival-time oversized-result storing, so a heavy session's disk envelope approaches the full transcript and never shrinks while the session lives. Add a host-side per-session byte cap (kernel delegates retention downstream): compress.ccr.maxStoreBytes (absent=32MiB default, 0=unbounded, >0=cap bytes) enforced at both choke points (load + adoption-growth) with oldest-ref-first (mNNNNN ascending) dedup-aware eviction, per-ref [ccr] evict warn logs, honest retrieve misses for evicted refs, and acp_status surfacing of stored-of-cap utilization.
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_ccr-store-byte-cap (8d917be)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1288

Each push to this PR publishes a new version under the pr-1288 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1288.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] 🏷 收到。这是之前会话(处理 #1282 时)已完成的 PR,不重做——现在按 PR Review 规范走完整审查:核对分支代码与描述一致性、回归清点、代码审查、测试有效性、diff 整洁度,并确认 CI 状态。结论稍后贴在本 thread。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of PR #1288 complete (per [PR] protocol: verified, not redone). Verdict: mergeable — one small fix was found in review and committed directly to the PR branch (8d917bee); local typecheck + full test suite + build all green on that head. Please merge once CI goes green on the new head.

① Direction (original issue #1282) — checked against the issue: it documents that since #1207 every fold persists covered originals into .content-store.json with no cap or eviction anywhere → envelope ≈ full transcript, dying only with the session (#1189 GC), and asks for a conservative byte cap (~32 MB/session, configurable) + eviction with per-ref logging + acp_status surfacing, deferring tier-aware eviction. The PR implements exactly that scope: compress.ccr.maxStoreBytes (absent = 32 MiB default, 0 = unbounded, >0 = cap), oldest-ref-first eviction (author-flagged call vs true LRU — accepted; it encodes tier ordering for free), [ccr] evict warn logs per ref, acp_status STORE line. It fixes the root cause (the unbounded-growth mechanism), not a symptom. Both compression modes reasoned through — the cap is disk-side retention only; wire format is unchanged.

② Regression inventory (existing behaviors on touched paths, each judged):

  • Store growth path (adoptContentStore, all 7 call sites — server.ts ×6, preflight.ts ×1): preserved — enforcement runs after adoption, before stats; no-growth turns early-return as before.
  • Load path (contentStoreOf): intentional change, disclosed — legacy oversized files now trimmed to the current cap on first touch; disk converges on the next save (persist dirty flag honored). Rollback-safe both ways: pre-cap files load fine under an unbounded config; post-cap files are a JSON subset of the old format. No persistence version bump needed.
  • codex compact-forge path (src/server.ts:3437-3481): verified safe — the all-or-nothing prevStore/prevStoreDirty save/restore rolls evictions back cleanly on gate failure.
  • Kernel contract (ids never reused): untouched — eviction only mutates the content store, never session.state.messageRefs; no ref re-issue window.
  • Config parse: maxStoreBytes follows the exact sibling-key pattern (non-number / non-finite / <0 rejected). Note, pre-existing and NOT introduced here: a function-level ok guard means any invalid value anywhere drops the entire compress settings block — consistent with how existing keys behave; left as-is deliberately.
  • stats.storedBytes: intentional change, disclosed — now UTF-8 bytes over unique contents (was totalChars).
  • acp_status output: intentional change, disclosed — STORE line gains of <cap> cap (P%) when bounded.
  • Not touched: wire shape, tool-call arguments, nudge cadence, src/update.ts, kernel pin (still 0.0.86), release infra.

③ Code review: enforceStoreCap checked line by line — dedup-aware (a hash frees bytes only when its last ref is removed, with an undefined-text guard), oldest-first via /^m(\d+)$/ sort with non-matching refs evicted last, no-op fast paths (no store / unbounded / under cap), marks dirty only when something was actually evicted, and the pathological single-entry-over-cap case drains to empty without looping forever. In-place mutation is safe (host owns the store post-adoption; kernel processTurn is pure). Byte accounting sums content bytes only (JSON envelope overhead excluded) — an approximate cap by design, not a bug.

④ Test validity: the 7 new tests have teeth — real assertions on eviction counts/survivors/retrieve hit-vs-miss, dedup semantics, unbounded mode, the default constant, adopt-growth enforcement, plus a load-path e2e that persists an oversized file then reloads it under a tight cap and asserts both memory and file converge. No tautologies; each would catch its regression.

⑤ Diff cleanliness: 4 files, +244/−8, every line in scope; no lockfile/generated churn; single linear commit rebased onto current master (behind=0). CI was 9/9 green on 30574c95, including the real codex/pi e2e lanes.

Fix committed in review (8d917bee, labeled separately): after a restart, persisted stats restore the pre-trim storedBytes, and the load-path trim didn't refresh it — so the new "X of Y cap (P%)" line could display >100% until the next CCR fold arrived. One-line fix in contentStoreOf (refresh the stat when the trim evicted anything) + a regression assertion seeded with the stale value; verified red without the fix, green with it. Local on 8d917bee: typecheck clean, full suite 2499 pass / 0 fail / 9 skipped (gated e2e), build success.

一句话中文:修复了 CCR content-store 无上限增长、磁盘信封≈全量会话记录的问题(#1282)——新增 32 MiB 默认字节上限(可配,0=不限)+ 按最旧 ref 逐出并记日志;review 中另补了一个"重启后 storedBytes 统计过期导致显示超 100%"的顺手小修(已单独标注提交),本地 typecheck/全量测试/build 全绿,CI 绿后可合并。

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