Repository navigation
[PR] fix: acp-loop re-request rewrites thread.continue to thread.create on the Anthropic production path (#2701 finding 2) | [PR] fix: acp-loop re-request 在 anthropic 线上把 thread.continue 改写为 thread.create(#2701 finding 2) - #2706
ranxianglei wants to merge 1 commit into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2923-pr.2706.5996df4This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2706.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到。识别为已完成工作的 [PR]( |
b48d0f4 to
71b06a7
Compare
[bot] 🏷 核对进展(代码已核完,CI 红因已定位并处理) 代码核对 —— 全部通过
CI 红 = stale base,与本 PR 无关
已采取行动:分支 rebase 到当前 master( |
[bot] 🏷 PR 核对完成,全部验证通过。判定:可合并(CI 全绿、mergeable,等人工合并)。 按八问逐项:
行为变更披露(旧→新):anthropic 线 + proxy mode + 原请求 过程说明:
收工判定:可合并 —— 代码方向、机制正确性、回归钉住、CI 均已核验,请人工合并 #2706 。 |
|
(ai: zhipuai-lb/glm-5.3) 孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。 |
关联 issue
#2701(Threads 下 bili 压缩回路在 continue 轮次全面失效)——本 PR 只修其中的 finding 2(立刻可做的 bugfix):continue 轮次上模型调用
compress→ bili 本地执行后 re-request 复用客户端的previous_message_id(round 1 已 continue 过它)→ 上游 400 "has already been continued" → 当前轮以错误结束、折叠丢失、下一轮重付 ~21 万 input token。findings 1/3/4(nudge 失明 / 折叠只能 create 送达 / 紧急兜底无从生效)与建议 2–4(C 方案主动 create 改写、A 方案取舍、文档建议)是设计决策,留在 #2701 线程等 owner 拍板,故本 PR 不 close #2701。
机制与修法
src/loop/adapter-anthropic.ts的buildRequest以{ ...body, system, messages }重建 re-request——messages是全量重构视图(coreToAnthropic 整个 kernel 状态,含折叠后视图),从来不是增量;但顶层thread字段原样透传。于是 re-request 带着已被 round 1 消费的previous_message_id发出 → 上游按「每个 response id 至多 continue 一次」规则拒绝。修法:re-request 重建时若原 body 带
thread.type === "continue",改写为{ type: "create" }。create 是唯一与全量视图语义一致的形态:新 Thread 以折叠后视图播种,宿主下一次 continue(引用本 re-request 的响应 id)即继承压缩后的 Thread——这正是 #2701 finding 3 用真实流量验证过的继承路径。不能像 responses 线 #1954 那样直接剥掉字段:anthropic 响应不带 thread 字段就不属于任何 Thread,宿主的后续 continue 会直接 thread_not_found。所有 re-request/retry 路径(proxy-tool re-request core.ts:1215、thinking-strip 重试 core.ts:1255、三处 nudge 重试 core.ts:804/850/908)都走同一个
adapter.buildRequest,一处修改全部覆盖。行为变更披露(旧 → 新)
thread.continue时,acp-loop 本地执行 proxy tool 后的 re-requestthread.continue→ 必然 400(id 已消费),轮次死亡、折叠丢失thread.create,全量折叠后视图播种新 Thread;宿主后续 continue 继承折叠态不受影响(各有断言钉住):
thread.create:不改动(F7d 断言);无新配置项、无阈值/时序/输出格式变化、stream 形态不变。
测试
tests/loop-adapters.test.tsF7c/F7d:adapter 契约单测(continue→create 改写;create/缺省不动)。tests/issue2701-threads-recreate.test.ts:全链路 e2e——脚本化上游强制复刻 Anthropic 的 once-only continue 规则(二次 continue 同一 id → 生产同款 400)。已验证:去掉修复该 e2e 失败(round-2 body 仍携带已消费的 continue、客户端流内出现 upstream error),恢复修复后通过(round-2 = create、折叠落地、客户端收到 round-2 文本)。tests/image-request-budget.test.ts引用已移除的compress.stripImages,fix: 让压缩图片历史先减量,再检查发送字节预算 #2613 与 建议:compress.stripImages默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 合并顺序错位所致,已在干净 master 复现确认与本 PR 无关)→ 已单独立项 [Bug] master typecheck 红:tests/image-request-budget.test.ts 引用已移除的 compress.stripImages(#2613 与 #2607 合并顺序错位) #2705。