Skip to content

Batch Execution

The core of batching is for a task to exit upon completion, then start the next task; in MCP scenarios, you can also use the Code Agent's Stop hook to automatically send continue or exit prompts. Each task must use an independent workspace to avoid confusion with history and artifacts.

1. Automatic Exit

Add the following when starting UCAgent:

1
2
3
4
5
--exit-on-completion

# Short form

-eoc

This option exits the process when the workflow passes its checks and the Agent successfully calls Exit. Batch scripts should also check the exit code, stage status, and actual artifacts.

After preparing separate workspaces as described in Normal Mode, run ToffeeUT tasks sequentially:

1
2
3
set -e
ucagent toffee-ut workspaces/adder Adder --tui --loop --exit-on-completion
ucagent toffee-ut workspaces/mux Mux --tui --loop --exit-on-completion

Run with different workspaces; do not rm -rf output inside the loop while directories are still in use. When restarting, explicitly select a new workspace for the current task or clean its dedicated directory according to project conventions.

2. Source Repository Example

Legacy UnitTest batch example

examples/BatchRun/README.md and the Makefile retain api_batch and mcp_batch for existing UnitTest projects. Each run creates a separate batch directory and checks the process exit code, stage completion, and Exit in .ucagent/ucagent_info.json.

3. MCP + Hook

MCP batching typically involves two terminals:

  1. Start ucagent toffee-ut with --backend blank --mcp-server --exit-on-completion so the client can use the workflow and file tools over MCP.
  2. Code Agent connects to /mcp and, at each stop, retrieves the next prompt via the hook and sends it to the client.

Run this command from the current task's workspace.

ucagent --hook-message 'continue|quit'

The format of --hook-message is [config_file.yaml::]continue_key[|stop_key]:

  • Without a file, it reads from the hooks in the current layered configuration;
  • continue and quit are default keys in the built-in configuration;
  • You can also write config.yaml::my_continue|my_stop to read custom YAML keys;
  • The command only outputs the prompt and does not send messages or operate tmux.

In shell hooks, correctly quote prompts containing spaces and explicitly specify the target tmux pane. Hook schemas and timeout units differ across Code Agents; refer to client documentation.

Example command to add MCP for Claude Code:

claude mcp add --transport http ucagent http://127.0.0.1:5000/mcp

See the documentation for your client for its complete hook configuration.

4. Reliable Batch Verification

Each task must record at least:

  • workspace, DUT, configuration file, and MCP port;
  • startup command, start/end time, and exit code;
  • .ucagent/ status, test report, and major phase results;
  • logs and next actions for failed tasks.

Batch scripts should stop or enter a clear failure queue upon encountering failures, rather than continuing to copy half-finished artifacts that may overwrite successful results. Before retrying, determine whether the failure is due to model/API issues, test infrastructure, configuration, or DUT defects.

5. Troubleshooting

  • Task does not exit automatically: Verify that all phases passed, the Agent called Exit, and --exit-on-completion was passed.
  • Hook not triggered: First run ucagent --hook-message 'continue|quit' alone to check output, then verify the client hook command, tmux pane, and permissions.
  • MCP connection fails: Check --mcp-server-port, client /mcp address, host, firewall, and client timeout.
  • Repeated execution overwrites results: Assign an independent workspace or a result directory with a timestamp to each task; do not treat old output/ as a global temporary directory.

Run a single task first, then add the same command to the batch; for parallel instead of serial execution, see Multi-instance Concurrent Execution.