Skip to content

obs: per-request [acp-usage] on the plugin path + fold-materialization anchor ceiling - #696

Merged
ranxianglei merged 1 commit into
masterfrom
obs/plugin-cache-usage-695
Sep 10, 2026
Merged

obs: per-request [acp-usage] on the plugin path + fold-materialization anchor ceiling#696
ranxianglei merged 1 commit into
masterfrom
obs/plugin-cache-usage-695

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #695

背景

用户报告 plugin 会话「压缩后缓存掉 0」。现场调查(见 issue)只能给出理论上限 ≈15–18%(系统提示+块摘要),无法区分折叠物理上游逐出,因为 plugin 路径没有任何 per-request 日志(wire 路径有 [acp-usage],plugin 路径静默更新内存)。

改动(纯观测,零行为变化)

  1. plugin 路径 per-request [acp-usage](src/plugin.ts applyUsageSample,现导出供测试):
    [<sid>] [plugin] [acp-usage] input=50000 cached=8000 (cache hit 16%) ctx=51200 fold=new
    • fold=new 精确标出折叠落地的那一个请求(applyRanges 置位 → 首个 usage 报告消费)
    • cached 缺失时打 cached=n/a,不算命中率
  2. [acp-compress-obs] 扩展锚点估计(src/stream.ts):
    ... anchor≈1234 tok (3 active blocks, sys excluded) postCtx≈31000 → next-request cache ceiling ≥3%
    • anchor = Σ active 块 summary chars/4(下界,sys 未知)
    • 下一请求真实 cached ≈ ceiling → 物理保留;≪ ceiling → 上游逐出/争用
  3. wire 路径同标 fold=new(src/loop/core.ts)保持两条路径对称。
  4. Session.stats.pendingFoldUsage?: boolean(src/session.ts),内存态,不落盘。

验证

  • 新增 tests/usage-observability.test.ts 4 项:置位/锚点行字段、usage 行格式+fold 消费、无残留标记、cached=n/a
  • 全套 1322 pass / 0 fail(2 skip),tsc + build 绿

…n anchor ceiling (#695)

- applyUsageSample (plugin path) now logs one line per upstream usage
  report, mirroring the wire path's [acp-usage]: input/cached/hit%/ctx,
  plus a fold=new marker on exactly the request whose prompt first
  materialized a fold — the one whose prefix-cache hit is expected to
  cliff. Previously the plugin path updated in-memory stats silently,
  so post-fold cache drops could not be attributed from logs.
- applyRanges sets stats.pendingFoldUsage and extends [acp-compress-obs]
  with the surviving prefix anchor (active block summaries, sys
  excluded → lower bound), postCtx, and the next request's cache-hit
  ceiling. Real cached ≈ ceiling → fold physics; real ≪ ceiling →
  upstream eviction/contention.
- Wire path's [acp-usage] gains the same fold=new marker for parity.

Fixes #695
@github-actions

Copy link
Copy Markdown

📦 Built Package Artifact

Branch: obs/plugin-cache-usage-695 (d6b955a)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-696

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr696.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei
ranxianglei merged commit 0a88333 into master Sep 10, 2026
6 checks passed
This was referenced Sep 11, 2026
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.

Plugin path has no per-request cache usage log — post-fold 'cache drops to 0' cannot be attributed

1 participant