runWorkflow is the primary entry point for executing a workflow. It accepts a compiled SmithersWorkflow object and a RunOptions bag, drives the render-schedule-execute loop until completion, and returns a RunResult.
Basic Usage
Signature
RunOptions
| Field | Type | Default | Description |
|---|---|---|---|
input | Record<string, unknown> | (required) | Input data for the run. Must be a JSON object. In the manual API it should match the input table schema; in the schema-driven API it is stored as a JSON payload. The runId key is injected automatically. |
runId | string | Auto-generated | Provide a deterministic run ID. If omitted, a new unique ID is generated. |
resume | boolean | false | Resume an existing run instead of starting a new one. Requires runId. Skips already-completed tasks and picks up from the last checkpoint. |
maxConcurrency | number | 4 | Maximum number of tasks that can execute in parallel at any given time. Also respects per-group limits set by <Parallel maxConcurrency>. |
onProgress | (e: SmithersEvent) => void | undefined | Callback invoked for every lifecycle event. See Events. |
signal | AbortSignal | undefined | Standard AbortSignal to cancel the run. When aborted, the run finishes with status "cancelled". |
workflowPath | string | undefined | Absolute or relative path to the workflow .tsx file. Used to resolve the default rootDir and stored in the run metadata. |
rootDir | string | Workflow file’s directory | Root directory for the tool sandbox. All file-system tools (read, edit, write, bash, grep) are confined to this directory. |
logDir | string | null | .smithers/executions/<runId>/logs | Directory for NDJSON event log files. Set to null to disable log file output entirely. Relative paths are resolved from rootDir. |
allowNetwork | boolean | false | Whether the bash tool is permitted to make network requests. |
maxOutputBytes | number | 200000 | Maximum number of bytes a single tool call can return. Output is truncated beyond this limit. |
toolTimeoutMs | number | 60000 | Maximum wall-clock time (in milliseconds) for a single tool call before it is killed. |
RunResult
| Field | Type | Description |
|---|---|---|
runId | string | The run identifier (either provided or auto-generated). |
status | string | Terminal status of the run. |
output | unknown | Rows from the output table in the schema, if the workflow finished successfully and the schema includes an output table. |
error | unknown | Error information if the run failed. Contains a serialized error object with code, message, and optional details. |
Status Values
| Status | Meaning |
|---|---|
"finished" | All tasks completed successfully. |
"failed" | A task failed (after exhausting retries) and continueOnFail was not set. |
"cancelled" | The run was cancelled via AbortSignal. |
"waiting-approval" | At least one task requires human approval before the run can continue. Use smithers approve or smithers deny to unblock. |
Resuming a Run
To resume a previously paused or crashed run, passresume: true along with the original runId. Smithers reads the persisted state from SQLite, skips tasks that already have valid output rows, and continues executing from the first pending task.
- The original input row is loaded from the database. You do not need to provide
inputdata again (pass an empty object). - Stale in-progress attempts older than 15 minutes are automatically cancelled and retried.
- Tasks with valid persisted outputs are skipped.
Cancellation
Pass anAbortSignal to cancel a running workflow:
NodeCancelled events are emitted.
Event Monitoring
Use theonProgress callback to receive real-time events as the run progresses:
Idle Sleep Prevention
On macOS,runWorkflow automatically acquires a caffeinate lock to prevent the system from idle-sleeping while a workflow is running. The lock is released when the run finishes, fails, or is cancelled. This is a no-op on other platforms.
Error Handling
If an unhandled exception occurs inside the engine (outside of individual task execution), the run is marked as"failed" and the error is serialized into RunResult.error. Individual task failures are handled by the retry and continueOnFail mechanisms.
Set SMITHERS_DEBUG=1 in your environment to print engine-level errors to stderr.
Related
- Events — All event types emitted during a run.
- renderFrame — Preview the workflow graph without executing.
- CLI — Run workflows from the command line.
- Resumability — How durable state and crash recovery work.