Skip to content

feat: neverPreserveRecentTools config knob (acp-kernel 0.0.92) - #547

Merged
ranxianglei merged 5 commits into
masterfrom
2026-09-25_never-preserve-recent-config
Sep 25, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
2026-09-25_never-preserve-recent-config

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Exposes kernel neverPreserveRecentTools (acp-kernel #395, released in 0.0.92 — pin bumped here) as a top-level ~/.pi/acp.json key: tool-name patterns excluded from the soft-protected recent zone, so matching tool results inside the recent window become compressible immediately instead of aging out first.

Why (upstream billion-context #1198/#1277)

The kernel built-in list ["decompress", "search_context", "read", "bash"] keeps read/bash compressible because they are the largest reclaimable mass — but in batch-read workflows (upstream #1198: 1M window correctly detected, usage 11–18%) the compression cadence folds freshly-read files right away → the model re-reads them → growth triggers another fold → death loop (9 compressions in 26 min).

Recommended remedy (owner guidance on upstream #1277): remove only read —

{ "neverPreserveRecentTools": ["decompress", "search_context", "bash"] }

— fresh read results then stay in the recent zone and age out by position later (unlike protectedLatestTools, which would pin the newest read forever, or protectedTools, which would never fold any read). Keep decompress/search_context in the list: re-including them pins just-restored blocks in the recent zone where they become unreclaimable. [] is a valid max-protection escape hatch.

Changes

  • src/config.ts: AdapterConfig.neverPreserveRecentTools + passthrough into defaultConfig overrides (unset → kernel built-in governs)
  • src/user-config.ts: top-level acp.json key (KNOWN set) + applyUserConfig validation via a separate cleanNeverPreserveList — an EMPTY ARRAY IS VALID here, unlike the two protection keys' non-empty-array check
  • Docs: CONFIGURATION.md / CONFIGURATION.zh-CN.md (table row + full section with recommended-value JSON example)
  • chore: pin acp-kernel 0.0.92

Tests

tests/config.test.ts (+2): resolveConfig verbatim passthrough ([] included), unset → undefined. tests/user-config.test.ts (+5): acp.json pickup, [] accepted, trim + user-overrides-adapter, malformed falls back to adapter, malformed dropped when no adapter value. All 87 green in both files.

Full suite branch vs pristine master (same kernel tarball): failure sets identical (environmental), branch additionally passes one flaky file (restart-cache).

Refs upstream billion-context #1277 / #1198

Top-level acp.json key removed from the soft-protected recent zone
(kernel #395). Recommended remedy for the batch-read fold->re-read
loop (upstream billion-context #1198/#1277): remove only 'read',
keep decompress/search_context. Unlike the two protection keys an
empty array is a VALID max-protection escape hatch, so it is
validated separately from cleanProtectionList.

Refs #545
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-25_never-preserve-recent-config (98413b5)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-547

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr547.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,正在按 PR Review 规范审查:方向(上游 billion-context #1277/#1198)、回归面(config/user-config 既有行为)、代码、测试有效性、diff 整洁度。会本地拉分支跑 typecheck+test+build,并核对 acp-kernel 0.0.92 是否已发布到 npm(CI npm ci 依赖精确 pin)。结论稍后回复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

PR #547 Review — neverPreserveRecentTools 配置项

结论先行:方向正确、回归面干净、本地+CI 全绿、语义经端到端验证与文档一致。可以合并(按规则由人来合,我不代合)。

① 原 issue / 方向(最高优先)✓

上游 billion-context #1277/#1198:批量读文件工作流中,内核内置 neverPreserveRecentTools 让 read 结果立即可折叠 → 新鲜读入的文件刚读完就被折 → 模型重读 → growth 再触发折叠 → 死循环(1M 窗口、usage 仅 11–18% 时 26 分钟 9 次压缩)。本 PR 把内核(acp-kernel #395)已有的旋钮暴露为 ~/.pi/acp.json 顶层键,文档推荐值正是 owner 在 #1277 给的方向——只移除 read,保留 decompress/search_context/bash,并说明与 protectedTools/protectedLatestTools 的语义区别。修的是根因(最近区排除机制),不是症状。

② 回归审查(既有行为清点)✓

逐项判定触碰路径承担的既有行为:

既有行为 结论
未设置该键的用户 保持。resolveConfig 逐字透传 undefined(刻意不 ?? []);内核 isNeverPreserveRecent(dist :1202):patterns === void 0 ? 内置列表 : patterns → 内置列表接管。已 grep 确认 0.0.92 dist 无任何 ?? [] 强制转换;{...base,...overrides} 展开中显式 undefined 键安全(base 本无此键)
acp.json 未知键处理 有意变更(披露):此前写在 acp.json 里的 neverPreserveRecentTools 会被当未知键静默忽略,现在生效——这是功能本身,非回归
畸形值处理 保持 fail-loud:adapter 层 cleanNeverPreserveList warn + 回退(不合并不丢弃整个配置),内核层 validateConfig 第二道防线("must be a string array")
内核 pin 0.0.91→0.0.92 无隐藏漂移:diff 了两个版本的 dist,恰好 13 行,全部是该功能(validate 3 行 + isNeverPreserveRecent 参数化 5 行 + 调用点 1 行,余为上下文)。内置列表不变;0.0.91 精确匹配 .includes() → 0.0.92 matchToolPattern(新增前缀通配支持),对无通配的内置列表行为完全一致
ref-tag 渲染 / token 校准 / 前缀缓存 未触碰
host 检测 / stand-down、sidecar 格式、update.ts、identity/session 未触碰
本包 version 字段 未 bump(正确,content commit 不动版本)
README「What gets protected」 默认值未变,描述仍然准确(可选后续,不阻塞)

③ 代码审查 ✓

  • src/config.ts 逐字透传 + 注释写明「unset → 内置列表接管」,与内核契约一致;
  • src/user-config.ts 用独立的 cleanNeverPreserveList 而非复用保护键的非空校验——正确,空数组在此是合法的最大保护逃生门,复用会误杀;KNOWN 集合同步更新,不会误报未知键;
  • 无 as any/@ts-ignore,无多余注释。

④ 测试有效性 ✓

7 个新测试断言有牙,且钉住了关键分叉:[] 合法(与两个保护键的非空规则对比)、trim、user 覆盖 adapter、畸形回退矩阵(有/无 adapter 值两路)。adapter 层测形状是恰当的——内核侧语义我另行端到端验证(见下)。CI 全量套件 + e2e 兜底。

⑤ diff 整洁度 ✓

8 文件 +117/−6,每行都与本 PR 目的相关;lockfile 双处 0.0.92 + integrity 同步;无空白 churn、无跑题文件。head b3a4e59 基于当前 master(1a737da),无需 rebase。

本地验证(分支 worktree @ b3a4e59,npm ci)

  • typecheck 干净,build OK(dist/index.js 942KB,自包含);
  • 全量套件:分支 951 测 / 846 过 / 99 挂;pristine master(worktree @1a737da,kernel 0.0.91)944 / 839 / 99。失败集按名称排序后逐字节相同 → 99 个失败全部为预先存在的环境问题(沙箱 /tmp 只读 → session sidecar EACCES: permission denied, lstat '/tmp/pai-acp-*.acp.json'),无一由本 PR 引入;分支额外多过一个 flaky 文件(restart-cache),与 issue 描述一致;
  • 7 个新测试本地全部通过;
  • CI @ b3a4e59:pr-validation、test(ubuntu+windows × node22+24)、build-artifact、e2e(ubuntu+windows)、docker —— 全部 success;
  • npm:acp-kernel@0.0.92 已发布(latest)→ 跨仓发布顺序满足。

端到端行为探针(真实 resolveConfig → 真实内核 pipeline,观察最近区工具结果的折叠资格)

配置 read bash decompress search_context write
A 未设置(内置接管) 可折叠 可折叠 可折叠 可折叠 受保护
B [](最大保护) 受保护 受保护 受保护 受保护 受保护
C 推荐值 [decompress,search_context,bash] 受保护 可折叠 可折叠 可折叠 受保护

三例与 issue/文档描述逐字吻合;C 例即死循环修复路径——新鲜 read 留在最近区、随后按位置老化,而 bash/decompress/search_context 仍可立即回收。

Auto-merge gate

不适用:feat: + 配置 schema 面 + 跨仓内核 pin → 无论哪条都要求人工合并。审查过程中未发现需要直接补修的小问题,未向 PR 分支添加任何 commit。


中文摘要:审查了 neverPreserveRecentTools 配置项 PR(#547)——方向正确(治上游 #1277/#1198 批量读文件折叠死循环的根因),回归面干净(未设置时内核内置列表接管、既有用户行为零漂移,0.0.91→0.0.92 内核 diff 仅 13 行且全部为该功能),本地 typecheck/build/定向测试通过、99 个环境性失败与 master 基线逐字节一致,CI 全绿,推荐值语义经端到端探针验证与文档一致,可以合并。

…lusion list

The positive-facing counterpart of neverPreserveRecentTools: patterns
REMOVED from the effective exclusion list computed by the kernel
(acp-kernel >= 0.0.93). The #1198/#1277 batch-read fold->re-read
remedy is one entry, ["read"], without restating — or freezing a
copy of — the built-in list. [] is rejected (pure no-op here — a
near-certain typo for neverPreserveRecentTools: []).

Refs ranxianglei/billion-context#1277
@ranxianglei

Copy link
Copy Markdown
Owner Author

Added the positive-facing companion knob on top of this branch (c3c77f0):

preserveRecentTools (needs acp-kernel >= 0.0.93 — kernel PR ranxianglei/acp-kernel#428):

{ "preserveRecentTools": ["read"] }  // the one-entry #1198/#1277 remedy

Effective exclusion = (neverPreserveRecentTools ?? built-in) minus preserveRecentTools — no restating/freezing of the built-in 4-entry list, keeps following built-in evolution. Composable with an explicit neverPreserveRecentTools; glob subtraction; unset = no-op. [] is rejected (pure no-op here — a bare [] is almost certainly a typo for neverPreserveRecentTools: []; malformed values warn + fall back to the adapter value).

Wiring: UserAcpConfig/KNOWN/applyUserConfig (new cleanPreserveRecentList with the typo-hint warning) + AdapterConfig field + resolveConfig defaultConfig overrides passthrough. Tests: +1 resolveConfig verbatim, +3 applyUserConfig (trim+override / reject-[] / malformed fallback) — config + user-config files 91/91, tsc --noEmit clean against the packed #428 tarball. Docs: CONFIGURATION en/zh table rows + full sections.

Kernel pin bump to a real 0.0.93 follows after acp-kernel#428 merges & releases (tarball install is --no-save).

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

新 commit c3c77f0(preserveRecentTools 正向旋钮)审查

代码、测试、文档都扎实,内核侧契约也核对一致——但当前 head 的 CI 全红且无法合并,原因与你的计划完全吻合(等 #428 → 0.0.93 → pin bump)。逐项如下。

① 方向 / 设计 ✓

正向配对的语义选得很好:(neverPreserveRecentTools ?? built-in) minus preserveRecentTools,单条 ["read"] 即 #1198/#1277 解法,不重述(不冻结过时手抄)内置列表、跟随内置演进。拒绝 [](纯 no-op,裸 [] 几乎必是 neverPreserveRecentTools: [] 的笔误)+ 告警文案直接给出正确写法——比静默接受好。

② 内核侧契约核对(acp-kernel#428 diff 已逐行看)✓

  • isNeverPreserveRecent(msg, patterns, preservePatterns):base = patterns ?? 内置;preservePatterns unset/空 → 原样;否则 base.filter(tool => !preservePatterns.some(p => matchToolPattern(tool, p))) —— glob 后缀对列表项做减法,与 PR 正文和 CONFIGURATION.md(en/zh)逐字一致;
  • 调用点、Config 类型字段、validateConfig("must be a string array")、内核侧 +126 行测试(内置减法 / 显式列表组合 / glob 与无匹配容忍)齐全;
  • 一个细节:内核层 validateConfig 对 preserveRecentTools: [] 是放行的(空数组是合法 string array),空数组拒绝策略只在 adapter 层执行——这是有意的严格化,合理,不算不一致。
  • 顺带:release v0.1.69 #428 里夹了一个 .gitignore +*.tgz(tarball 实验产物),无害,归那个 PR 自己审,不阻塞这里。

③ 本地验证(分支 worktree @ c3c77f0,npm ci = pinned 0.0.92)

检查 结果
tests/config.test.ts + tests/user-config.test.ts 91/91 通过(与你声明一致;新测试都是 shape 级,不依赖 0.0.93)
运行时安全(0.0.92 下带该键跑 processTurn) ✅ 无 validateConfig 告警刷屏,键被静默忽略(no-op),不会在 pin bump 前污染用户日志
npm run typecheck ❌ 失败:src/config.ts(585,5): error TS2561: 'preserveRecentTools' does not exist in type 'Partial<Config>'. Did you mean to write 'preserveRecentTokens'?
npm run build ❌ 同错(build 脚本含类型检查步骤,tsup 本体成功但整体非零退出)

④ 阻塞项:CI 红(已确认,非猜测)

GitHub check-runs @ c3c77f0:test(ubuntu/windows × 22/24)、build-artifact、e2e(×2)、docker 全部 failure,仅 pr-validation success。根因就是上表 TS2561——CI 顺序 npm ci → typecheck → build → test,typecheck 挂掉后全线连带。这个 head 现在不可合并。

合并路径(建议,无歧义版)

不需要改这个 commit,也不需要拆 PR。按你写好的顺序走完即可:

  1. acp-kernel#428 合并(目前仍 open,head d54835b;npm latest 仍是 0.0.92);
  2. 0.0.93 发布后先验证:npm view acp-kernel version == 0.0.93(跨仓发布顺序铁律);
  3. 本 PR 追加 pin-bump commit(package.json + package-lock.json,精确版本,不加 ^);
  4. CI 转绿后由人合并整个 PR(两个旋钮一起进)。

当前状态是一个正确的中间态:adapter 侧就绪、运行时安全、文档诚实标注了「requires acp-kernel >= 0.0.93」,只差内核发布这一环。


中文摘要:审查了新 commit c3c77f0(preserveRecentTools 正向旋钮)——代码/测试(91/91)/中英文档均合格,内核 #428 实现与文档契约逐字一致、运行时在 0.0.92 下安全无副作用,但因本 commit 仍 pin 0.0.92(类型缺该字段),typecheck/build 必然失败、CI 实测全红,暂不可合并;待 #428 合并、0.0.93 发布并追加 pin-bump commit 转绿后即可整体合并。

…l 0.0.92

The kernel pin is still 0.0.92 until acp-kernel#428 (preserveRecentTools,
0.0.93) is released; Partial<Config> from 0.0.92 rejects the key at the
literal. Annotated overrides object compiles against both versions; the
property rides defaultConfig's spread and is ignored by kernels that
don't read it.
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