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:
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:
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:
- Start
ucagent toffee-utwith--backend blank --mcp-server --exit-on-completionso the client can use the workflow and file tools over MCP. - Code Agent connects to
/mcpand, 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.
The format of --hook-message is [config_file.yaml::]continue_key[|stop_key]:
- Without a file, it reads from the
hooksin the current layered configuration; continueandquitare default keys in the built-in configuration;- You can also write
config.yaml::my_continue|my_stopto 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:
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-completionwas 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/mcpaddress, 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.