ccswitchmulti icon indicating copy to clipboard operation
ccswitchmulti copied to clipboard

[Bug] Codex Multi-Agent V2 工具 `agents__followup_task` 的 `message.encrypted` 触发 MFJS fail-closed,整个 /responses 请求 422

Open sanjink opened this issue 2 months ago • 1 comments

Self Checks / 自检

  • [x] I have read the FAQ section in README. 我已阅读 README 中的常见问题。

  • [x] I have searched for existing issues, including closed ones. 我已搜索过已有的 Issue(含已关闭)。同类的 fail-closed 报告见 #87(触发点 oneOf)与 #16(第三方路由上的 encrypted_content 投影),本次是新触发点:Codex 侧 agents__followup_task 的 message.encrypted。

CC Switch Version / 版本号

3.20.2-19

Operating System / 操作系统

macOS

Related App / 涉及应用

Codex

Steps to Reproduce / 重现步骤

环境

  • macOS + CCSwitchMulti 3.20.2-19,Codex MultiRouter(schema v2)接管中。

  • 目标 Provider:GLM(公司 OpenAI-compatible 网关 https://<company-gateway>/v1),apiFormat = openai_chat,Provider meta = {},没有手动覆盖 codexToolSchemaDialect。

  • Codex 侧开启了 multi-agent v2,工具名带命名空间前缀:

    [features.multi_agent_v2]
    enabled = true
    hide_spawn_agent_metadata = true
    tool_namespace = "agents"
    
  • 该 Provider 的协议探测档案(protocol_compatibility_profiles,脱敏)里选中的是 Moonshot MFJS:

    {
      "selected_transport": "open_ai_chat",
      "branches": [
        {
          "assessment": { "transport": "open_ai_responses", "baseline": "failed" },
          "tool_schema_dialect": "open_ai",
          "tool_schema_evidence": "unspecified"
        },
        {
          "assessment": {
            "transport": "open_ai_chat",
            "baseline": "passed",
            "streaming": "passed",
            "forced_tool": "passed",
            "continuation": "passed"
          },
          "tool_schema_dialect": "moonshot_mfjs",
          "tool_schema_evidence": "negotiated_tool_call",
          "adaptations": [
            {
              "trigger": "missing_valid_tool_call",
              "change": "tool_schema_moonshot_mfjs",
              "outcome": "verified"
            }
          ]
        }
      ]
    }
    

重现步骤

  1. 路由目标选 GLM Provider,模型 glm-5.3-flash(glm-5.3 同样)。
  2. 在 Codex 里对 glm-5.3-flash 发任意一条消息(请求会自动携带 agents__* 工具列表)。
  3. 请求没有发到上游,直接在本地代理被拒绝并返回 422:
unexpected status 422 Unprocessable Entity: CC Switch local proxy failed while handling Codex endpoint /responses.
Provider: GLM; model: glm-5.3-flash;
cause: 请求/响应转换错误: tool `agents__followup_task` schema at
`$.tools[11].function.parameters.properties.message.encrypted` is incompatible with Moonshot MFJS:
encrypted is not supported by Moonshot MFJS,
url: http://127.0.0.1:15721/v1/responses
  1. 同一路由下所有会话都固定在这条路径失败,只有工具序号随请求变化(日志里出现过 $.tools[8] 与 $.tools[11])。

Expected Behavior / 期望行为

  1. 单个工具 schema 无法用 MFJS 表示时,不应该让整个 /responses 请求 422。 与 #87 一致:应 fail-open(对该工具降级为 strict: false、丢弃无法表示的键、或保留原样直传),只豁免这一个工具并记录结构化事件,而不是 fail-closed 到整个会话。
  2. 建议同时复查 MFJS 方言的继承条件:本例探测档案中的方言升级触发是 adaptation.trigger = missing_valid_tool_call(模型没有按预期返回强制工具调用),没有上游拒绝 schema 的证据,端点也不是 Moonshot/Kimi 域名。如果只在“上游明确拒绝 schema(explicit_rejection / ambiguous_rejection)”时才继承 MFJS,本例这类 422 可能根本不会发生。
  3. Codex 侧 agents.* 工具的 encrypted 语义与 #16 讨论的第三方明文投影相关。如果这些工具在第三方路由上不可能真正使用加密变体,也可以在投影阶段去掉该变体,而不是让编译器报错。

Actual Behavior / 实际行为

  • 请求在本地代理被 MFJS 编译器拒绝(未到上游),422 fail-closed,会话不可用。
  • 只要 Codex 侧工具列表里带 agents__followup_task(multi-agent v2 开启时默认带),该路由上的请求就全部失败。
  • 本机日志合计 87 条相同报错:2026-09-20 58 条(首次 09:58:15)、2026-09-21 11 条、2026-09-22 18 条(最近 10:48:02),路径固定为 ...parameters.properties.message.encrypted。

Additional Context / 补充信息

1. 代码定位

  • src-tauri/src/proxy/providers/codex_tool_schema.rs → MfjsCompiler::compile_object():先把 MFJS 可表达的键(type / enum / properties / required / additionalProperties / items / min* / max* 等)搬进 constraints,随后对任何剩余键直接返回错误:

    if let Some((keyword, _)) = source.iter().next() {
        return Err(self.error(
            &format!("{path}.{keyword}"),
            &format!("{keyword} is not supported by Moonshot MFJS"),
        ));
    }
    

    报错文本即出自这里,encrypted 就是那个“剩余键”。

  • 走 MFJS 并不是因为域名判定(transform_codex_chat_moonshot_schema::upstream_requires_ref_sibling_all_of 只覆盖 moonshot.cn / moonshot.ai / kimi.com),而是运行态继承了探测档案里的方言:codex.rs 的 should_inherit_probe_tool_schema() + protocol_compatibility/types.rs 的 ToolSchemaEvidence::NegotiatedToolCall.allows_runtime_inheritance() == true。

  • 相关 issue:#87(同类 fail-closed,触发点 oneOf)、#16(第三方路由上的 encrypted_content 投影)。

2. 日志证据(脱敏)

2026-09-20 09:58:15 [WARN][cc_switch_lib::proxy::forwarder] [codex] [FWD-003] Provider GLM 请求失败:
  响应转换失败: tool `agents__followup_task` schema at
  `$.tools[8].function.parameters.properties.message.encrypted` is incompatible with Moonshot MFJS:
  encrypted is not supported by Moonshot MFJS

2026-09-22 09:33:57 ~ 10:48:02  同一路径 18 次(`$.tools[8]` 7 次 / `$.tools[11]` 11 次)

3. 我这边没能确认的部分

agents__followup_task 的完整工具 schema 原文(含 message.encrypted)没有从本机安装包里直接导出成功。按编译器的路径命名规则(属性 → {path}.properties.{name},未知键 → {path}.{keyword})判断,出错点是 message 节点上的一个 encrypted 键,而不是某个属性名。如果维护者需要,我可以按指定方法抓取该工具的原始 parameters JSON 再补充到本 issue。

4. 临时绕过方式(参考 #87,未在本机验证)

目标 Provider 卡片 → 高级选项 →「协议配置方式」= 手动覆盖(高级)→「工具 Schema」= OpenAI JSON Schema → 保存后重启 Codex;此时会写入 meta.codexToolSchemaDialect = "openai",运行态不再走 MFJS 编译。

5. 隐私说明

本 issue 不包含 API Key、Token、Cookie、认证头、完整请求体或数据库备份;公司网关域名以 https://<company-gateway>/v1 占位。

sanjink avatar Sep 22 '26 03:09 sanjink

感谢报告,这条已确认并修复(与 #87 同一批根修)。

根因

agents__followup_task 这类 Codex 动态工具的 schema 带有 MFJS 无法验证的未知键(如 encrypted 标记)。旧契约是整请求 fail-closed:一个工具的 schema 编译失败就拒绝整个 /responses 请求,所以只要会话里携带这类动态工具,Moonshot 上游就 422。

修复(已在主线,将随 v3.20.2-20 发布)

  • 未知 schema 键现在被丢弃,并把该工具标记为非严格校验(strict=false)——MFJS 无法验证的键保留也没有意义,放宽接受是正确语义;
  • 其他 MFJS 无法表示的构造(allOf 交集、pattern、tuple items、remote $ref 等)同样改为工具级丢弃,不再毒化整请求;
  • 非互斥 oneOf(如 number/integer)放宽为 anyOf + 非严格。

全量测试通过(4206 passed / 0 failed),覆盖 encrypted 未知键丢弃与动态工具场景。升级 v3.20.2-20 后该 422 不会再出现;若仍有问题请附 proxy_request_logs 对应请求记录再开新 issue。

BigStrongSun avatar Sep 22 '26 20:09 BigStrongSun