Skip to content

fix: withhold ACP compression surface below minCompressRange (#1112) - #1121

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-09-22_acp-surface-feasibility-gate
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-09-22_acp-surface-feasibility-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1112

Problem

A fresh Codex session below compress.minCompressRange (default 5000 chars) was already exposed to the full ACP surface from request one — compress/decompress/search_context/acp_status tools plus the kernel's compression philosophy prompt — while the kernel sums range chars against that same floor. Every compress call in such a session is therefore guaranteed to fail (Total compressible content too small (1990 chars …, min 5000)), and the model burned the first turn on follow-up acp_status/search_context rounds — including conversation_id: "current", taken verbatim from the param description "Defaults to the current conversation", which failed as an unknown session.

Verified against the injected surface (acp-kernel 0.0.82 buildCompressSystemPrompt() + tool schemas): nothing in it says compression is unavailable before the conversation can hold a viable range, and the philosophy section actively pushes compressing listed ranges. The proxy nudge was idle (as the issue log shows) — the trigger was the always-injected surface itself, not a proxy prompt.

Changes

  • Sticky feasibility gate — new exported armAcpSurface(session, msgs, minChars, log) in src/server.ts: ACP tools + philosophy prompt are injected only once visible conversation content reaches minCompressRange; arming is per-session sticky (one-time flip at the threshold, like nudges — no mid-session tool removal after native compaction shrinks history). Wired into all four wire paths (anthropic/openai/google/responses) and the stream-handler absorb re-check. minCompressRange <= 0 restores legacy always-on behavior.
  • Prepared.acpTurn — the compress-loop pipeline (usage accounting, tag stripping) keeps running for tracked turns even pre-arm; pipeline selection stays byte-identical to baseline for every request shape, only wire injection differs. Without this, sub-floor sessions lost usage capture and preflight/emergency went blind (caught by 21 regressions during development).
  • Conclusive failure receipt — src/stream.ts applyRanges: when the whole conversation holds fewer chars than the floor, NO range combination can succeed (the kernel sums across ranges against one threshold), so the standard failure receipt gains one appended sentence telling the model not to retry or inspect status and to continue the task. Kernel reason and the 出现持续压缩失败,无法自动恢复 #847 reversal note remain intact; when a larger viable range does exist, the generic advice is unchanged.
  • "current" alias — src/decompress-shared.ts executeSearchContextTarget: literal conversation_id: "current" (any case) resolves to the current session instead of unknown session "current".
  • Tests — new tests/fix-1112-acp-arm.test.ts (gate units incl. stickiness and the <=0 escape hatch; conclusive-vs-generic receipt receipts; end-to-end sticky arming through startServer with a mock upstream); [Bug] Codex 新会话首轮无可压缩内容仍调用 compress,低于 5000 字符阈值后进入 ACP 工具循环 #1112 alias case in tests/search-context-cross-session.test.ts; sixteen existing harnesses restored to the always-on surface via { compress: { minCompressRange: 0 } } because they assert wire mechanics on sub-floor fixtures (baseline always injected; their assertions were written against that).

Review notes

Wire-shape change affecting both compression modes' injection path → human review required per AGENTS.md §7.4 (no auto-merge claim). Plugin mode unaffected: the proxy injects nothing there; the gate only gates proxy-side injection. Side requests/title-gen/passthrough/transform-fallback paths keep the pipeline off exactly as before.

Pre-flight (rebased head = origin/master + this change)

  • npm run typecheck — clean
  • npm test — 2202 pass / 0 fail / 2 skipped (baseline master: 2193 pass / 0 fail / 2 skipped)
  • npm run build — OK

A fresh session below compress.minCompressRange (default 5000 chars) was already exposed to the full ACP surface — compress/decompress/search_context/acp_status tools plus the compression philosophy prompt — from request one, while the kernel sums range chars against that same floor: every compress call in such a session is guaranteed to fail, and the model then burned rounds on acp_status/search_context (including conversation_id "current" from the param description).

- armAcpSurface (src/server.ts): sticky per-session feasibility gate; the ACP tools + philosophy prompt are injected only once visible content reaches minCompressRange. minCompressRange <= 0 restores legacy always-on. Wired into all four wire paths and the stream-handler absorb re-check.
- Prepared.acpTurn: keeps the compress-loop pipeline (usage accounting, tag stripping) running for tracked turns even pre-arm, so pipeline selection is byte-identical to baseline; only wire injection differs.
- applyRanges (src/stream.ts): when the whole conversation is below the floor, append a conclusive verdict (no range can succeed yet; do not retry or inspect status) to the standard failure receipt — kernel reason and #847 reversal note stay intact.
- executeSearchContextTarget (src/decompress-shared.ts): literal conversation_id "current" (any case) aliases to the current session instead of failing with unknown-session.
- Tests: new tests/fix-1112-acp-arm.test.ts (gate units, verdict receipts, end-to-end sticky arming through startServer); #1112 alias case in tests/search-context-cross-session.test.ts; sixteen harnesses restored to the always-on surface via { compress: { minCompressRange: 0 } } because they assert wire mechanics on sub-floor fixtures.

Pre-flight on rebased head (origin/master + this change): typecheck clean, 2202 pass / 0 fail / 2 skipped, build OK.
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-22_acp-surface-feasibility-gate (5396c0c)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1121

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

#1112's arm gate makes the filler-less warmup turn structurally lighter than
steady state (below minCompressRange it carries no ACP tools/philosophy
prompt), so it became the new min and tripped the peak <= min*1.3 bound
(CI e2e-fake-codex: PR warmup 45003B vs master 58814B; load turns are
byte-comparable across both, ratio 1.0145). The bound targets the
filler-injected steady state, so measure it over load turns; unbounded
growth still trips it within two turns.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of #1121 — verified against the rebased head (base = current origin/master 14d06f1, no drift). Local gates on the PR head: npm run typecheck clean, npm test 2202 pass / 0 fail / 2 skipped, npm run build OK.

What I verified

  • Sticky gate: armAcpSurface flips once per session; metadata.acpArmed survives restarts (persist write/read round-trip confirmed in src/persist.ts). All four wire paths gate tools + philosophy prompt + nudge consistently; plugin mode untouched (every gate keeps !pluginMode); side requests / title-gen / passthrough keep the pipeline off exactly as before.
  • Kernel coherence: the arm char-sum (Σ m.text.length over projected core messages) matches what the kernel's compress gate sums across ranges against minCompressRange — so once armed, at least one viable range exists (fresh session, no blocks). The <= 0 escape hatch mirrors the kernel's own minCompressRange > 0 condition.
  • Pipeline selection: audited every Prepared return site. Pre-arm turns keep the compress-loop pipeline live via acpTurn (usage accounting, tag stripping, preflight/emergency visibility) — selection is byte-identical to baseline for every request shape; only wire injection differs. This matches your "21 regressions during development" note.
  • Conclusive receipt: trigger is sound — when whole-conversation chars < floor, no range combination can succeed because the kernel sums across ranges against one threshold; kernel reason and the 出现持续压缩失败,无法自动恢复 #847 reversal note stay intact, and the generic advice is preserved whenever a larger viable range exists.
  • "current" alias: case-insensitive, no regression for omitted/literal-session-id paths; collision risk only if another session were literally named current (negligible).
  • Tests: new suite covers withhold / sticky / <=0 escape / conclusive-vs-generic receipts plus end-to-end sticky arming through startServer (port-0, deterministic); the 16 harness restorations are minimal one-liners restoring the always-on surface those fixtures assert against.

Found & fixed — pushed 5396c0c to the PR branch
CI's e2e-fake-codex (real codex vs deterministic fake upstream, zero tokens) was red: peak=59602 > min*1.3 (min=45003). I reproduced it locally and A/B'd against master: the compression mechanics are identical on both sides (same per-turn preflight folds, ~4764 tokens saved each, load-turn payloads within ~300 bytes of each other). Root cause: #1112 correctly stops injecting the ACP surface into the filler-less warmup turn below the floor (master's warmup payload carried it: 58814 B; PR's doesn't: 45003 B), and the test's boundedness ratio had incidentally used that warmup turn as its floor. Product behavior is correct; the assertion was calibrated against an always-on surface. Fix (test-only): measure boundedness over the load turns only — unbounded growth still trips the bound within two turns. Local re-run after the fix: both fake-e2e tests pass.

Notes (non-blocking)

  • CONFIGURATION.md documents minCompressRangeChars but not the new deferred-surface behavior — worth a line: ACP tooling appears once visible content reaches the floor; <= 0 restores always-on.
  • The one-time prefix-cache re-anchor at the arm turn is inherent to any deferred-injection design; short sessions pay zero ACP overhead forever, which is the point.

Verdict: correct in both compression modes, clean diff, gates green on current master — mergeable once the re-run CI on 5396c0c is green. Merge stays human per AGENTS.md §7.4 (wire-shape change, no auto-merge claim).

中文摘要:修复了低于 minCompressRange 的新会话从第一轮起就被暴露完整 ACP 压缩面(每次 compress 必然失败、模型空转 acp_status/search_context)的问题——压缩面改为可见内容达到阈值后一次性粘性注入,另加结论性失败回执与 current 会话别名;review 中复现并定位了 e2e-fake CI 红灯为测试断言对无 surface 的 warmup 轮标定偏差(非产品回归),已直接在 PR 分支修掉(5396c0c),CI 复跑绿后可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI re-run on 5396c0c is all green: CI, e2e-fake-codex (previously red), CI Windows codex overlay (#686), PR Build Artifact. Nothing further outstanding from my side — ready for human merge whenever you are.

(补充:修复提交 5396c0c 后四个 CI 工作流全部通过,可以合并。)

@ranxianglei

Copy link
Copy Markdown
Owner Author

[人工否决] 这个方向不合并 —— 没有定位根因,用"隐藏表面"预防症状,同时引入新的复杂度和能力损失。

为什么说没定位根因

#1112 的产生机制是三要素叠加:

  1. 注入的内核哲学 prompt 无条件鼓励压缩(静态、不感知会话状态);
  2. 会话实际不可压缩(低于门槛)→ compress 必然失败;
  3. 失败后 re-request 循环让模型继续在 ACP 工具面里打转(acp_status / search_context,叠加 "current" 别名缺失)。

本 PR 只把要素 2 在 <5000 字符时用"表面隐藏"预防,要素 1、3 原样保留。直接后果(独立 review 实证):armAcpSurface 按全部可见文本计数(含最新受保护消息,src/server.ts:3176),而 kernel 只按请求范围内的 live 消息计数——会话在 5000+ 字符 arm 之后,最大可压缩范围仍可能 <5000,compress 照样必然失败,同样的工具循环照样发生(此时 stream.ts 的"别重试"句也不会出现,因为 totalChars ≥ floor)。修了等于没修。

同时引入的新问题

  • 能力损失:pre-arm 会话完全失去 acp_status / search_context / decompress,包括跨会话搜索(feat: 支持 search_context 显式查询历史 session #841)——与可压缩性无关的能力被砍;
  • plugin mode 静默变更:injectSystem 无 pluginMode 豁免(src/server.ts:3201-3202),master 上 plugin 会话从第 1 轮就有哲学 prompt,现在被门槛扣住——PR 描述声称 plugin mode 未动,不成立;
  • 配置语义静默扩大:minCompressRange 从"单范围资格门槛"变成"整个 ACP 表面开关",CONFIGURATION.md / README 中英文均未更新;
  • 复杂度:为一个"不该调用"的问题引入持久化 sticky flag + 四条 wire 路径 gate,本 PR 自身就带出 3 个 P1。

根因修法方向(讨论后再做)

在决策点给模型状态正确的信息,而不是藏掉工具:nudge 引擎每次请求已经算出精确的 live 可压缩量(日志 max compressible 0 < threshold 50000 就是它)。当该值低于最低可压缩门槛(按 kernel 同一口径:live 可压缩字符,而非全部可见文本)时,在注入表面追加一条按请求计算的状态注记(挂现有 withConversationIdNote 注记链):"当前会话无可压缩范围,不要调用 compress,直接继续任务"。无 sticky 状态、无工具隐藏、plugin/proxy 两模式都生效、改动面极小。

本 PR 中可独立保留的两块(请拆成独立小 PR)

  1. src/stream.ts 失败回执:全对话低于门槛时明确告知"别重试、继续任务"——失败时刻给可行动指引,方向正确;
  2. "current" 别名(src/decompress-shared.ts:179-189):search_context 的 conversation_id: "current" 别名到当前会话——修的是参数描述与执行器不一致的真实缺陷,正是 [Bug] Codex 新会话首轮无可压缩内容仍调用 compress,低于 5000 字符阈值后进入 ACP 工具循环 #1112 里 search_context 失败的直接燃料。

本 PR 关闭或按上述方向重做。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 接受否决。两个决定性技术点我都独立复核过,确认成立,不是只凭描述同意:

1. Arm ≠ 可压缩(口径不一致)— 成立。 PR head 的 armAcpSurface(src/server.ts:3176)对全部投影消息求和 m.text ?? "";kernel 的门槛判定只对请求范围内的 live 消息计数——跳过 block-boundary range、未解析的 spec,且近期消息保护还会排除最新消息。所以一个会话可以在可见文本 ≥5000 时 arm,但之后每次 compress 都必然失败(例如内容集中在受保护的近期消息里),触发完全相同的 acp_status/search_context 循环;此时 totalChars ≥ floor,新加的"别重试"回执也不会出现。我之前的 review 抓到了 block-boundary 这个 case 但把它当边缘情形放过了——保护性排除让它在日常会话里就可达,这是我的漏判。

2. Plugin mode 静默变更 — 成立。 master 的 injectSystem 只要 injectTool 开启就无条件推入 buildCompressSystemPrompt,没有 pluginMode 豁免;只有工具数组被 !pluginMode gate。也就是说 master 上 plugin 会话从第 1 轮就有哲学 prompt,本 PR 把它扣在 acpArmed 后面。PR 描述里"plugin mode 未动"对 system prompt 部分不成立。

你的三要素框架是对的:本 PR 只在要素 2 上用"藏表面"预防,同时砍掉了与可压缩性无关的能力(跨会话搜索 #841、decompress、acp_status),并静默把 minCompressRange 从单范围资格门槛改成整个 ACP 表面开关。

已执行 / 进行中:

  1. ✅ PR fix: withhold ACP compression surface below minCompressRange (#1112) #1121 已关闭(未合并、未发布)。
  2. 两块可保留内容拆成独立小 PR,各带自己的 issue:
  3. 根因方向(按请求计算的状态注记,挂现有注记链、无 sticky 状态、不藏工具、两模式生效)待讨论后再做。两个设计点想听你拍板:(a) 触发范围——只在 live 可压缩 < floor 时注入,还是窗口已满/无可压缩时也注入?我建议后者,两者都是"此刻不要调 compress"状态;(b) plugin mode 下 host 自己也渲染 ACP 指引——我建议 proxy 侧注记只挂在 proxy 拥有的 system block 上,作为 proxy 面的单一事实来源,不与 host 协调。你确认后我实现。

拆分 PR 就绪后我会在本线程跟进链接。

中文摘要:接受否决——独立复核确认两处硬伤(arm 按全部可见文本计数而 kernel 只数请求范围内 live 消息,arm 后仍可能必然失败;master 上 plugin 会话第一轮就有哲学 prompt,PR 静默改变了该行为);PR 已关闭,stream.ts 失败回执与 "current" 别名拆为两个独立小 PR,根因方向待讨论后实现。

antclt pushed a commit to antclt/billion-context that referenced this pull request Sep 22, 2026
…inCompressRange

When the WHOLE visible conversation holds fewer chars than compress.minCompressRange, no range combination can succeed (the kernel sums range chars against the single threshold), yet the standard failure receipt gave only generic 'combine more messages' advice — steering models straight back into compress retries and acp_status/search_context inspection loops (root-cause factor 3 of ranxianglei#1112).

Append one conclusive sentence to the applyRanges failure receipt when minCompressRange > 0 and total visible chars < minCompressRange: the floor is unreachable for any range, so do not retry compress or inspect ACP state about it. Kernel reason string and the ranxianglei#847 reversal note stay intact; when a viable larger range exists the generic advice is unchanged. No config schema change, no wire-shape change beyond failure-time tool-result text, plugin mode unaffected (receipt text only).

Piece 1 of the owner-approved split of PR ranxianglei#1121 (surface-gating half stays out of scope); re-applied standalone on current master per the split directive.

Closes ranxianglei#1124
@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing per owner conclusion on #1112: the proxy-side artifacts from the incident log are already fixed on master independently — the literal "current" session resolution landed as #1125 (src/decompress-shared.ts, duplicating this PR's alias hunk), and the #156 loop guard now breaks only on re-submitted identical failing compress/decompress args (src/loop/core.ts failedSignatures), so a first failure no longer terminates the round. The remaining pieces here (feasibility gate + conclusive sub-floor receipt) were premised on injection-as-trigger, which the production record (all bili products inject unconditionally, never reproduced outside this single codex×gpt-6-astra incident) does not support. Branch 2026-09-22_acp-surface-feasibility-gate stays pushed; reopen or ask for a slimmed receipt-only variant if wanted.

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.

[Bug] Codex 新会话首轮无可压缩内容仍调用 compress,低于 5000 字符阈值后进入 ACP 工具循环

1 participant