Skip to content

Codex WS lane: proxy-failure error frames carry error as a string, so codex ignores them and waits for its idle timeout; 1009 diagnostic reports 0.0 MiB #4601

Description

@z0d0dOr

(ai: anthropic/claude-opus-5-5)

Category D: timeouts/retries (scope/wiring). Related: #3701, #4594.

When a codex WebSocket exchange fails inside the pipeline, codex never sees the failure. In the field (bili 0.1.206, codex-tui 0.164.0) an un-intercepted compaction was forwarded at 17,490,755 bytes and the upstream closed with 1009. bili logged Error: WS upstream rejected the 0.0 MiB request with close 1009 … at 13:58:37Z. Codex logged remote compaction v2 stream failed … stream disconnected before completion: idle timeout waiting for websocket at 14:03:37Z, exactly 5:00 later, retried twice, and failed the turn after ~15 minutes.

Mechanism:

  1. dispatch (src/server.ts:669, failure body at :700) answers with buildProxyFailureResponse, whose body is {"error": "<string>", "detail": "…"} (src/upstream-fail.ts:212).
  2. ResponsesWsResponse.end() (src/responses-ws.ts:573) turns a JSON body into { ...details, type: "error", status }, so error stays a string.
  3. Codex parses WS error events as { type, status, error: { code?, message?, headers? } } (parse_wrapped_websocket_error_event in codex-rs/codex-api/src/endpoint/responses_websocket.rs). A string error fails deserialization, so the frame is not treated as an error and the stream waits for its idle timeout. bili's own errorFrame() (src/responses-ws.ts:500) uses error: { type, code, message } and is understood.

A second defect on the same path: src/server/relay.ts:877 computes sentBytes only for string bodies. For a non-string (verbatim passthrough) body the 1009 diagnostic therefore reports 0.0 MiB together with the default "(no sheddable images outside the protected recent messages)" reason from wsOversizeDiagnosis (:186), although no shedding was attempted.

Expected: failure frames on the WS lanes use the Responses error shape (error: { code, message }, status preserved) so the client fails fast and surfaces or retries the error, and the 1009 diagnostic reports the actual frame size.

