Skip to content

feat: report new block ids and actual ref spans in compress result panel (#376) - #377

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-11_compress-result-block-spans
Sep 12, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-11_compress-result-block-spans

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

背景

#375 中发现:模型对"之前的压缩块覆盖到哪里"的记忆与 nudge 推荐的 ranges 矛盾,被迫先调 acp_status 验证再执行(~1.8K tokens + 一轮 LLM)。根因:compress 结果行只报 N blocks,不报新块 ID 与实际覆盖——模型只能从自己提交的 startId/endId 推断;而 kernel 的保护排除与 turn-integrity 撤回会在事后改变实际范围,每次 compress 后块账本都偏差一点,累积到与 nudge 冲突。

改动

  • src/compress-tool.ts:新增 blockSpanLabel(block, state)——取 effectiveMessageIds 的首尾 ref 作为实际跨度(而非请求边界);跨度内存在仍存活但未被该块覆盖的 ref(被保护/撤回排除)时标 *;tier ≥ 2 标 (T2)/(T3);单消息跨度渲染为裸 ref(与 kernel 渲染约定一致);无法解析 ref 时退化为裸块 ID。
  • 成功面板逐块列出新块:
    ▣ ACP | 61.1K → 13.7K tokens (~47.4K reclaimed, blocks: b3=m00044–m00097*, b4=m00103–m00123*)
  • 0-block 运行保持旧格式 0 blocks(与 dead/cap 拒绝面板一致);compressPanelBlocks 双格式兼容——index/floor-stale 的日志回放路径必须继续解析历史 transcript 里的旧面板。

测试

  • 新增 9 个测试:e2e 结果格式断言(多块逐一列出;partial 运行只列创建的块)、blockSpanLabel 单元(连续 / 内部排除 * / 尾部排除不标 * / 编号空洞非排除 / 单消息裸 ref / tier 标注 / 不可解析退化)、解析器双格式兼容。
  • 更新 7 处旧 /1 block/ 断言(decompress-cmd、integration ×5、view-recount)——它们对真实输出断言旧格式,随本次有意的输出契约变更同步更新。
  • 全量:657 pass / 0 fail / 3 skipped(skipped 为既有);typecheck + tsup build clean。

无 acp-kernel 依赖 bump——纯本仓库改动。配套 acp-kernel#251(nudge 块地图)落地后,两项共同消除验证性 acp_status 往返。

Fixes #376

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-11_compress-result-block-spans (f54ef35)

Option A — Install from npm PR tag (recommended)

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

Each push to this PR publishes a new version under the pr-377 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-pr377.tgz
pi install ./package

This comment is automatically updated on each push.

…parens

compressPanelBlocks' span-form branch captured with `[^)]*`, which stops at
the ")" inside tier labels like `b3(T2)=...`, undercounting any batch whose
first new block is T2/T3 (two T2 blocks parsed as 1). Both current consumers
use only boolean >0/===0 so nothing breaks today, but that still violates the
function's own "block count" contract for a reachable input. Count the
`bN=`/`bN(Tn)=` label tokens in the header line instead. Exported for direct
unit testing + regression test. Review fix on #377 (feature #376).

typecheck + tsup build clean; 658 pass / 0 fail / 3 skipped.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Reviewed against master. Diff is clean — 5 files, all feature-scoped, no whitespace/unrelated churn. Ran typecheck + tsup build + full suite on the head: baseline 657 pass / 0 fail / 3 skipped, matching your claim.

Found one real defect in the new parser and fixed it directly on the branch (commit f54ef35, now pushed to 2026-09-11_compress-result-block-spans):

Bug — compressPanelBlocks parsed the new span form with / , blocks: ([^)]*)\)/. The capture stops at the first ), but tier labels carry a paren: b3(T2)=…. So any batch whose first listed block is T2/T3 undercounts: blocks: b3(T2)=…, b4(T2)=… parses as 1 instead of 2. Verified empirically: single-T1→1, two-T1→2, T1-then-T2→2, two-T2→1, legacy N blocks→correct.

Impact — none in the current tree. Both consumers (src/index.ts:711, src/floor-stale.ts:52) use only the boolean forms (>0 / ===0), and the span path can never return 0/-1 for a real success panel, so nothing breaks today. But it violates the function's own "block count" contract for a reachable input (a batched call whose earliest-created block is T2/T3), and would silently bite any future consumer that trusts the exact count.

