Skip to content

feat(vendor-channels): 过渡管线诊断快照与 Anthropic 配对自检#255

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

feat(vendor-channels): 过渡管线诊断快照与 Anthropic 配对自检#255
ThreeFish-AI merged 12 commits into
feature/1.x.xfrom
ThreeFish-AI/sacramento-v1

Conversation

@ThreeFish-AI

Copy link
Copy Markdown
Owner

摘要

prepare_zhipu_to_anthropic 过渡管线中引入两个辅助函数,提升变换阶段的可观测性与协议兼容性自检能力,定位 enforce_anthropic_tool_pairing_enforce_pairing_sanity_pass 之外的边界 case。

变更内容

1. _dump_message_digest — 过渡管线诊断快照

  • 输出前 N 条消息的结构摘要(role + content_type_counts),用于诊断变换前后的消息形态差异
  • 仅在 DEBUG 级别且消息非空时输出,避免日志噪声
  • prepare_zhipu_to_anthropic 的 4 个关键阶段插桩(before / after_rewrite / after_enforce / after_strip

2. _validate_anthropic_pairing — 独立配对自检

  • 纯检测,不修改消息列表,与 enforce_* 形成职责正交
  • 针对每个 assistant + tool_use,精确记录下一条 user 消息中匹配/缺失的 tool_use_id
  • 检测三类异常:
    • 末尾截断(assistanttool_use 但无后继 user
    • 角色错位(tool_use 后非 user 消息)
    • 部分缺失(tool_use_iduser.content.tool_result 中未匹配)
  • 异常时输出 WARNING 日志并返回问题列表;在 prepare_zhipu_to_anthropic 末端执行,发现问题时追加 anthropic_pairing_validation_issues 适配标签

设计取舍

  • 不修改原有 enforce_anthropic_tool_pairing:保持原有自动修复链路的稳定性,新增自检作为独立保险层
  • 末端执行自检:在所有变换(rewrite / enforce / strip)完成后运行,反映对外提交前的最终状态
  • WARNING 而非 ERROR:自检定位为诊断观测手段,不阻断请求

测试覆盖

新增 TestDumpMessageDigestTestValidateAnthropicPairing 测试类,覆盖:

  • 空消息列表零输出
  • 多类型 content 结构摘要(list / str / empty)
  • 正确配对零问题
  • 缺失 tool_result 检测
  • 后继非 user 角色检测
  • 末尾截断检测
  • 部分缺失仅报告缺失 ID
  • prepare_zhipu_to_anthropic 的集成(正常路径不触发标签,构造场景下捕获缺陷)

测试计划

  • 单测:uv run pytest tests/test_vendor_channels.py -k "TestDumpMessageDigest or TestValidateAnthropicPairing" -v
  • 全量回归:uv run pytest tests/test_vendor_channels.py -v
  • 联调:在 DEBUG 日志级别观察 zhipu → anthropic 过渡管线的 digest 输出

ThreeFish-AI and others added 12 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>
在 prepare_zhipu_to_anthropic 管线中新增两个辅助函数:
1. _dump_message_digest: 输出各阶段消息结构摘要(DEBUG 级别),
   用于过渡管线变换前后的可观测性诊断
2. _validate_anthropic_pairing: 独立的 tool_use/tool_result 配对
   自检(纯检测,不修改),定位 enforce/sanity 未覆盖的边界 case

🤖 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>
@ThreeFish-AI ThreeFish-AI merged commit 288b14b into feature/1.x.x May 27, 2026
6 checks passed
@ThreeFish-AI ThreeFish-AI deleted the ThreeFish-AI/sacramento-v1 branch May 28, 2026 06:01
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