feat(rollover): 批量 rollover 压缩 — Prompt Cache 稳定性主杠杆 (closes #241) - #243
Open
ranxianglei wants to merge 1 commit into
Open
feat(rollover): 批量 rollover 压缩 — Prompt Cache 稳定性主杠杆 (closes #241)#243ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
6 tasks
📦 Built Extension ArtifactBranch: Option A — Install from npm PR tag (recommended)pi install npm:billion-context-pi@pr-243Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pi-pr243.tgz
pi install ./packageThis comment is automatically updated on each push. |
Owner
Author
[bot] 收到,开始审查
有结论后在此回帖。 |
Owner
Author
[bot] 审查完成,结论:通过,验收标准全部独立复验。 验证结果(本地 checkout
关键设计点核实:
小问题(非阻塞):
按仓库约定 PR merge 由人工执行,我不代操作。 |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
#80 提出、#240 确认:压缩真实成本的大头不是写摘要的 output tokens,而是 Prompt Cache 失效——selective compression 在历史中间就地改写,把压缩点之后的整个后缀踢出缓存前缀,后续每轮按全价重算这段 input。
本 PR 实现 #241 的主杠杆:把频繁就地压缩变成偶发批量 rollover,让 model-visible history 在阶段内尽量 append-only。
方案(默认开启,
"rollover": false恢复旧行为)compress调用立即校验范围(坏范围仍当场报错、计入重试上限),但只把范围记录为 pending:原文保持可见,历史不改写。第 3 个 pending 调用起,kernel 的 KEEP_LAST_ORPHANED=2 会把最早的 pending 调用从历史中间隐藏——adapter 侧做了 restore 修复(按原始位置重新插入合成 tag 的消息,字节级与 kernel 渲染一致),保证前缀稳定。absorb({ref, summary}):把大型 tool output 蒸馏成模型自写的紧凑摘要;原文标记 pending drop、保持可见直到批量应用(复用 kernel 原生 applyAbsorb,纯函数校验)。rollover.threshold(默认 70%,刻意低于 75% 强制 nudge 带,保证 rollover 总在 nudge 升级前触发)时,一次性 applyCompression 全部 pending + 合并 absorb 记录:一次缓存失效摊薄整段。该轮追加一次性▣ ACP rollover | N compression(s) + M absorb(s) applied: X → Y tokens报告(瞬态尾部,下轮消失)。关键设计决策
"rollover": false(或{enabled: false})是逃生舱,恢复逐次就地压缩。.acp.json的rolloverPending字段(跨重启生效);顺带修复mergeInitialState丢弃absorbed字段的 bug(rollover 应用后重启会丢 absorb 记录)。acp_status新增Rollover: N pending ... (threshold 70%, current X%)行;/acp-rollover命令强制立即批量。验收标准
验证
npm run typecheck✅npm test→ 433/433 ✅(428 基线 + 5 新增;既有 60 处 createAcpExtension 调用显式rollover: false保留旧行为覆盖,prefix-stab 回归测试同处理)npm run build✅(dist/index.js 544 KB,acp-kernel 内联)