Introducing a new way to review your PRs.

Read the announcement

solana-foundation / surfpool

Surfpool is where developers start their Solana journey.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / runbook-automation

Runbook automation

Runbook automation packages repeatable project actions for a Surfpool session. A runbook can prepare a local network, deploy programs, seed state, or perform another declared workflow. The CLI loads the workflow from a workspace manifest or a runbook file, applies the selected environment and inputs, then reports progress and results through logs, consoles, saved state, and optional JSON output.

Runbook model

Runbooks sit between the operator-facing CLI and the local Surfnet. They turn a project workflow into a named unit that can run by hand, during Surfnet startup, or from a script. For the wider choice of operator surfaces, see User interfaces and automation.

Workspace package

A runbook package is described by a txtx.yml workspace manifest. The manifest gives each runbook an ID, a source location, and an optional description. It also gives the workflow named environments and top-level inputs so the same actions can target a local network, a public Solana network, or another configured context.

The package can also be a direct .tx file. This path is useful when a workflow is not listed in the manifest. Generated projects use a runbooks/deployment package as the standard deployment workflow and keep environment-specific signer material beside it.

References: crates/…/mod.rs• L45-60 crates/…/mod.rs• L746-870 crates/…/mod.rs• L121-129 crates/…/mod.rs• L305-376 crates/…/mod.rs• L409-495

Action workflow

The runbook system presents a workflow as a sequence of actions with shared context. The context combines the workspace manifest, the selected environment, input files or values, authorization information, and the add-ons that provide standard and SVM-aware capabilities. The action engine then runs the workflow against the selected network context rather than making each CLI command define its own deployment or setup logic.

This packaging makes operational actions reusable. A project can keep deployment and setup in one named runbook while adding other runbooks for seeding, checks, or scenario preparation. The CLI does not need to know the internal action list; it selects the runbook and supplies the execution context.

References: crates/…/mod.rs• L191-236 crates/…/mod.rs• L48-65 crates/…/mod.rs• L882-912

CLI execution

The CLI exposes runbooks as both a discovery operation and an execution operation. This keeps the package definition in the project while giving people and automation a small, stable command surface.

Runbook selection

surfpool ls reads the selected manifest and shows the runbook IDs and descriptions that the workspace exposes. surfpool run RUNBOOK selects one manifest entry by ID, or loads a runbook from the supplied file path when the ID is not found in the manifest.

The execution command can select an environment with --env and pass one or more input files with --input. It can also explain the plan, choose a log level and log directory, and request JSON output. CLI and HTTP server describes how this command fits with the other top-level CLI commands.

References: crates/…/mod.rs• L114-137 crates/…/mod.rs• L746-870 crates/…/mod.rs• L1003-1008 crates/…/mod.rs• L1103-1122

Execution modes

Runbook execution has one action model but several presentation modes. An unsupervised run is suited to scripts and CI. A supervised run can expose a browser console or a terminal console so an operator can inspect action progress and stop the run.

The mode changes observation and control, not the project workflow. All modes use the same runbook inputs, emit the same runbook lifecycle events, and return success only after the action engine reports completion.

ModeMain useOperator signal
UnsupervisedCI, scripts, and background workExit result, logs, saved state, and optional JSON
Browser supervisedInteractive review of a workflowBrowser console with action and log progress
Terminal supervisedInteractive work without a browserTerminal console with action and log progress

References: crates/…/mod.rs• L758-870 crates/…/mod.rs• L910-912 crates/…/mod.rs• L321-350 crates/…/mod.rs• L355-552

Startup runbooks

Surfpool uses runbooks as part of project startup when deployment or setup is enabled. Startup first brings up the local network, then plans the project work and marks the runbook task as part of readiness. This means a process can be running before the project is usable, while readiness waits for its required runbooks to finish.

Startup sources

Startup chooses how to obtain the deployment workflow from the project state. An existing txtx.yml is authoritative. When no manifest exists, the CLI can generate a runbook on disk from detected project information, or build an equivalent in-memory deployment workflow when the command needs custom artifact handling or compatibility behavior.

