Skip to content

fix(zhipu): 兼容转换 thinking.type=adaptive 修复 [1210] 语义拒绝#249

Merged
ThreeFish-AI merged 8 commits into
feature/1.x.xfrom
ThreeFish-AI/sacramento-v1
May 26, 2026
Merged

fix(zhipu): 兼容转换 thinking.type=adaptive 修复 [1210] 语义拒绝#249
ThreeFish-AI merged 8 commits into
feature/1.x.xfrom
ThreeFish-AI/sacramento-v1

Conversation

@ThreeFish-AI

Copy link
Copy Markdown
Owner

Summary

  • 基于 2026-05-26 日志证据(8 次连续拒绝均含 thinking.type=adaptive),在 ZhipuVendor._prepare_request 中实现兼容转换(而非移除),将 adaptive 转换为 GLM 原生确认支持的 enabled + budget_tokens 格式
  • 新增 _build_zhipu_request_snapshot 诊断快照函数,使成功/失败请求日志使用统一格式,可 diff 对比定位差异维度
  • 扩展语义拒绝日志的错误体截断(200→500 字符),保留 zhipu [1210] 完整字段级诊断信息
  • 更新 issue.md 根因分析记录(从"仍在收集证据"更新为"已定位")

根因定位

PR #247 (Step 1 v2) 部署后的日志证据显示,所有 [1210] 拒绝请求均携带 thinking={"type": "adaptive"}。此前 curl 测试仅验证了 {"type": "enabled"},未覆盖 Anthropic Claude 4.x 新增的 adaptive 类型。GLM 不支持此类型值,触发参数校验错误。

修复策略

采用兼容转换而非参数剥离,保留完整 CC (Claude Code) 功能特性:

  • thinking.type="adaptive"{"type": "enabled", "budget_tokens": 16000}(thinking 能力保留)
  • metadata 暂不处理(待进一步诊断确认兼容性)
  • cache_controlreasoning_effort 已确认被 GLM 静默忽略,不触动

变更文件

文件 变更
src/coding/proxy/vendors/zhipu.py 新增 _prepare_request 覆写 + _build_zhipu_request_snapshot
src/coding/proxy/routing/executor.py 语义拒绝日志错误体截断 200→500
tests/test_zhipu.py 新增 4 个转换测试
tests/test_vendors.py 新增 1 个 adaptive 转换测试
docs/agents/issue.md 更新根因定位和 Step 2 修复记录
src/coding/proxy/convert/vendor_channels.py 更新 _ZHIPU_UNSUPPORTED_PARAMS 注释

Test plan

  • uv run pytest tests/test_zhipu.py tests/test_vendors.py tests/test_vendor_channels.py -v — 172 passed
  • 部署后观察日志 ZhipuVendor first-tier compat: converted_thinking_adaptive→enabled 确认转换激活
  • 验证 Tier zhipu semantic rejection 不再出现([1210] 消失)
  • 验证 thinking_blocks_in_history 仍然增长(thinking 功能未被阉割)
  • 若 [1210] 仍在特定场景复现,对比 _build_zhipu_request_snapshot 输出定位下一个差异维度

🤖 Generated with Claude Code

ThreeFish-AI and others added 8 commits May 23, 2026 23:20
在 execute_message 和 execute_stream 的 semantic rejection 日志中
附加请求体参数快照(thinking/extended_thinking/reasoning_effort 顶层参数、
会话历史中 thinking blocks 数量、cache_control 存在情况、模型名、消息数),
用于定位 zhipu glm-4.7 [1210] 参数校验拒绝的具体祸根参数。

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
…t_types 等维度

PR #244 部署后的诊断日志反转了原推断:失败请求均不含 thinking/cache_control,
说明祸根在更细粒度的参数。扩展 _build_semantic_rejection_diagnostic 函数:

新增维度(仅存在时输出):
- system 形态(string/blocks + cache_control 计数)
- tools 数量 + tool_choice 形态
- 采样参数(max_tokens/temperature/top_p/top_k/stop_sequences)
- stream / metadata_keys
- messages.content 类型分布(含 string content)
- 请求体字节数估算(json.dumps)

新增 14 个单元测试(TestBuildSemanticRejectionDiagnostic)覆盖各字段组合
与真实失败请求形态。所有测试通过(1478 passed)。
- pyproject.toml: 版本号取上游 0.4.1a8
- tests/test_router_executor.py: 保留两侧新增的 import 与测试类(TestBuildSemanticRejectionDiagnostic + TestSanitizeUserText + TestExtractSessionTitle)
- uv.lock: 同步版本号并重新生成

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
…] 语义拒绝

基于 2026-05-26 16:30–16:31 日志证据(8 次连续拒绝均含 thinking.type=adaptive),
在 ZhipuVendor._prepare_request 中实现兼容转换:
- adaptive → enabled(budget=16000):保留 thinking 能力,使用 GLM 原生确认支持的格式
- 新增 _build_zhipu_request_snapshot 诊断快照(成功/失败统一格式,可 diff 对比)
- 扩展语义拒绝日志错误体截断(200→500 字符),保留完整字段级诊断
- metadata 暂不处理,待进一步诊断确认兼容性

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Step 1 v2 扩展版本与 Step 1 旧版本同名重复定义,Python 运行时后者覆盖前者
不报错但旧版成为死代码。删除旧版仅保留扩展版本。

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
冲突文件:docs/agents/issue.md — 保留 HEAD 的 Step 2 根因定位和修复记录

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ThreeFish-AI ThreeFish-AI merged commit 9579b85 into feature/1.x.x May 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant