Skip to content

[Bug]: 压缩质量检测失败时返回的错误信息过长,导致额外的上下文消耗 #396

Closed

Description

@WantexZard

Bug Description

Model:GPT5.6 sol

当 ACP 的 compression quality gate 检测失败时,当前返回给模型的错误信息非常长。

例如图中的情况:

  • Range: m00010–m00265
  • Original: ~426473 tokens
  • Summary: 3547 chars
  • Ratio: 480.9:1
  • Retention: 0.21%
  • Gate layer: L1-length

压缩本身被 quality gate 拒绝是合理的,因为这可以避免低质量的压缩结果破坏历史上下文。

但问题在于,Gate Failure 返回的信息本身非常庞大。

除了必要的失败原因和重试提示之外,还会附带一整套非常长的 HOW TO COMPRESS 指南,包括:

  • KEEP VERBATIM 规则
  • DROP 规则
  • KEEP MARKERS 规则
  • PRIORITY 规则
  • 大量关于如何重新生成 summary 的详细说明
  • acknowledgeRisk: true 的重试说明

这会产生一个比较明显的问题:

压缩的目的本来是减少上下文占用,但当压缩失败时,ACP 又向上下文中注入了一大段新的提示内容。

尤其是在已经达到数十万甚至数百万 tokens 的长会话中,这种失败信息会进一步占用宝贵的上下文空间。

另外,由于这段内容是作为模型上下文的一部分返回的,而不是仅仅显示给用户,因此它不仅影响 UI 可读性,也会直接增加模型的 context consumption。

报错信息与图片附上

t2.md

Image

Expected Behavior

Compression quality gate failure 本身应该继续保持。

但失败时返回给模型的信息应该是简洁、针对性的。

理想情况下:

压缩失败
→ 返回失败原因
→ 返回关键质量指标
→ 给出简短的 retry 指引
→ 不重复注入完整的 compression instruction

只有在确实需要时,才提供完整的压缩规则。

Debug Context Logs

如上文档;对话记录已丢失

Tool Call Details

No response

DCP Version

1.16.0

Opencode Version

1.18.29

Model

Other (specify in description)

Additional Context

No response

Activity

  1. ranxianglei commented on Sep 15, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    Triage 结论(Bug 类,三步审核通过)

    1. 复现/查证:确认存在。pre-commit quality gate 拒绝压缩时,buildQualityRejectionError(lib/compress/quality-gate/rejection.ts)把完整的 HOW_TO_COMPRESS_RULES(4,936 字符 ≈ ~1,234 tokens)外加一段多行 CRITICAL 警告嵌入返回给模型的错误信息。而且同一份规则已经存在于 ACP 系统提示中(lib/prompts/system.ts:58,每次请求都发送)——拒绝时注入的这部分是 100% 冗余内容,你截图里的 KEEP VERBATIM / DROP / PRIORITY / KEEP MARKERS 全段都是重复注入。
    2. 层次判断:你描述的就是根因本身,而非表面现象——根因不是"报错文案太长",而是"系统提示中已有的内容被重复塞进 tool error payload"。修复方向是去掉重复注入,而不是单纯裁剪措辞。
    3. 方案评估:你的 Expected Behavior(失败原因 + 关键指标 + 简短重试指引,不重复注入完整规则)打到了核心,实现完全按此方向进行。

    分析中发现并一并修复的两个附加问题:

    效果:单次拒绝的注入量从 ~5.4K 字符(~1.4K tokens)降到 ~600 字符(~150 tokens),减少约 85%。gate 本身的拦截行为不变;E2E fake-LLM 依赖的标记字符串(COMPRESSION REJECTED / QUALITY GATE FAILURE)保留在头部。全量测试 1,133 pass / 0 fail,typecheck/build 通过。

    重复判定:与 #339 相关但不重复——#339 讨论的是参数语义与交互设计(dangerous 残留、acknowledgeRisk 交互、advisory 模式),本 issue 是拒绝 payload 的上下文消耗问题,两者独立处理;advisory 模式等设计议题仍留在 #339 由 owner 拍板。

    PR: #397 (双 agent 评审进行中,完成后更新)

  2. ranxianglei commented on Sep 15, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    进展更新:评审与 CI 全部完成,PR 可以合并(合并操作按规范由人工执行)

    • 双 agent 独立评审(AGENTS.md §5.3/§5.6):代码评审 APPROVE、测试评审 APPROVE。测试评审做了变异验证——把 master 的旧 rejection.ts 换回去跑新测试,3 个新/改测试如预期失败(缺 reason / 规则被重新内嵌 / 5811 字符超预算),恢复后 15/15 全过,证明新测试确实能抓住本 bug。两条 NIT 已直接修复并推送(补 Retry: 断言;acknowledgeRisk 生效窗口措辞精确化为"下一次 compress 调用"——qualityGateRetryPending 在每次 compress 调用开始时清除)。
    • CI 6/6 绿:pr-validation、build、build-artifact、test (Node 22)、test (Node 24)、e2e。其中 e2e 通过 fake-LLM 服务端到端验证了拒绝→重试链路不受影响(检测用的标记字符串保留在消息头部)。
    • 最终拒绝消息样例(620 字符,修复前 ~5800):
    ⚠️ COMPRESSION REJECTED — QUALITY GATE FAILURE
    
    Range: m00001–m00005
    Reason: Summary too short
    Original: ~1000 tokens
    Summary: 18 chars
    Ratio: 222.2:1
    Retention: 0.45%
    Gate layer: L1-length
    rougeF1: ?
    top20Recall: ?
    
    Retry: rewrite a more complete summary that preserves critical details
    (file paths, decisions, exact values, errors) and call compress again on
    the same range — the gate re-evaluates automatically. Full compression
    rules are already in your system prompt. If you are confident the summary
    is correct despite the metrics, add "acknowledgeRisk": true to bypass the
    quality gate on your next compress call.
    

    PR: #397 — 请 owner 确认后自行合并(Agent 无合并权限)。

  3. added a commit that references this issue on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions