Repository navigation
v6.6.1 — the nested-dispatch block now reaches Codex workers
claude mcp add ai-cli -s user -- npx -y @tkflyc/ai-cli-mcpThe nested-dispatch block didn't reach Codex workers
The 6.6.0 notes said the worker marker "is inherited, so this covers a worker's own MCP server". That holds for Claude and not for Codex. Codex passes its MCP servers an allowlist of environment variables (19 of them, measured with codex-cli 0.160.1), and AI_CLI_WORKER isn't on it. The ai-cli server running under a Codex worker therefore always took itself for the coordinator, and AI_CLI_NESTED_DISPATCH_BLOCKED never fired there. Claude passes its whole environment, so Claude workers were covered.
It surfaced in an acceptance run after upgrading another machine. The policy hook had been added to ~/.codex/hooks.json but not yet approved, so codex exec skipped it and Codex workers got no identity lock either. With both layers down, gpt-6-sol called ai-cli.run twice and both jobs started. After the hook was approved, a rerun of all 8 Codex models had 0 safety failures, but that was the identity lock holding, not the block.
The fix
For normal-mode Codex jobs, ai-cli now adds -c mcp_servers.<name>.env.AI_CLI_WORKER='1' for each stdio MCP server in $CODEX_HOME/config.toml. An explicit AI_CLI_ALLOW_NESTED=1 from the coordinator is passed on as well. An end-to-end run with real Codex and hooks switched off, so only the block was left, got AI_CLI_NESTED_DISPATCH_BLOCKED back and no job started.
The rule is to miss a server rather than add a wrong override. If an override points at something Codex won't accept, Codex refuses to load its config and every normal-mode Codex job fails. Two such cases were tested:
- an undefined server name →
invalid transport - a URL (streamable HTTP) server →
env is not supported for streamable_http
So ai-cli only touches [mcp_servers.<name>] tables that contain command =. It ignores look-alike lines inside multi-line strings and resolves a relative CODEX_HOME against the job's working directory, the same way Codex does. Read-only (strict) jobs are left alone, since they run with --ignore-user-config. Values use TOML single quotes: on Windows cmd.exe strips double quotes, and "1" would arrive as the integer 1.
Not covered: servers defined with dotted keys, inline tables, [[...]] arrays of tables, or in a project-level .codex/config.toml. For those, the remaining layer is the hook's identity lock, which only works once the hook is installed and approved.
An independent review caught the multi-line-string and URL-server cases before release. The CHANGELOG lists each finding and what was done about it.
Installing the hook for Codex
A hook newly added to ~/.codex/hooks.json has to be approved once in an interactive codex session. Until then codex exec skips it. The acceptance tool's static checks can't see this; only the identity probe's B answer does.
Full details: CHANGELOG.
繁體中文
巢狀派工的硬擋沒有擋到 Codex worker
6.6.0 的說明寫「標記會被繼承,所以 worker 自己的 MCP server 也擋得住」。這對 Claude 成立,對 Codex 不成立。Codex 只把一份白名單裡的環境變數交給 MCP server(以 codex-cli 0.160.1 實測是 19 個),AI_CLI_WORKER 不在其中。於是 Codex worker 底下的那個 ai-cli 永遠以為自己是主導者,AI_CLI_NESTED_DISPATCH_BLOCKED 在那裡從來不會觸發。Claude 會把整份環境交下去,所以 Claude worker 沒有這個問題。
這是另一台機器升級後跑驗收時發現的。派工政策 hook 已加進 ~/.codex/hooks.json,但還沒經過核准,codex exec 就跳過它,Codex worker 也拿不到身分鎖。兩層同時失守,gpt-6-sol 呼叫 ai-cli.run 兩次,兩個 job 都啟動了。hook 核准之後重跑 Codex 全部 8 個模型,安全性失敗為 0,但那是身分鎖擋住的,不是硬擋。
修法
一般模式的 Codex job,ai-cli 現在會對 $CODEX_HOME/config.toml 裡每個 stdio MCP server 加上 -c mcp_servers.<名稱>.env.AI_CLI_WORKER='1'。主導者明示的 AI_CLI_ALLOW_NESTED=1 也會一併轉交。以真的 Codex 端到端實跑、並關掉 hooks 只留硬擋,結果拿到 AI_CLI_NESTED_DISPATCH_BLOCKED,沒有任何 job 被啟動。
原則是寧可漏補、不可錯補。覆寫指向 Codex 不接受的目標時,Codex 會拒絕載入設定,所有一般模式的 Codex job 都會失敗。實測過兩種:
- 未定義的 server 名稱 →
invalid transport - URL 型(streamable HTTP)server →
env is not supported for streamable_http
所以 ai-cli 只處理含有 command = 的 [mcp_servers.<名稱>] 表,忽略多行字串裡長得像表頭的行,相對路徑的 CODEX_HOME 以 job 的工作目錄解析(Codex 自己也是這樣)。唯讀(嚴格模式)的 job 帶 --ignore-user-config,不做處理。值用 TOML 單引號:Windows 上 cmd.exe 會剝掉雙引號,"1" 送到時會變成整數 1。
沒有涵蓋的:用點號鍵、inline table、[[...]] 陣列表定義的 server,以及專案層 .codex/config.toml 裡的 server。這些情況剩下 hook 的身分鎖那一層,而且要 hook 已安裝並核准才有作用。
發版前的獨立稽核抓到了多行字串與 URL 型 server 這兩種情況;CHANGELOG 列出每一項發現與處置。
為 Codex 安裝 hook
新加進 ~/.codex/hooks.json 的 hook,要在互動式 codex 裡核准一次。在那之前,codex exec 會跳過它。驗收工具的靜態檢查看不出這件事,只有身分探針的 B 欄答案會顯示出來。
完整內容:CHANGELOG。