Skip to content

[PR] fix: recover x.ai Responses WS continuations rejected without a type - #5883

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
jmspwr:2026-11-07_xai-responses-ws-error-envelope
Nov 8, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
jmspwr:2026-11-07_xai-responses-ws-error-envelope

Conversation

@jmspwr

@jmspwr jmspwr commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #5881

原因

x.ai 拒绝过期的 previous_response_id 时,回的是没有顶层 type 的信封:

{"error":{"message":"gRPC error: Response with id=<uuid> not found","type":"api_error"}}

OpenAI 走的是 {type:"error", error:{code:"previous_response_not_found"}}。现有重试只认后一种,所以 x.ai 这一帧在类型检查处被当成协议错误,socket 被关掉,客户端记成 unclassified transport failure,并武装 emergency shrink。随后客户端改发完整请求,这一次是成功的。

修复

把这个信封当成已有的 continuation-rejected,清掉失效 checkpoint 后重发完整输入。不是“缺 response id”的无类型错误则按 HTTP 400 原样返回,不把真实供应商错误藏掉。其它无类型帧仍抛原来的错误。

测试

  • node --import tsx --test tests/xai-responses-ws-error-envelope.test.ts 2 pass
  • node --import tsx --test tests/responses-websocket.test.ts 41 pass
  • tsc --noEmit 通过

未改版本号。运行中的 0.1.212 不会因此改变。

x.ai answers a stale previous_response_id with an HTTP-style error envelope
and no top-level type. The OpenAI parser closed the socket, which the client
treated as an unclassified transport failure and answered by arming emergency
shrink. Treat that envelope as the existing continuation-rejected resend.
@ranxianglei ranxianglei changed the title fix: recover x.ai Responses WS continuations rejected without a type [PR] fix: recover x.ai Responses WS continuations rejected without a type Nov 7, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 GitHub issue/PR 全量检索(x.ai responses websocket / previous_response_not_found):与本 PR 同主题的只有 #5881(本 PR 自己修的 issue)和 #5883(本 PR)。Responses WS 车道既有工作(#4808 / #4817 / #2126 / #1926 / #2004 等)机制各不相同——codex stream_options 准入、413 长会话、delta 全量重建、idle socket 观测——没有一条处理「x.ai 无顶层 type 的错误信封」。独立修复,无并行在途 PR。

初步方向判断(待本地测试背书): 根因定位准确——src/responses-ws.ts 的 message handler 对无字符串 type 的帧直接 throw "Invalid Responses WebSocket event" → fail() → close("invalid-event"),x.ai 拒绝过期 checkpoint 的那一帧因此被当协议错误关 socket,客户端记成 unclassified transport failure 并武装 emergency shrink。修法把该信封并入既有的 continuation-rejected 路径(resetHistory + resend-full);非「缺 response id」的无类型错误按 HTTP 400 原样返回而非关 socket——方向正确,是疏不是堵(修的是产生误判的类型检查这一决策点,不是在下游再过滤一次 payload)。

状态: 已把 PR head(0c213c09a0)拉到本地跑定向测试取证;镜像与 GitHub 目前都还没有这个 head 的 CI check-run(后台套件未回)。稍后补完整的结构化八问结论 + 本地测试结果。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

判定:可合(recommend mergeable)。 改动小且隔离,有牙的回归测试钉死,本地定向取证全绿。唯一待办:这个 head 的 CI 还没回 + 落后 master 264 个提交(master 未触碰本文件,rebase 无实质风险)。合并动作归 owner(human-only),我不代合。

结构化八问

  1. 是什么问题:x.ai 拒绝过期 previous_response_id 时回的信封没有顶层 type(只有 error:{message, type:"api_error"}),而 Responses WS 车道只认 type:"error" 的帧——这一帧被当协议错误直接关 socket,客户端记成 unclassified transport failure 并武装 emergency shrink。

  2. 什么原因导致:src/responses-ws.ts message handler 对「非字符串 type」的帧一律 throw "Invalid Responses WebSocket event" → fail() → close("invalid-event")。根因是类型检查这个决策点只覆盖了 OpenAI 的 typed 形态,把 x.ai 的 HTTP-style 信封误判为协议违规——是判断错,不是 payload 本身有问题。

  3. 影响范围与严重程度:仅 x.ai(Responses WebSocket,grok 系)的 continuation(delta)回合触发;OpenAI typed previous_response_not_found 路径不受影响。严重度=特定条件下体验受损:turn 靠客户端自己全量重发仍能成功,但每次 miss 都武装 emergency shrink(白收缩上下文)+ 一条误导性的 transport-failure 日志。属 p2(能绕过、不毁会话、非缓存泄露)。

  4. 怎么修复的:在类型检查之前加一层 untypedErrorEnvelope 识别「无 type + 有 error 对象」的信封;命中且判为 continuation-rejected(x.ai 缺失文案正则 / OpenAI 既有 code)时并入既有 resend-full 路径(resetHistory + 重发完整输入);非缺失类的无类型错误按 HTTP 400 原样返回真实供应商错误,不再关 socket。修的是决策点(疏),不是在下游再过滤一次 payload(堵)。把重复判定抽成共享谓词 continuationRejected,typed/untyped 两路共用。

  5. 是否有回归问题(审过的既有行为逐项):

    • typed error 路径:原两个条件逐字保留进 continuationRejected;新增第三子句(api_error+缺失文案)对 typed 帧也生效——这是同语义扩展(typed 版「response not found」本就该 resend-full),且 retryFull 保证最多重发一次、不会循环。有意变更,已披露。
    • connection-limit 重连(Support Codex Responses WS clients with HTTP/SSE upstreams, preserving local delta checkpoints #3342 分支):要求 frame.type==="error",永不落 bare 路径,不受影响。✓
    • mid-stream 无类型帧:!settled 门保证只在首事件前处理;流式中途仍走原 throw/close。✓
    • prewarm probe 路径:空 input 不会收到「response not found」;即便收到,行为从 generic 502 变为透传 400,更准确,低危。
    • 现有 WS 套件 41/41 绿;master 自 PR base 起未改本文件(空 diff),无跨分支交互。
    • 高危模式逐项:fal-fast 变吞错 / 阈值·时序·输出格式漂移 —— 均未触及,400 返回的是原始信封字节,不吞不改。
  6. 是否破坏缓存:不涉及。改的是错误恢复路径,不动 checkpoint 覆盖/签名/去重键;resend-full 后 resetHistory 清的是已失效 checkpoint,与缓存失效策略正交。

  7. 是否改了设计方向:不涉及架构转向。仍走既有 continuation-rejected→resend-full 机制,只是让 x.ai 的信封进入同一决策分支。

  8. 是否引入新配置:不涉及。无新 env/config/knob,纯内部错误处理。

行为变更披露(old→new):

  • x.ai delta miss:关 socket + 武装 emergency shrink → bili 内部 resend-full、turn 干净完成、shrink 不武装。
  • 任意无类型错误信封:关 socket(unclassified transport failure)→ HTTP 400 透传供应商错误。

代码/测试质量(外部贡献者从严):命名达意、无死码、DRY 抽取合理、注释讲 why 且与事实相符、风格贴合本文件;两测试 hermetic(listen(0) 随机端口)、正负成对、断言到 wire 帧序列与日志行;实测对 pre-fix 源码 0/2 失败、PR head 2/2 通过,是真回归钉不是恒真断言。质量达标,无需对齐重构。

diff 整洁度:仅 2 文件(src/responses-ws.ts +36/-1,新增测试 124 行),每行都服务本目的,无无关 churn / 锁文件 / 生成物。干净。

状态与后续:镜像与 GitHub 目前都还没有这个 head 的 CI check-run(后台套件未回);PR 落后 master 264 提交但本文件未被那些提交触碰,建议合并前 rebase 一下保持套件新鲜(非正确性阻塞)。CI 绿 + owner 点头即可合。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

收工摘要(外部 PR #5883,x.ai Responses WS 无 type 错误信封恢复):

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)

本 PR 的 CI 红全部是继承性失败(master 侧 #5860 波次根因),与本 PR 的 diff 无关;但本 PR 的 head 在外部 fork jmspwr/billion-context,本机账号对该 fork 只有 pull 权限,无法把修复推进 PR 分支——需要你选一条路:


七问摘要(本轮)

  1. 是什么问题:本 PR 的 10 个 test 分片 CI 红,但失败无一由本 PR 改动引起。
  2. 什么原因导致的:根因 = master 的 [PR] fix(nudge): no billing sample this round → hold pressure-band injection one round (phantom-pressure guard) #5860(kernel 0.0.184 phantom-pressure guard,commit a7cbfd12fc)新增配置字段并改变 estimate-grade nudge 行为,但未重生成黄金快照、未对齐既有 nudge 测试断言;master push 不触发 CI,born-red 隐形到 schedule cron 才暴露(完整归因与隔离证据见 CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 floor 1103/1106)。本 PR diff 仅 src/responses-ws.ts(+37/-1)+ 新增 tests/xai-responses-ws-error-envelope.test.ts,与全部失败路径不相交。
  3. 影响范围与严重程度:仅信号级(检查矩阵失去信号),无用户面功能影响;后果是本 PR 无法转绿合并。我分片(ubuntu 22 shard 1)6 条失败 = storage-render goldens×4(F1,metadata digest 漂移)+ wire-contract kernel.json×1(F2,additive 字段)+ Egress Judge false positive on Snapshot Render Lane I2: prefix comparison baseline needs to be aware of the render view | 出站判官对快照渲染车道误报 I2:前缀比对基准需要感知渲染视图 #4241 teeth-intact×1(F3,estimate-grade nudge 断言过期)。
  4. 怎么修复的:F1+F2 是机械修复且已完成——哨兵已在 ci-fixes 重生成两族 golden(e7b0cee859/6436b23b3c,CI preload 环境本地验证绿);我把 ci-fixes 干净合入 PR head 得到镜像分支 f16517c053(merge 零冲突,已验证 PR 文件未被改动、goldens 与 ci-fixes tip 逐字节一致)。F3(含本分片的 Egress Judge false positive on Snapshot Render Lane I2: prefix comparison baseline needs to be aware of the render view | 出站判官对快照渲染车道误报 I2:前缀比对基准需要感知渲染视图 #4241 一条)是产品契约裁定项,等你在 The storage-render golden snapshot on master went stale after kernel 0.0.184 (#5860): the next scheduled CI run will def | master 的 storage-render 黄金快照在 kernel 0.0.184(#5860)之后过期:定时 CI 下次必红 #5867 拍板 A/B/C,不属于我可自决范围,未动。
  5. 是否有回归问题:merge 零代码语义变化(纯 master 同步 + golden 对齐);golden 的 diff 本身只有 additive 的 requireUsageSampleForPressure 字段,账本只增不缩。本 PR 自身的 responses-ws 改动原样保留。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向 / 引入新配置:均未涉及(配置面属 [PR] fix(nudge): no billing sample this round → hold pressure-band injection one round (phantom-pressure guard) #5860 自身,已随 master 落定,不在本 PR 范围)。

结论:本车道可做部分已完成(归因钉死 + 镜像分支备好),剩余红为预期状态(F3 等 #5867 裁定 + fork 权限路径待你选择),等你拍板后继续。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

x.ai Responses WS rejects previous_response_id with an untyped error envelope, closing the socket and arming emergency shrink

2 participants