The selected startup runbooks are associated with the local environment. Multiple runbook IDs can be supplied to surfpool start --runbook, and input files can be supplied with --runbook-input. --no-deploy removes deployment work from the startup plan, but the startup lifecycle still seals an empty plan before the network becomes ready.

References: crates/…/startup.rs• L36-80 crates/…/startup.rs• L207-331 crates/…/mod.rs• L289-337 crates/…/mod.rs• L248-280

Startup lifecycle

The startup planner seals the required work before it dispatches the runbooks. The local network can report that its core is started before this point, but it cannot report full readiness until every declared startup task completes successfully. Runbook progress flows to the selected terminal or headless logger while the startup state tracks the result for readiness consumers.

The startup path is therefore:

sequenceDiagram
    participant C as CLI
    participant N as Local Surfnet
    participant P as Startup planner
    participant R as Runbook engine
    participant O as TUI or headless logger

    C->>N: Start local network
    N-->>C: Core started
    C->>P: Inspect project and seal required tasks
    P->>R: Dispatch startup runbooks
    R-->>O: Send logs and progress
    R-->>P: Report success or failure
    P-->>N: Mark startup ready or failed

References: crates/…/mod.rs• L63-72 crates/…/mod.rs• L230-337 crates/…/startup.rs• L334-452 crates/…/types.rs• L763-781

Artifact watching

With --watch, the CLI monitors the deploy-artifact directory and runs the selected startup workflows again when a program .so file is created or changed. This supports a short edit-build-run loop without restarting the Surfnet process. The watcher is a development aid; the initial startup plan remains the source of readiness state.

References: crates/…/mod.rs• L315-327 crates/…/startup.rs• L433-449 crates/…/startup.rs• L455-542

Progress and results

Runbooks expose progress at two levels. Action-level events show what the workflow is doing, while runbook lifecycle events show whether the named workflow has started or completed. The CLI and terminal UI consume these signals so an operator sees the same broad result whether the run is supervised or headless.

Lifecycle signals

The shared event model identifies a runbook by ID when it starts and when it completes. Completion carries optional diagnostic messages. The terminal UI and headless logger use these events to show workflow boundaries and to stop treating startup actions as ordinary post-start transactions.

The Surfnet information response also exposes runbook execution status for clients that need a readiness view. A status record contains the runbook ID, start time, optional completion time, and optional errors.

References: crates/…/types.rs• L450-479 crates/…/types.rs• L1596-1658 crates/…/mod.rs• L408-528 crates/…/simnet.rs• L465-623

Outputs and logs

Successful execution collects named runbook outputs. With --output-json and a directory, the CLI writes those outputs to files. With JSON output requested without a directory, it prints the result. Logs remain available through the configured runbook log path, while progress events can also feed the browser or terminal supervisor.

The output conversion uses the add-ons known to the CLI. This lets values from standard and SVM-aware actions cross the JSON boundary in a form that external scripts can consume.

References: crates/…/mod.rs• L800-815 crates/…/mod.rs• L48-59 crates/…/mod.rs• L711-766 crates/…/mod.rs• L812-895

Repeat execution

Runbook state lets repeated operations account for what happened before. When a manifest provides a state location, a later run can compare the saved execution snapshot with the current workflow and focus on changed or unfinished work.

State comparison

Before a stateful rerun, the CLI loads the prior snapshot and simulates the current flows to find additions, edits, and actions left by an earlier failure. It displays the meaningful changes and asks for confirmation before continuing when the comparison requires operator review. If nothing changed, it reports that the snapshot is already in sync and does not run the workflow again.

This behavior makes a runbook suitable for repeatable deployment and setup. The workflow remains declarative from the operator's view, while the saved state prevents an interrupted run from being treated as a completely new operation.

References: crates/…/mod.rs• L238-319 crates/…/mod.rs• L555-644

Failure recovery

An unsuccessful action run emits diagnostics and writes transient state when a state location is available. The next run can identify the actions associated with the earlier interruption and schedule them for re-execution. A successful run writes normal execution state after it handles its outputs.

