Repository navigation
[PR] fix(thinking): detect OpenRouter Zod signature-missing 400 so #5998 strip fires - #6991
ranxianglei wants to merge 2 commits into
Conversation
…trip fires OpenRouter's /api/v1/messages validator rejects a signature-less thinking block with a Zod complaint (path ends in "signature", "expected string, received undefined") that carries NEITHER "thinking" NOR "required"/"missing" — so detectThinkingSignatureRejection missed it and the #5998 strip-and-resend probe never fired, forwarding the 400 verbatim every turn (#6988). Extend the detector with a second, narrow gate: path tail "signature" + "expected string". Reuse the proven #5998 mechanism (first 400 → probe strips the unsigned block → retry accepted → posture learned → later turns drop proactively; the client never sees the 400). Regression tests: 3 detector unit cases (positive + 2 negatives) and an OpenRouter e2e personality mirroring the strict one.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.10532-pr.6991.d85e3b0This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr6991.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…R_ZOD_BODY alias Review pass on the #6988 detector fix: the tamper/openrouter/default cases landed indented one level deeper than their switch siblings, and OPENROUTER_ZOD_BODY was a pure identity alias of OPENROUTER_ZOD (same value, extra indirection). Cosmetic only — no behavior change; the 20-test file re-runs green after the fix.
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 检索 open+closed 的 issue 与 PR:无其他条目处理「OpenRouter Zod signature-missing 400」;源 issue 为 #6988,本 PR 是唯一关闭它的 PR。相关但不同:#5497(DeepSeek /anthropic "must be passed back"——不同措辞、不同病理,已关闭)、#4679(round-2 unsigned thinking stream——不同机制)、#147(DeepSeek 保留 signature——不同)。镜像 open [PR] 清单中无针对本 thread 的并列 PR。 审核结论① 原 issue(方向)——正确。
② 回归审查——无回归。 触碰路径的既有行为逐项过:
③ 代码——最小且正确。 文档注释已更新为描述两种措辞;正则 ④ 测试有效性——真测试,有牙。
⑤ diff 整洁度——干净。 2 文件、+91/−15,每行都与本 PR 目的相关;无跑题文件、无空行/重排洪水。 ⑤b 代码整洁——发现 2 处小问题,已直接在 PR 分支修掉(commit 标签——PR 已有 CI——运行中:旧 head 的 test 车道在最后一次镜像缓存读取时(01:25Z)为 in_progress/queued;我推的 八问
判定:可合并(等新 head CI 转绿)。 |
问题
OpenRouter + Claude Code 场景下,bili 向 OpenRouter 发送的 thinking 内容块缺少
signature字段。OpenRouter 的/api/v1/messagesZod 校验器要求每个 thinking 块的signature必须是字符串,否则整个请求返回 HTTP 400。只要对话历史里包含这样的块,Claude Code 会话每一轮都会失败。根因
src/server/thinking-posture.ts的detectThinkingSignatureRejection只认 Anthropic 原版措辞(必须含thinking+required/missing)。OpenRouter 的 Zod 措辞(expected string, received undefined+ path 以signature结尾)既无thinking也无required/missing,所以 #5998 的 strip-and-resend 探针对 OpenRouter 永不触发,400 每轮原样转发。修法
扩展
detectThinkingSignatureRejection,新增一个窄门: path 尾signature+expected string。复用已上线、已验证的 #5998 机制(首 400 → 探针剥掉无签名块 → 重试成功 → 记住 strict posture → 后续轮在出站前主动剥,客户端不再见 400)。测试
行为变更
无。仅放宽一个 400 措辞检测器,使其能识别 OpenRouter 的 Zod 措辞;复用既有 #5998 机制,不改变出站 wire 形状、不主动补空签名。
Closes #6988