Activity

  1. ranxianglei commented on Oct 24, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b)

    查重: 不重复。 与相关条目逐一比对:

    标签: bug / codex / opencodev2 / scope/wiring / p1(已打好)。p1 理由:不是只有 1009——WS 车道上任何管道级失败(上游超时/重置/熔断 fail-fast…)产生的错误帧 codex 都读不懂,每次失败白烧 5 分钟 idle × 重试次数(现场 ~15 分钟才 fail turn),且用户全程看不到失败原因;错误快速上抛是代理的核心承诺,此车道上该承诺整体失灵。opencodev2 同打因为 Responses-WS 车道是共享的,帧形状修复影响该车道所有客户端。

    Bug 审核三步:

    1. 复现查证(当前 master 代码级确认,两处缺陷全部成立):
      • ① buildProxyFailureResponse(src/upstream-fail.ts:212)body 恒为 {error:"<string>", detail};ResponsesWsResponse.end()(src/responses-ws.ts:573)把 JSON body 展开成 {...details, type:"error", status},error 保持字符串。我拉了 codex 源码核对(codex-rs/codex-api/src/endpoint/responses_websocket.rs):WrappedWebsocketErrorEvent.error: Option<WrappedWebsocketError> 是 struct,字符串反序列化整个事件失败 → .ok()? → 非错误帧 → 落回普通事件解析也失败 → continue → 等 idle timeout。与现场日志逐字吻合。另外确认了帧里 status 缺失或 <400 同样会被忽略——现有 end() 已强制 ≥400(默认 502),这点不用动。
      • ② relay.ts:877 sentBytes 只对 string 体计长,Buffer 体(verbatim passthrough)= 0;guard 分支(:880)随即用 wsOversizeDiagnosis(0, undefined, budget) 抛出「0.0 MiB + no sheddable images」——但 shedding 根本没试过(shedWireImages 只吃 JSON 字符串体)。与现场 Error: WS upstream rejected the 0.0 MiB request with close 1009 … 吻合。
    2. 层次判断:报告打到根因层——① 的病根在帧形状转换点(WS 车道的 egress sink 没有把 HTTP 语义的失败 body 转成该车道的错误契约),不在 buildProxyFailureResponse(HTTP 车道的 string-error 契约是有意设计,改了会伤 HTTP 客户端);② 的病根在 sentBytes 的类型盲区 + 诊断文案对「未尝试 shedding」的误述。
    3. 方案评估:按 issue Expected 的方向成立——在 end() 这一处把 error 归一化为对象形 {code, message}(已是对象的原样保留;字符串则包装,message 合并 error+detail 保信息量;无 error 字段落回 incomplete_response 形状),status 沿用现状;sentBytes 对 Buffer 体取真实长度,guard 分支对非字符串体给出诚实原因(verbatim passthrough,shedding 不适用)。都是车道局部修改,HTTP 车道字节不变。

    正在实现 + 回归测试,PR 随后贴出。

  2. ranxianglei commented on Oct 24, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b)

    **修复完成,PR: https://github.com/ranxianglei/billion-context/pull/4624**(Closes #4601)

    八问:

    1. 是什么问题:codex WS 车道上管道失败时,错误帧对客户端「不可见」——帧里 error 是字符串,codex 的错误事件反序列化(要求 error 为对象)失败后直接丢弃该帧,只能干等 5 分钟 idle timeout × 重试次数(现场 ~15 分钟才 fail turn),期间用户看不到任何失败原因。同路径第二缺陷:非 JSON(verbatim passthrough)体被上游 1009 拒收时,诊断报 0.0 MiB 加一句假的「no sheddable images」——实际根本没尝试 shedding。

    2. 什么原因导致的:① HTTP 车道的失败体契约(string error,有意设计)被 ResponsesWsResponse.end() 原样展开成 WS 帧,缺一步车道形状转换——HTTP 语义的 body ≠ WS 车道的错误契约;② sentBytes 只对字符串体计长、Buffer 体硬编码 0,且诊断文案统一套「试过 shedding 但无可 shed」的模板,对未尝试的场景失实。

    3. 影响范围与严重程度:Responses-WS 车道的所有客户端(codex 主报、opencode-v2 同车道)。触发面 = 该车道上任何管道级失败(上游超时/重置/熔断 fail-fast/1009 超限…),不止 1009。p1:每次失败白烧 ~15 分钟死等且原因不可见,错误快速上抛这一核心承诺在该车道整体失灵。

    4. 怎么修复的:在 WS egress 的唯一转换点 end() 归一化——对象 error 原样保留;字符串 error 包成 { code: "proxy_failure", message: "<error>: <detail>" }(信息量不丢);无 error 字段落回 incomplete_response 形状;status 语义不变(statusCode ≥400,默认 502)。诊断侧:Buffer 体按真实字节计长;no-shed 分支用新加的 why 覆盖参数如实说明「body 不是 JSON wire body(verbatim passthrough)— shedding 不适用」。HTTP 车道一行未动。

    5. 是否有回归问题:审计过既有行为——HTTP 车道 string-error 契约不变(新增 gate 测试钉住)、admission errorFrame 形状不变(钉住)、三个相邻套件 29/29 绿(codex-responses-ws / issue3701-ws-byte-budget / responses-ws-http-fallback)、tsc 干净。一处微型变更已披露:unparseable-buffer 回退帧的 status 从恒 502 改为尊重显式 4xx/5xx statusCode(实践中此前不可达:设置 4xx 却写非 JSON 体的路径不存在)。

    6. 是否破坏缓存:不涉及——未触碰缓存/重试/游标/去重逻辑。

    7. 是否改了设计方向:没有。补的是车道边界缺失的转换步骤;buildProxyFailureResponse 共享构建器与 HTTP 契约保持原样。

    8. 是否引入了新的配置:无。

    验证:新回归套件 3/3 绿(两个缺陷各一 + 负向门禁);负向对照已做——stash 掉修复重跑,两个缺陷测试如预期红、gate 测试如预期绿(测试有牙)。全量判定交 CI(分支 base = master tip 146b34f,无 rebase 漂移)。热文件提示:#4595 同触 src/responses-ws.ts 但改的是 probe gate 区域(onMessage ~:655),与本 PR(end() ~:569)不重叠,若先后落地注意 rebase 顺序即可。

  3. ranxianglei commented on Oct 24, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b)

    CI 状态更新(PR #4624,head ce00312):40 个 check run 里 23 绿、16 skip(e2e 门控车道,常态)、唯一失败 = unused-exports——已证实为继承性失败:master tip(146b34f27)同一门禁同样红,#4606 在途修复;本 PR diff 未新增/改动任何 export。按 #4599 协调规则已在那边留了一行继承性说明,未本地追查。等 #4606 合入后本分支 rebase 即全绿,之后可合并(合并动作归 owner)。

  4. ranxianglei commented on Nov 4, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b) PR #5662 首轮红:仅 unused-exports gate(我新增的 FastpathTailScanResult 接口 INTERNAL_ONLY,自己代码问题非继承红)。已去掉 export 关键字(gate/tsc/定向套件本地全绿),amend 后重推 sha=e17d19f3f,等 CI 复跑。

  5. added a commit that references this issue on Nov 9, 2026
    3fcf41e
  6. added a commit that references this issue on Nov 9, 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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions