Repository navigation
feat: per-request cache reconciliation ledger (acp_cache tool) - #804
Conversation
[bot] 🏷 Review complete — code verified good; CI is red solely because of the unpublished dependency. What I verified
Non-blocking observations (noted, no action taken)
Remaining blockers, in order
📝 中文摘要:代码审查通过,并已用内核 PR #297 的精确 head 本地全量验证(typecheck 干净、1617 个测试全部通过、构建成功);当前 CI 红仅因 acp-kernel@0.0.73 未发布。下一步:合并内核 PR #297 → 发布 v0.0.73 → 在本分支刷新 lockfile(release CI 用 |
|
解决冲突 解决ci失败 |
Issue #800: prove with data that compression does not wreck the prompt cache. Every provider usage report is decomposed into an exact additive identity — missed = new content + compression re-pay + ttl/other — so the grand ledger always closes against the provider-reported totals. - src/cache-ledger.ts: session-scoped ledger in metadata.cacheLedger (512-line ring + exact aggregates + fold events with measured T/h/k); folds detected from state.blocks diff (proxy mode eager at applyRanges, plugin mode lazy at usage time), X via tokenSnapshot prefix sums; incremental math delegates to acp-kernel decomposeSample so streaming and batch reports agree bit-for-bit. - executeProxyTool / executeAnthropicProxyTool dispatch the new read-only acp_cache tool (kernel-defined) -> formatted report. - GET /__bili/cache-report?session=<id> management endpoint (JSON). - recordUsage (proxy mode) and applyUsageSample (plugin mode) feed the ledger; acp-kernel pinned to the release containing PR ranxianglei/acp-kernel#297.
cbc298c to
8abb9bc
Compare
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-804Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr804.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Done — conflicts resolved and CI fully green. Pushed rebased head Root causes
What the rebase does
Evidence
Rebase 到最新 master(v0.1.118)解决了冲突:保留 kernel 0.0.77 固定版本、去掉 master 临时加上的 acp_cache 屏蔽(本 PR 正是它的执行路径,随本 PR 一起上线),lockfile 已同步;原 CI 全红是因为旧分支基于旧代码且当时 acp-kernel@0.0.73 尚未发布导致安装失败——现在 8 项 CI 全绿、无冲突,可以合并(合并由你操作)。 |
Issue #800 (part 2/3 of three-repo change; kernel core: ranxianglei/acp-kernel#297)
What
Prove with data that compression does not wreck the prompt cache. Every provider usage report is decomposed into an exact additive identity:
so the grand ledger always closes against provider-reported totals (
identity check OK — IN = C + NC + CR + TR, printed in every report — a broken implementation cannot hide).compRepayis capped at the structural excess beyond the fold's divergence point (X), so compression is only charged for re-pay it actually caused; everything else in the stable prefix lands honestly inttl/other(TTL expiry / eviction).Changes
src/cache-ledger.ts(new): session-scoped ledger persisted insession.metadata.cacheLedger— 512-line ring + exact running aggregates (survive ring eviction and restart) + fold events carrying measured T/h/k counters.state.blocksdiff against a persisted high-water mark: proxy mode eagerly at theapplyRangessite (with V/V′ geometry), plugin mode lazily at usage time (pi creates blocks locally; bootstrap guard ignores pre-existing blocks).tokenSnapshotprefix sums over ref order (kernel contract: refs are chronological, never reused).decomposeSample— the same functionbuildCacheReportuses internally — so streaming and batch reports agree bit-for-bit (test asserts equality on identical raw data).executeProxyTool(OpenAI/Responses) andexecuteAnthropicProxyTool(Anthropic) both handle the new read-onlyacp_cachetool → formatted report text. Registered to the model in all proxy-mode wires via the kernel arrays.GET /__bili/cache-report?session=<id>(defaults to most recent) → JSON{reports:[{id,report}]}; loopback+origin guards apply as with/__bili/stats.recordUsage(proxy mode, per upstream round) andapplyUsageSample(plugin mode, per client request) feed the ledger with normalized cached-inclusive input totals.package.json: acp-kernel pinned0.0.72 → 0.0.73(first release containing feat: cache reconciliation core (acp_cache tool + buildCacheReport) acp-kernel#297)。Pre-flight
Known limitations (documented in module header)
ttl/otherbucket (they are not folds).tokenSnapshotholds first-render estimates, and provider-side tokenization differs slightly.npm install(notnpm ci) and re-resolves once the version exists.