Fix — count bN= / bN(Tn)= label tokens in the header line instead of capturing to ). Exported compressPanelBlocks for direct unit testing (matches the file's existing pattern of exporting blockSpanLabel/tailRepair) + added a regression test covering the two-T2 case. Re-ran after the fix: typecheck + build clean, 658 pass / 0 fail / 3 skipped.

Everything else checks out:

  • blockSpanLabel's actual-span logic is correct and well-covered — lo/hi from effectiveMessageIds, interior-exclusion *, trailing-not-starmed, numbering-gap-isn't-an-exclusion, bare single ref, tier mark (T2)/(T3), unresolvable→bare block id.
  • Dual-format backward-compat for legacy N blocks / 0-block panels is preserved, so the index/floor-stale transcript-replay path still parses historical panels.
  • No acp-kernel bump needed — confirmed pure-source change.

Verdict: mergeable — the fix commit is already on the PR branch; no further changes required from me.

一句话中文总结:修复了新增 compressPanelBlocks 解析器对带 (T2)/(T3) 括号的块标签会截断计数的问题(首个新块为 T2/T3 的批量压缩会被少算块数——当前无实际功能影响,但违反函数自身"块计数"契约),已改为按块标签 token 计数并补了回归测试,可以合并。

@ranxianglei
ranxianglei merged commit 350efbb into master Sep 12, 2026
9 checks passed
ranxianglei pushed a commit that referenced this pull request Sep 12, 2026
Enables the nudge-side half of the #375 fix: active block map
('Active blocks (N): b1=m00001–m00009 · …') and per-range user-msg
counts in efficiency/emergency nudges. Nudge text is rendered by the
kernel (renderNudgeText), so no adapter code changes are needed.
The compress-result block spans (#376) already shipped via #377.
ranxianglei added a commit that referenced this pull request Sep 12, 2026
…anel-format

test(export): assert post-#377 panel format in setupSession
ranxianglei pushed a commit that referenced this pull request Sep 12, 2026
ranxianglei pushed a commit that referenced this pull request Sep 12, 2026
ranxianglei added a commit that referenced this pull request Sep 12, 2026
…ale-assertion

fix(tests): use isCompressSuccessText in export-cmd setupSession (stale /1 block/ after #376/#377)
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
…ompress calls (ranxianglei#336)

Exact semantic alignment with opencode-acp ranxianglei#377 (owner-locked design):
compress calls are hard-exempt from compression, so their thinking rides
along every request as an unreclaimable context floor. A request-time
pass (src/reasoning-drop.ts) removes thinking parts only when ALL gates
hold: closed turn (strictly before the last genuine user message),
compress toolCall selector, and total reasoning length strictly exceeds
threshold chars (2048 default, summed per-message; 0 drops any
non-empty). The active round is never touched; persisted history is
never modified; pure/idempotent/fail-safe.

Config: compress.reasoning { drop, threshold } merged field-wise across
the existing three levels (model > provider > global). OpenAI-style
opaque reasoning opts out per-provider:

  { "compress": { "providers": { "openai": { "reasoning": { "drop": false } } } } }

Applied to the rebuilt outgoing view BEFORE the nudge push so a
synthetic user-role nudge can never become the boundary.

Fixes ranxianglei#336
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
…parens

compressPanelBlocks' span-form branch captured with `[^)]*`, which stops at
the ")" inside tier labels like `b3(T2)=...`, undercounting any batch whose
first new block is T2/T3 (two T2 blocks parsed as 1). Both current consumers
use only boolean >0/===0 so nothing breaks today, but that still violates the
function's own "block count" contract for a reachable input. Count the
`bN=`/`bN(Tn)=` label tokens in the header line instead. Exported for direct
unit testing + regression test. Review fix on ranxianglei#377 (feature ranxianglei#376).

typecheck + tsup build clean; 658 pass / 0 fail / 3 skipped.
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
…ss-result-block-spans

feat: report new block ids and actual ref spans in compress result panel (ranxianglei#376)
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
Enables the nudge-side half of the ranxianglei#375 fix: active block map
('Active blocks (N): b1=m00001–m00009 · …') and per-range user-msg
counts in efficiency/emergency nudges. Nudge text is rendered by the
kernel (renderNudgeText), so no adapter code changes are needed.
The compress-result block spans (ranxianglei#376) already shipped via ranxianglei#377.
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
…port-test-panel-format

test(export): assert post-ranxianglei#377 panel format in setupSession
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
…port-cmd-stale-assertion

fix(tests): use isCompressSuccessText in export-cmd setupSession (stale /1 block/ after ranxianglei#376/ranxianglei#377)
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.

compress 工具结果缺少新块 ID 与实际 ref 跨度,模型块账本随会话漂移

1 participant