Skip to content

fix(runtime): restore SOP gate tools when stdio MCP args are empty - #1292

Open
Robert0622 wants to merge 1 commit into
mainfrom
codex/fix-sop-gate-mcp-args
Open

Robert0622 wants to merge 1 commit into
mainfrom
codex/fix-sop-gate-mcp-args

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

The shared stdio MCP renderer writes a nil Go argument slice as JSON null. Several CLIs reject that entry. When the entry is the built-in gate server, an Agent can produce its artifact and then stop the SOP because the terminal decision tool is missing.

Scope

  • Platform core / API / runner

Compatibility

The change applies to generated CLI configuration and requires no data migration. An Agent still submits a structured terminal decision. A required human gate waits for approval after a valid submission.

Validation

  • The new regression fails on the base with args: null and passes with the shared fix. The runtime package and focused engine submission checks pass.
  • Six SOP runs passed on an isolated Linux installation using the patched binary and DeepSeek V4.1 Flash. Claude Code, Pi, Kimi, DeepSeek Harness, and CodeBuddy each published an artifact, submitted pass, and ran a downstream node. The separate required-manual-gate run first recorded pass, waited for approval, and then ran downstream after approval.
  • Chatbot build and 486 tests, go vet ./..., the public content check, and the pinned Gitleaks scan passed.
  • The public Playwright suite first reported 23 passed, 6 skipped, and 2 failed. The generic SOP cleanup timeout passed on a focused retry. The short-window reference picker assertion failed identically with the base binary.
  • Three browser-dependent Go cases in the initial core run passed with the browser enabled on focused reruns. Two separate local Chromium startup cases showed the same startup error with the base source.

Safety

  • The diff contains source code and synthetic regression inputs.
  • User files and unrelated changes were preserved.

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查结论:Approve(head 43acea2a,base d2462fa5)

审查范围

  • internal/runtime/materialize.go 中 mcpConfigEntries 的改动:stdio 条目在 args 为空时不再写出该字段。
  • 读了渲染结果的所有下游:共享 mcp.json(Claude Code、CodeBuddy)、Pi、Kimi、Cursor、Antigravity、DeepSeek Harness、opencode、zcode,以及 Codex 的 -c mcp_servers.* 参数。
  • 只有 agent_cli.go 中 opencode 的适配逻辑会读 entry["args"],字段缺失时它也能正确处理。

实际验证(隔离环境、合成数据)

  • 新增的 TestWriteAgentCLIMCPConfigStdioArgs(pi/kimi/cursor/agy)和 TestMaterializeInvocationInjectsGateMCP 在 head 通过。只把 materialize.go 换回 base 版本后两项都失败:gate 条目写出 "args":null。由此可以确认这个回归是本 PR 修掉的。
  • 用临时探针按 head 和 base 分别生成各 CLI 的实际配置文件,结果如下:
    • 所有 JSON 都能正常解析。
    • 空 args 由 base 的 null / [] 变成省略该字段。
    • 有参数的条目(含空字符串参数)顺序和内容不变。
    • opencode、zcode、Codex 和 HTTP 条目的输出与 base 完全一致。
  • 在 internal/runtime、internal/httpapi、internal/engine、internal/domain 跑了 go test:domain 通过;其余失败(bwrap、Docker、Chromium 不可用,以及缺少 gitignore 掉的 native-chat 资源)在 merge-base 上逐项对照,都能同样复现,属于环境问题,与本 PR 无关。
  • CI 全部通过。

未做的验证

  • 没有用真实 CLI 和模型跑 SOP 端到端,也没有确认 gate 工具在各 CLI 里重新可见:本环境没有供应商凭据。
  • 用户显式配置空 args: [] 时,现在也会省略该字段。没有找到要求 args 必须存在的 CLI;zcode 和 Codex 路径原本就是这样处理的。

@cocofhu00

Copy link
Copy Markdown
Contributor

结论:建议合入

GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号无法提交正式 Approve / Request changes。以下改为普通评论。

核对了 stdio MCP 配置:参数为空时不再写出 args: null,有参数时仍按原顺序保留。这能避免内置 gate 被部分 CLI 拒绝,导致产物写完后 SOP 停住。测试检查了 Pi、Kimi、Cursor、Antigravity 以及真实 gate 配置。CI 已全部通过,与 main 没有冲突。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 用真实 CLI 跑 SOP 实测(head 43acea2a),没有发现问题

在本机分别部署 main 和这个 PR,用**真实的 Cursor CLI(模型 grok-4.7-high)**跑同一个 SOP:Agent 节点写出 report.md(必需产物),下游接一个脚本节点。

main PR
生成的 .cursor/mcp.json "agentflow-gate": {"args": null, ...} 不再写 args 字段
Cursor 能不能看到 gate 工具 GetMcpTools 报错:namespace "agentflow-gate" not found. Available namespaces: cursor 直接调用了 agentflow-gate__submit_gate_result
过程 30 次工具调用、100 秒、4.6 万 token。模型去读平台源码 internal/gatemcp/server.go,然后手写 JSON-RPC 调 gate 二进制,绕了一圈才交上结果 3 次工具调用、37 秒、2 万 token
结果 这次碰巧绕过去了,换个弱一点的模型就会卡在「产物写完、交不了终态」 pass,下游节点运行成功

git merge main 没有冲突。合并后复跑了 runtime 里 MCP/Gate/Materialize 相关的测试,结果见文末。

合并 main(3815373c)后复跑 runtime 的 MCP/Gate/Materialize 测试:只有 TestEnvironmentIdentityGitAndMCPHeaders 失败,main 上同样失败(本机环境原因),没有新增失败。

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.

3 participants