Run Controls
A host (a UI, a job runner, MAESTRO) often needs to stop or hold a chain while it
runs. CARL gives four controls: fail_fast, pause/resume, cancel, and the chain
timeout. A chain can also stop itself early with a
terminate step (0.5.2); fail-fast and host
cancellation take priority over it. All of them act at step boundaries: a step that has already started
runs to its own end or to its timeout.
Fail-fast
Section titled “Fail-fast”By default a failed step does not stop the chain. Independent steps keep running, and so do steps that depend on the failed one: they see whatever the failed step left (often nothing). This is the historical behaviour.
Turn on fail_fast to stop scheduling after the first final failure:
chain = ReasoningChain(steps=steps, max_workers=4, fail_fast=True)
# orchain = ChainBuilder()...with_fail_fast().build()
# or directlyDAGExecutor(fail_fast=True)With fail_fast=True:
- after a step fails for good (its own retries and fallbacks are used first), no new step starts;
- steps already running finish;
- every step that did not start is reported as skipped
(
StepExecutionResult.skipped=True); - the chain result has
success=False, andresult.metadata["fail_fast"]says what happened:
{ "enabled": True, "triggered": True, "failed_step_number": 1, "skipped_step_numbers": [3, 2],}Rules and limits:
fail_fastmust be abool. Withfail_fast=True,max_workersmust be a positiveintor"auto".- Fail-fast wins over loops and chain-level RE-PLAN: a failure stops the run instead of looping back or re-planning.
- External side effects of completed steps are not rolled back.
fail_fastis written byto_dict()and read byfrom_dict().- An unexpected exception inside a step executor becomes a failed step result
(with
error_traceback), not a crash of the run.
Pause and resume
Section titled “Pause and resume”Pause is acknowledged: asking for a pause and being paused are different states.
task = asyncio.create_task(chain.execute_async(context))
context.request_pause()context.is_pause_requested() # True right awaycontext.is_paused() # False while a step is still running# ... the running step finishes, the scheduler waits ...context.is_paused() # True: nothing is running
context.clear_pause() # resumeresult = await taskrequest_pause()sets the request. Queued steps check it before they start. Running steps (an LLM call, a tool) finish normally.is_paused()isTrueonly when a pause was requested, the scheduler is waiting, and no step is active. Use it to show “Paused” in a UI.clear_pause()resumes. Completed steps are not replayed.paused_duration()returns the accumulated idle pause time in seconds.wait_for_resume()is the awaitable the executor uses; custom executors can use it too.- Parallel snapshot contexts share one pause token, so one call reaches the whole batch.
Cancel
Section titled “Cancel”from mmar_carl import ExecutionCancelledError
task = asyncio.create_task(chain.execute_async(context))context.cancel()try: await taskexcept ExecutionCancelledError as exc: partial = exc.result # ReasoningResult with completed stepscancel()requests cancellation and also wakes a paused run, so a paused chain can be cancelled without resuming first.- Steps that have not started are skipped; running steps finish.
- The run raises
ExecutionCancelledError. Itsresultholds the partialReasoningResult(success=False). is_cancelled()(aliasis_cancellation_requested()) andawait wait_for_cancellation()let long-running tools and custom executors stop early. Chain tools, for example, cancel their nested run.reset_cancellation()clears the flag before reusing a context.
Timeouts
Section titled “Timeouts”| Level | Where | What happens |
|---|---|---|
| Chain | ReasoningChain(timeout=...), ChainBuilder.with_timeout() | Checked before each batch starts. When the active time is over the limit, the run raises TimeoutError (Chain execution timed out after …s. Completed k/n steps.). Idle pause time is not counted. |
| LLM step | LLMStepDescription.timeout, LLMStepConfig.timeout | Per call. |
| Tool step | ToolStepConfig.timeout (default 30.0) | Per tool call; fallbacks via ToolErrorRecovery.on_timeout. |
| Agent and runtime steps | their own config | E.g. AgentStepConfig.timeout_seconds, ClaudeCodeStepConfig.timeout, CodexStepConfig.timeout, ChainToolDefinition.timeout_seconds, command and code runtime limits. |
The chain timeout also caps every step. The executor waits at most for
the step’s own timeout (or the chain timeout when the step has none), and
never longer than what is left of the chain deadline. Steps running in parallel
share that remaining deadline. A step that runs out fails with
Step timed out after …s; it does not raise. Only LLM and
command-plan steps (and the legacy StepDescription) carry a step-level
timeout field, so for other step types the chain value is the cap. Tool and agent steps also apply their own config timeouts inside.
See also
Section titled “See also”- ReasoningChain · Async execution
- Human-in-the-loop: waiting for a person is a step, not a pause.