Skip to content

fake-completion corrective retry derives from the raw client body, bypassing wire transforms the main attempt carried #1900

Closed

Description

@ranxianglei

来源: #1894 (PR #1899, Closes #1894) 分析 seam forensics hop re-note 时发现

Problem

resolveFakeCompletion() (src/server.ts, ~L6454) builds its corrective-hint retry from opts.body, and BOTH call sites pass forward()'s raw client body parameter:

  • proxy streaming lane (~L6088): body — the untransformed client request;
  • plugin lane (~L5982): body — the agent's own body.

The MAIN attempt of the same request went out as wireBody — post wireTransform (learned compat-role rewrite #552/#583, steering, chain-stamp). The hinted retry therefore re-sends PRE-rewrite bytes even though the provider rejected those exact bytes earlier in the same request.

Repro (code path)

  1. Responses/OpenAI session; provider rejects role developer once → bili learns the compat rewrite (billion-context: 400 Bad Request when codex sends role: "developer" messages — request a request-body compat transform hook #552 learn-on-failure); all subsequent main sends carry the rewritten role.
  2. Enable the opt-in backstop: BILI_FAKE_COMPLETION_RETRIES > 0 (default 0 = disabled).
  3. A turn streams a fake completion (tool-call XML without a tool block).
  4. resolveFakeCompletion retries with injectFakeCompletionHint(protocol, rawBody) — the raw body still contains developer → upstream returns the same 400 → "fake-completion retry rejected … presenting original" → the user is shown the FAKE completion instead of a corrected turn.

Impact

Functional, narrow: requires the opt-in env var AND mid-session learned compat roles AND a real fake completion on the same turn. No data corruption — the failed retry falls back to presenting the original stream unchanged. Distinct mechanism from #1894 (that one is forensic pairing only, diagnostic); this one changes what bytes reach the provider, so it is a separate failure domain.

Suggested fix

Pass the effective wire bytes (wireBody, already in scope at both call sites) instead of the raw body, so the hinted retry derives from the same base the provider just accepted — then verify injectFakeCompletionHint handles the transformed shape per protocol. Decide the plugin-lane semantics explicitly (the agent owning its own re-issue body may be intentional there — document or align). Wire-behavior change: review-gated, not auto-merge territory.

Activity

  1. ranxianglei commented on Oct 2, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Triage: issue confirmed — root cause verified in code; one additional facet of the same mechanism found. Working on fix + regression tests.

    Verification (master @ 6cab41b):

    Regression tests planned: proxy lane with configured compat.roles, the in-request learning facet (400 → hop → fake → hinted retry must carry the hopped role), plugin lane, plus a unit pin for hint-injection-on-transformed-shape. Follow-up with the PR link shortly.

  2. ranxianglei commented on Oct 2, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 已完成,PR 已开:#1904

    按结构化七问作答:

    1. 是什么问题:opt-in 的 fake-completion 纠正重试(BILI_FAKE_COMPLETION_RETRIES > 0)从原始 client body 派生重试字节,而同一请求的主发送走的是 wireTransform 之后的 wireBody。当 provider 已在会话早期拒绝过那些原始字节(learned compat roles,#552/#583)时,带 hint 的重试重发被拒字节 → 同样的 400 → 用户看到的是假完成而非纠正后的回合。审核确认属实(issue 描述与代码路径完全吻合)。

    2. 什么原因导致的:两个 call site(proxy lane + plugin lane)都把 forward() 的原始 body 参数传给了 resolveFakeCompletion,而不是主发送实际发出的 wireBody——重试基座与主发送基座不一致。triage 中发现同机制的第二面:即使改传 wireBody 也不够——#552 role hop(fixed.body)和 #1195 overflow refold(refolded)在请求内重发成功时都没有更新 wireBody,所以「角色是本次请求内学到的」那一回合,wireBody 仍是过期的预 hop 字节。两个缺陷同属「重试基座 ≠ 上游刚接受的字节」这一失败域,合并在本 issue/PR 内处理。

    3. 怎么修复的:① 两个 call site 改传 wireBody(opts 字段 body→wireBody 改名 + 文档块固化契约);② role-hop 与 refold 的 ok-branch 更新 wireBody,确立不变量「wireBody = 最近一次成功发出的字节串」;③ plugin lane 对齐 proxy lane(在 call site 注释中显式记录该决定):hint 重试是 proxy→upstream 的 HTTP 调用,其基座必须是上游刚接受的字节,与哪一侧拥有压缩无关;相邻的 makeContinuationRefetch({ body }) 用原始 agent body 是另一机制,保持不变。

    4. 是否有回归问题:无。逐条审过触碰路径的既有行为:#552 hop 阶梯、#1195 refold、#371/#473 fake-completion 检测+重试+streak 门控、plugin/proxy 双模式注入抑制——语义均未变,仅重试内容在 opt-in 路径上变为正确基座。新增 3 个 e2e 回归测试(configured compat roles / in-request learned 400→hop / plugin lane)+ 2 个单测 pin,全部验证过在未修复代码上失败、修复后通过;定向测试全绿(fake-completion 25/25、issue473 4/4、compat-roles+refold 19/19),typecheck 干净,全局套件交给 CI。行为变更披露:仅 opt-in 路径,旧=原始 client body+hint → 新=最后被接受的 wire 字节+hint——这就是修复本身;副作用是 reasoning-guard 等后续读 wireBody 的地方从此读到被接受字节而非 pre-hop 字节(严格更正确)。

    5. 是否破坏缓存:不涉及。未触碰 prefix cache / prompt-cache key / 增量游标 / 去重键;chain-stamp digest 过期时走既有的 graceful strip 路径(#1421 已有机制)。

    6. 是否改了设计方向:不涉及架构转向;只把「重试必须派生自主发送同一基座」这一契约显式化并补上两处漏更新的赋值。

    7. 是否引入了新的配置:无。复用现有 compat.roles,无新 env/config/默认值。

    注意:测试选 Responses wire 承载 e2e 场景,因为 OpenAI-chat adapter 在 prepare 阶段就把 developer→system 归一化了,只有 Responses 保留 client 原始 role,场景才可表征——这是测试实现细节,不是产品限制。wire 行为变更(opt-in 路径),review-gated,不合并不由我执行。判定:可合并,等 owner review。

  3. ranxianglei commented on Oct 2, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 开放检查项(#1904 review 发现)— 同机制相邻面:degenerate-terminal continuation refetch 仍从 raw body 派生

    来源: #1904 (PR) 分析 #1900 修复时发现

    Review #1904 时确认 fake-completion 重试路径已被完整覆盖(两个 call site + hop/refold 的 wireBody 跟踪,不变量经枚举成立),但同一失败域——「请求内 proxy→upstream 重发派生自非上游刚接受的基座」——还有一个 PR 有意保留的相邻面:

    待 owner 拍板:并入 #1904 合并前处理,或单独跟踪/处理。分析已备妥,两种走向都可直接执行。

  4. added a commit that references this issue on Oct 2, 2026
  5. added a commit that references this issue on Oct 19, 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 workingp1

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions