Skip to content

v6.8.0 — jobs survive an MCP restart, plus Grok CLI

Choose a tag to compare

@moerasermax moerasermax released this 09 Oct 15:09
· 151 commits to master since this release
claude mcp add ai-cli -s user -- npx -y @tkflyc/ai-cli-mcp

Jobs survive an MCP restart

Until now a dispatched job lived inside the MCP server process: the full output piled up in memory, nothing was ever freed, and a /mcp reconnect lost every running job and its output.

From 6.8.0, every Claude, Codex and Grok job runs under its own small runner process, and the operating system writes stdout/stderr straight to ${AI_CLI_STATE_DIR}/jobs/<jobId>/ (default ~/.local/state/ai-cli/jobs/). The server keeps only metadata and the last 4 KB.

  • Picked up again after a restart. When a new MCP server starts under the same coordinator (the Claude Code or Codex session, identified by PID and process start time), it lists those jobs with recovered: true. Running jobs keep being tracked, jobs that finished while the server was gone return their result, and a job whose runner also disappeared is reported as lost with its output kept.
  • Never re-run. No path re-starts a worker, retries, or re-sends a prompt — so a restart never costs extra tokens.
  • npx users included. Package launchers (npx, npm exec, npm run) are skipped when finding the coordinator, including the rewritten process titles npm uses on Linux and macOS. Checked with real process chains on Windows, Linux and macOS.
  • Collected automatically. Finished jobs are kept for 30 minutes, with caps of 100 jobs and 500 MiB (oldest first). cleanup_processes still removes them at once.
  • Measured. 50 jobs × 1 MiB output: server heap grew by about 0.15–0.3 MB; bytes written were about 0.14% above the output itself.
  • Each job now has a UUID jobId (returned by run, list_processes, get_result, peek, kill_process), so a reused PID on Windows no longer hides an older job.

Check it yourself after upgrading: npm run verify:restart-recovery (in a clone of this repo) dispatches one job per family, kills the server mid-run, starts a new one and checks the results — it uses a little real model quota.

New agent: Grok CLI

grok-4.7, grok-4.7-build-fast, grok-4.6, grok-4.5 (list read from grok models).

  • Long prompts go through --prompt-file; the worker identity lock and your system_prompt go through --rules on every call, including resume; sub-agents are always off. reasoning_effort: low / medium / high / xhigh.
  • Strict (read-only) mode allows only read tools and also removes Grok's native MCP bridge (search_tool / use_tool), shell, write, sub-agent and web tools.
  • Grok reads Claude Code's MCP configuration, so a Grok worker can see ai-cli too. Verified: the ai-cli server Grok starts inherits the worker marker, and a nested dispatch is refused with AI_CLI_NESTED_DISPATCH_BLOCKED.

Fixes

  • query_usage no longer triggers a vendor self-update: Codex starts with check_for_update_on_startup=false, and key presses stop if an interactive update menu appears.
  • ai-cli jobs --watch redraws on the alternate screen instead of pushing copies of the table into the scrollback.
  • The Antigravity model list no longer mixes the built-in fallback into a successful agy models result (gemini-3.5-flash-high is retired).

Compatibility and known limits

Additive (SemVer minor). Visible changes: the extra jobId and recovered fields, and the alternate-screen --watch.

  • Antigravity (ConPTY) and direct-API jobs are not recoverable yet; they are collected after 30 minutes like the rest. Planned for 6.9.0.
  • The runner is a separate process on purpose: if the parent shell is force-killed, its jobs run to completion and are collected later (or stopped with kill_process).

An independent audit by another model found 2 high, 7 medium and 4 low issues; all were fixed before release. Live acceptance across 44 models had zero safety failures, with Claude, Codex, Grok and Gemini all passing. CI is green on Windows, Linux and macOS with Node 20.19 and 22.

Full details: CHANGELOG.


繁體中文

MCP 重啟後,job 會接回來

以前派出去的 job 活在 MCP server 行程裡:完整輸出一直累積在記憶體、從不釋放,/mcp 重連一次,執行中的 job 和輸出就全部不見。

6.8.0 起,每個 Claude、Codex、Grok job 都由自己的小型 runner 行程啟動,stdout/stderr 由作業系統直接寫進 ${AI_CLI_STATE_DIR}/jobs/<jobId>/(預設 ~/.local/state/ai-cli/jobs/),server 只保留 metadata 與最後 4 KB。

  • 重啟後接回。 新的 MCP server 在同一個主導者(Claude Code 或 Codex session,以 PID 加上行程建立時間識別)底下啟動時,會把這些 job 列出來並標 recovered: true:還在跑的繼續追蹤,server 不在期間結束的直接取結果,runner 也不見的標成 lost,輸出保留。
  • 絕不重跑。 任何路徑都不會重新啟動 worker、不重試、不重送 prompt,重啟不會多花 token。
  • npx 使用者也適用。 判定主導者時會跳過 npx、npm exec、npm run 等啟動器,也認得 npm 在 Linux/macOS 上改寫過的行程標題;Windows、Linux、macOS 都以真實行程鏈測試。
  • 自動回收。 結束的 job 保留 30 分鐘,另有 100 個與 500 MiB 上限,由舊到新刪除;cleanup_processes 照樣立即清除。
  • 實測。 50 個各輸出 1 MiB 的 job:server heap 只增加約 0.15~0.3 MB,寫入量只比輸出多約 0.14%。
  • 每個 job 都有 UUID jobId(run、list_processes、get_result、peek、kill_process 都會回傳),Windows 重用 PID 時不再蓋掉較舊的 job。

升級後可以自己驗:在本 repo 的 clone 執行 npm run verify:restart-recovery,它會每家派一個 job、中途殺掉 server、起新 server 再核對結果(會用到少量真實模型額度)。

新 agent:Grok CLI

grok-4.7、grok-4.7-build-fast、grok-4.6、grok-4.5(清單由 grok models 實查)。

  • 長 prompt 走 --prompt-file;worker 身分鎖與你的 system_prompt 每次(含 resume)都經 --rules 送出;一律關閉子 agent。reasoning_effort:low/medium/high/xhigh。
  • strict(唯讀)模式只開讀取工具,並移除 Grok 原生的 MCP 橋接(search_tool/use_tool)、shell、寫入、子 agent 與網路工具。
  • Grok 會讀 Claude Code 的 MCP 設定,所以 Grok worker 也看得到 ai-cli。已實測:Grok 啟動的 ai-cli server 會繼承 worker 標記,再派工會被 AI_CLI_NESTED_DISPATCH_BLOCKED 擋下。

修正

  • query_usage 不再誤觸 vendor 自動更新:Codex 啟動時帶 check_for_update_on_startup=false,畫面出現互動式更新選單就停止送鍵。
  • ai-cli jobs --watch 改在替代畫面重畫,不再把一份份表格推進捲動緩衝區。
  • Antigravity 模型清單在 agy models 查詢成功時不再混入內建後備清單(gemini-3.5-flash-high 已退役)。

相容性與已知限制

新增功能為主(SemVer MINOR)。看得到的變化:多了 jobId 與 recovered 欄位,--watch 改用替代畫面。

  • Antigravity(ConPTY)與 direct-API 的 job 尚不能接回,但同樣在 30 分鐘後回收;預計 6.9.0 處理。
  • runner 刻意做成獨立行程:外層 shell 被強制結束時,底下的 job 會跑到結束再被回收(或用 kill_process 停掉)。

另一家模型的獨立稽核找到 2 個高、7 個中、4 個低嚴重度問題,全部在發佈前修正。44 個模型的實機驗收安全性失敗為 0,Claude、Codex、Grok、Gemini 四家都通過。CI 在 Windows、Linux、macOS 的 Node 20.19 與 22 全部通過。

完整內容見 CHANGELOG。