Skip to content

The life of a Run

A Run is one execution of one schematic. This page follows a Run from the moment you type builder execute to the moment files appear on disk, and shows what each stage looks like from the outside. How it works explains the parts involved (SDK, engine, CLI); this page explains the order they act in.

Every output below comes from the published CLI (v0.19.17) and @pbuilder/sdk 0.23.0, except the section on invoked schematics, which comes from CLI v0.20.0, and the one on direct writes, which comes from CLI v0.21.1.

builder execute default:make first resolves the name default:make through the manifest, project-builder.json, to a schematic directory. If the name does not resolve, the command stops there: no runner starts and nothing is written. The error lists the schematics the collection does have.

{"error":{"code":"execute_schematic_not_found","message":"schematic \"nope\" not found in collection \"default\"","suggestions":["boom","hello","make","nets","twice"]}}

The same happens when the flags contradict each other. --dry-run is shorthand for --commit=never, so --dry-run --commit=always is refused before anything runs (invalid_input, exit 2), and so is any --commit value other than never or always.

Once the schematic resolves, the engine starts a runner that loads your factory and calls it with the schematic’s inputs. The factory never touches your project. Each verb (create, remove, rename, and the others) emits an instruction, and the SDK sends those instructions to the engine over a wire. The SDK–engine conversation covers when they are sent. Reading a file also goes through the engine, so a read always sees what the Run has already staged.

The engine serves at most 8 MiB of one file per read (rule E-41), from engine v0.16.0, shipped in CLI v0.24.0. A read of a larger file is refused for that read only: with @pbuilder/sdk 0.24.0 the factory receives a ReadTooLargeError it can catch, and the Run goes on. Uncaught, it fails the factory, as When a factory fails shows, but with its own error code: from CLI v0.26.0 with @pbuilder/sdk 0.26.0 the Run fails with execute_read_ceiling_exceeded instead of engine_native_developer_fault, still with exit code 5. See Files over the read cap.

The engine applies each instruction to the Staging Tree, an in-memory copy of the workspace. Your disk is not involved yet. The engine reduces what the factory did to the net change: a sequence that cancels itself leaves no trace.

This factory creates a file, deletes it, and then creates a second one:

create("tmp/scratch.txt", { template: "x\n", options: {} });
remove("tmp/scratch.txt");
create("kept.txt", { template: "kept\n", options: {} });

The Run reports one operation, and tmp/scratch.txt never exists on disk:

{"result":{"plan":[{"class":"create","path":"kept.txt"}]}}

A rename works the same way. A factory that creates f/two.txt and renames it to three.txt produces a single create of f/three.txt, not a create followed by a rename.

Two writes to a path the Run created leave the last one. A second create of tmp/a.txt in the same Run replaces the first, and the Plan holds one create. This holds across schematics too, as the next section shows.

A factory can run another schematic of the workspace with invoke. The engine starts the child on a runner of its own, against a fork of the parent’s Staging Tree. The parent waits while the child runs. When the child succeeds, its fork joins the parent’s tree; when it fails, the fork is discarded and the parent receives the error, which it can catch. An invoked evaluation runs read-only: its fork is discarded even when it succeeds, and its Findings reach the parent as the invoke’s Result.

Everything still ends in one Plan and one Commit. A Run whose root invokes default:add-route plans both schematics’ files together:

create (2)
create src/pages/about.ts
create src/routes/about.ts
✓ done — 2 create

Netting does not look at which schematic staged what. When the parent creates src/index.ts and then invokes a child that creates it again, the last claim wins: the Plan holds one create src/index.ts with the child’s content. A file that was already in the workspace keeps its protection, in the child as in the parent, as the next sections show.

When the factory returns, the Run is sealed into a Plan: the list of net operations, each with a class (create, copy, copyIn, modify, rename or delete) and a path. The Plan names what would change and carries no file content.

What happens to the Plan depends on the commit mode:

  • Dry Run (--dry-run, or --commit=never) reports the Plan and stops. Nothing is written. The result holds the operations under plan, and a warn_dry_run warning says so.
  • Commit (--commit=always, the default) writes the Plan to disk and reports the operations it applied under changes.
Terminal window
builder execute --dry-run default:make # plan: out/a.txt, out/b.txt; no out/ directory
builder execute default:make # changes: out/a.txt, out/b.txt; both on disk

There is no confirm-then-apply mode. To apply what a Dry Run showed, run the same command again without --dry-run; the second Run reads the disk afresh. With --output=pretty the operations are grouped by class:

dry run: nothing is written to the workspace
create (2)
create f/one.txt
create f/three.txt
✓ done — 2 create

Conflicts surface before anything is written

Section titled “Conflicts surface before anything is written”

The verbs that write to a new path are strict: create rejects a path that already exists unless you pass { force: true }. A Dry Run hits the same rejection as a Commit, because both run your factory against the same tree. After default:make has created out/a.txt, running it again with --dry-run fails:

dry run: nothing is written to the workspace
✗ [ENGINE] sidecar runner exited with code 2
engine_native_developer_fault · factory at schematics/make failed: create failed at out/a.txt: path-collision

A Dry Run therefore catches a collision before anything is written. The fix belongs in the factory: read first and branch, as Error handling describes. For the reason values a rejection can carry, see the AuthoringError reference.

A factory that throws fails the Run, and a failed Run writes nothing. This factory stages a file and then throws:

create("boom/one.txt", { template: "1\n", options: {} });
throw new Error("factory failed on purpose");

The command exits with code 5, the error carries the factory’s message in runner_note, and the workspace has no boom/ directory afterwards:

{"error":{"code":"engine_native_developer_fault","reason":"schematic_developer_fault","runner_note":"factory at schematics/boom failed: factory failed on purpose","log_path":"~/.pbuilder/logs/runner-7596423e1dd1aac3.ndjson"}}

Because everything staged lives in the Staging Tree until the Commit, there is nothing to clean up. The log_path points to the runner’s diagnostic log. The codes, exit codes and envelope are listed in CLI output and errors.

The Plan covers what goes through the verbs. Every runner, an invoked child’s included, starts in its own empty temporary directory, not in the workspace, and the directory is removed when the Run ends. A relative path that a factory writes with Node’s fs lands there: a factory that appended a line to kept.txt this way left the workspace’s kept.txt unchanged.

An absolute path into the workspace still reaches the disk. The same factory, appending to the absolute path of kept.txt, changed the file, and the Run reported ✓ done — no changes. Such a write bypasses the Staging Tree and is not part of the Plan, so a Dry Run does not show it. It still happens in a Dry Run: with --dry-run, the same factory changed kept.txt while the command printed dry run: nothing is written to the workspace. Express every change as a verb. To list what a factory has queued, see Pending directives.

Since the runner starts outside the workspace, the engine passes @pbuilder/sdk 0.22.0 and later the workspace root, and their messages name paths relative to it, as in factory at schematics/boom failed. An older SDK still runs, but its messages name the schematic’s folder through a ../../.. chain that climbs out of the temporary directory.

A factory whose package lies outside the workspace, such as one in an external collection, has no workspace-relative folder. From CLI v0.22.0 the engine hands a generator root its qualified name when the SDK is 0.20.0 or later, and runners from SDK 0.23.0 name such a factory factory <collection:schematic>, never by a path of the machine (rule CA-19).