State is a recovery aid, not a guarantee that an external action is safe to repeat. Actions that affect an external network still need workflow-level safeguards and suitable input values.

References: crates/…/mod.rs• L679-766

Scenario relationship

A runbook and a scenario solve different parts of repeatable testing. A runbook describes operational actions such as deployment or setup. A scenario describes account states over a slot-based timeline so a protocol can be observed under controlled conditions.

Scenario preparation

Scenario definitions contain ordered account overrides and can be registered for execution in a Surfnet. Their account addresses and values can come from reusable protocol templates, while the runbook remains the place for project actions that prepare the environment around that test. This separation keeps time-based state changes distinct from deployment and operational steps.

For scenario data and protocol templates, see Scenario execution. For the CLI and other user-facing paths that operate the same Surfnet, see Interactive terminal.

References: crates/…/README.md• L1-33 crates/…/scenarios.rs• L464-590 crates/…/mod.rs• L191-236

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep runbook IDs, manifest locations, and generated source locations aligned. A manifest can list a workflow that the loader cannot resolve.
  • Keep environment and input selection consistent between direct surfpool run execution and startup execution. The same runbook can otherwise act on different network or signer contexts.
  • Keep the three execution modes on the same lifecycle and diagnostic contract. A supervised view must not hide a failure that makes an unsupervised run exit unsuccessfully.
  • Keep startup task sealing and runbook completion paired. A missing completion signal can leave readiness waiting forever.
  • Keep output conversion support aligned with any new action add-on. An action can succeed while its result fails to cross the JSON output boundary.
  • Keep saved state scoped to the runbook and selected top-level input. Reusing state across workflows can cause the wrong actions to be skipped or repeated.
  • Keep artifact-watcher reruns independent from initial readiness. A watcher failure must not change the meaning of the startup plan that already completed.

Important failure modes

TriggerConsequenceGuard
The requested runbook ID is absent and the argument is not a readable runbook fileThe CLI cannot load a workflow and execution stops before actions runCheck surfpool ls and the manifest or pass a valid .tx path
The manifest or selected environment cannot supply the needed runbook inputsContext creation reports diagnostics and the workflow may not execute correctlySelect the intended --env and provide the required --input files
A required startup runbook failsStartup is marked failed; headless operation can terminate instead of exposing a false-ready SurfnetRead the runbook diagnostics and correct the project or action inputs before retrying
A runbook action fails after stateful execution beginsTransient state is saved and later runs may schedule unfinished actions againReview the recovery plan and verify that external actions are safe to repeat
A saved snapshot is out of sync with the current runbookThe CLI can stop for confirmation or report no work when the snapshot is already currentReview displayed changes and use the force option only when ignoring cached state is intended
A runbook output contains a value with no JSON converterThe action can complete but the requested JSON output is incomplete or reports a write warningAdd or select an add-on converter before depending on the output in a script
A watched program artifact changes while startup runbooks are not validThe watcher rerun can fail without fixing the underlying deployment or setup issueTreat watcher output as a rerun signal and inspect the runbook diagnostics

Key files

FileWhy to read it
crates/…/mod.rsDefines the run and ls commands, runbook options, startup runbook flags, and command dispatch.
crates/…/mod.rsShows how the CLI loads runbooks, builds their context, selects execution modes, handles state, and emits outputs.
crates/…/startup.rsExplains how project inspection chooses on-disk, scaffolded, or in-memory startup runbooks and how readiness tracks them.
crates/…/mod.rsShows how the CLI creates a standard deployment package and its environment-specific support files.
crates/…/mod.rsConnects startup runbook progress and lifecycle events to the local Surfnet service and its operator frontends.
crates/…/simnet.rsShows how the terminal UI presents runbook progress and sends lifecycle completion back to the Surfnet.
crates/…/types.rsDefines the shared runbook events, startup commands, and execution status returned to clients.
crates/…/README.mdGives the product-level distinction between operational runbooks and time-based scenario state.