Skip to content
codeband is pre-release. These docs describe its first release, and some of what they describe is still being built.

Step

A step is one piece of work that your pipeline asks codeband for, whose value the run records. There are four kinds: a function step, a shell step, a human step and an agent step. Each step has a step ID, its name and a counter, such as post_summary#1.

codeband moves a run forward by run replay: it runs your pipeline function again from the start, many times per run. Steps are the work that must not happen again on each run replay, such as a webhook call, a program, a person’s answer or an agent’s work. The engine records the value of each step in the run journal once, and every later run replay returns the recorded value. The step ID is how a call in your code finds its record. After this page you know which kind fits which work, where each kind runs, and how codeband counts step IDs.

Kind What it is Runs in Workspace Its recorded value Python SDK
Function step A function of your pipeline code The code server None The function’s return value, or its error @cb.function_step
Shell step A program with an argument list The engine A new one, removed after the program ends The exit code, the end of the output and the changed files cb.shell_step
Human step A typed question to a person The engine, which waits for the answer None The answer and who gave it cb.human_step
Agent step One piece of work by an agent The engine, with a harness A new one for each attempt The step output, the end commit and the cost Agent.do

The code server is the process that loads your factory and runs pipeline code. The engine is the part of the daemon that executes runs and writes the run journal. Architecture shows both.

The pipeline find_todos below looks for TODO lines in each folder of its run input, asks a person whether to post them, and posts them. It uses three kinds of step: the function step post_summary of the example py-factory, which sends a text to a webhook and returns false when none is set, a shell step grep_todos in a loop, and the human step post_todos. Its run works on a target repository with the folders api and web.

import codeband as cb
from py_factory.function_steps import post_summary
@cb.pipeline
def find_todos(folders: list[str]) -> cb.RunResult | None:
"""List the TODO lines of each folder and post them once a person agrees."""
post_summary(f"Looking for TODOs in {', '.join(folders)}")
found = []
for folder in folders:
grep = cb.shell_step(["grep", "-rn", "TODO", folder], name="grep_todos")
if grep.ok:
found.append(grep.output_tail)
if not cb.human_step("post_todos", cb.Question(text=f"Post the TODOs of {len(found)} folders?"), answer=bool):
raise cb.Stop("a person did not want the TODOs posted")
post_summary("\n".join(found))
return None

A run with the input {"folders": ["api", "web"]} takes six invocations. An invocation is one run replay of the pipeline function that the code server does for the engine, which ends at the first step without a record or when the function returns.

  1. The first invocation reaches the first call of post_summary, which gets the ID post_summary#0. It has no record, so the code server runs the function step, and the invocation ends with its value, false. The engine writes the function step and its value to the run journal.
  2. The second invocation gets false for post_summary#0 from the run journal and runs nothing. The loop’s first cb.shell_step call is grep_todos#0, which has no record. The invocation ends and hands the shell step to the engine, which runs grep in a new workspace and records exit code 0 and the output api/auth.go:3:// TODO: check the token.
  3. The third invocation reaches the second call of the same name, grep_todos#1, and the engine runs it the same way.
  4. The fourth invocation ends at the human step post_todos#0. The engine records the question, and the run waits with nothing running. codeband run prints Run 4bbn3bh0p8 waits for an answer to human step post_todos#0.
  5. A person answers true with codeband answer. The engine invokes with the answer, the code server checks it against the answer type bool, and the engine records it with the user who gave it. In the same invocation, the pipeline goes on to the second call of post_summary, post_summary#1, which runs in the code server.
  6. The sixth invocation finds a record for every step, and the pipeline function returns. The run ends with no code change.

The daemon logs the start and the end of each step by its ID:

Daemon log
Nov 24 17:33:20.179 INF Step started run=4bbn3bh0p8 step=post_summary#0
Nov 24 17:33:20.179 INF Step finished run=4bbn3bh0p8 step=post_summary#0
Nov 24 17:33:20.212 INF Step started run=4bbn3bh0p8 step=grep_todos#0
Nov 24 17:33:20.310 INF Step finished run=4bbn3bh0p8 step=grep_todos#0 ok=true timed_out=false cancelled=false exit_code=0
Nov 24 17:33:20.349 INF Step started run=4bbn3bh0p8 step=grep_todos#1
Nov 24 17:33:20.434 INF Step finished run=4bbn3bh0p8 step=grep_todos#1 ok=true timed_out=false cancelled=false exit_code=0
Nov 24 17:33:20.471 INF Step started run=4bbn3bh0p8 step=post_todos#0
Nov 24 17:33:24.070 INF Step finished run=4bbn3bh0p8 step=post_todos#0
Nov 24 17:33:24.095 INF Step started run=4bbn3bh0p8 step=post_summary#1
Nov 24 17:33:24.095 INF Step finished run=4bbn3bh0p8 step=post_summary#1
Nov 24 17:33:24.137 INF Run finished run=4bbn3bh0p8 status=finished reason=""

A step ID is the step’s name, # and a counter. The counter counts the calls of that name in the run, from 0, in the order that the pipeline code makes them. Each name has its own counter, so post_summary#1 is the second call of post_summary, whatever other steps came between. The counter does not depend on the arguments or on the line of code.

Every invocation runs the pipeline function from the start and counts again from 0, so the same call gets the same ID on every run replay. The run journal holds each step under its ID:

Terminal window
jq -r '.stepStarted.stepId // empty' ~/.local/state/codeband/store/runs/4bbn3bh0p8/journal.jsonl
Output
post_summary#0
grep_todos#0
grep_todos#1
post_todos#0
post_summary#1

A function step’s name is the name of its function. A shell step, a human step and an agent take their name as an argument, and every agent step of an agent counts on that agent’s name, such as writer#0.

Rule What breaks it
No two function steps or agents of a factory share a name The code server does not load the factory. No run starts: codeband run prints start run: invoke: factory FACTORY: the factory does not load: NAME is defined twice: …. The runs in progress wait until the factory loads
One name names one kind of step in a run The run fails: failed: definition_error: pipeline code uses the name 'post_summary' for a function step and for a human step: give one of them another name
A recorded step keeps its kind, and a recorded shell step or agent step keeps its start commit The run fails with diverged. Run replay explains it

The ID is the name you use for a step outside your code. codeband answer takes the ID of the human step it answers, and a failed run prints the ID of the step that failed, as in failed: KIND: STEP: MESSAGE. Git refs write the ID as its name and counter, because # is special in shells: the end commit of the agent step writer#0 is under the ref agent_steps/writer/0.

A function step runs in the code server, in the middle of an invocation, with the code server’s environment variables. It has no workspace and cannot see the target repository: an invocation tells the code server the ID of the start commit, but not where the repository is. Use a function step for side effects outside the target repository, such as a webhook or a ticket file, and for a value that changes between run replays, such as the clock. Its arguments and its value are JSON values.

A function step has a timeout, 5 minutes by default. After it, your pipeline code gets the function step’s error. codeband does not stop a function step that times out: it runs on in the background of the code server. Handle a function step that fails or times out shows how pipeline code goes on, tries again or stops after a failed function step.

Shell steps run in the engine, in a workspace

Section titled “Shell steps run in the engine, in a workspace”

A shell step runs one program with an argument list. No shell reads the arguments; name sh -c as the program to use one. The engine runs the program, not the code server, in a new workspace: a checked-out commit of the target repository that the engine makes for this one step and removes after it. By default the workspace holds the run head, which is the end commit of the run’s last agent step that may write, or else the run’s start commit. A call can name another commit.

The workspace is in a new sandbox, the isolated place in which the program runs, such as a container. The shell step gets its sandbox from the sandbox definition that its pipeline names, as the agent steps of the run do, so a test runs with the same tools as the agent that wrote the code.

Nothing reaches the program from the daemon’s environment except what this table lists.

The program gets Value
Working folder The root of the workspace, the folder workspace in the sandbox. A sandbox of the kind host makes it in a new temporary folder
PATH, HOME, USER Those of the sandbox. A sandbox of the kind host gives the daemon’s values
The variables of the [env] table of codeband.toml and the default login variables Read from their sources when the shell step starts
Each variable that the shell step names The daemon’s value. The run records the names, never the values. When the daemon’s environment does not set one, the program does not start, the shell step is not ok, and its output names the variable
GIT_CONFIG_GLOBAL=/dev/null, GIT_CONFIG_NOSYSTEM=1 and other GIT_ variables git in the workspace ignores your git configuration, runs no hooks and signs nothing

The recorded value says whether the program exited with code 0 within its timeout, its exit code, whether it timed out, the last 64 KiB of its standard output and standard error, and the files it changed, at most 1000. The blob store keeps the full output. A program that fails does not raise an error in your pipeline code: the shell step is not ok, and your code decides what follows.

A shell step never commits and never moves the run head. The engine discards every change the program makes. The timeout is 10 minutes by default. After it, or when someone cancels the run, the engine sends SIGTERM to the program and the programs it started, and SIGKILL to those that still run 10 seconds later. When the program ends, the engine also stops the programs it started that still run.

Each shell step starts in a new workspace, so files from an earlier shell step, such as a .venv folder or build output, are not there.

A human step asks a person a typed question. The engine records the question, and the run waits with no process working on it. A person answers in the terminal of codeband run or with codeband answer. The code server checks each answer against the human step’s answer type, and the engine records the first answer it accepts, with the user who gave it.

In a run that a GitHub issue started, people answer in the issue’s thread.

Agent steps run in the engine, with a harness

Section titled “Agent steps run in the engine, with a harness”

An agent step is one piece of work by an agent. The engine runs each attempt of it with a harness, such as Claude Code, in a new sandbox and workspace. Agent step explains step requests, attempts and step outputs.

A name is part of every ID of the step. A run that continues after you rename a step finds no record under the new name, so it does that work again. Rename function steps, shell steps, human steps and agents only when no run that uses them is still going.

Make a function step’s side effect safe to repeat

Section titled “Make a function step’s side effect safe to repeat”

A function step runs at least once. When the code server or the daemon stops after the side effect and before the engine records the value, the function step runs again. Handle a function step that fails or times out makes the function step post_summary of py-factory send a key built from a recorded time, so the webhook drops a repeat.

Work on the target repository in a shell step or an agent step

Section titled “Work on the target repository in a shell step or an agent step”

A function step has no workspace. A program that reads or builds the code of the target repository, such as tests or a linter, belongs in a shell step. Work that changes the code belongs in an agent step, because only an agent step ends with a commit.

  • Run a program in the target repository runs tests in a shell step, reads how they ended and passes a variable by name.
  • Handle a function step that fails or times out sets a function step’s timeout, catches its error and makes its side effect safe to repeat.
  • Run replay explains how recorded steps return their values, and why a run fails with diverged.
  • Stage explains how pipeline code groups its steps into named parts, such as build and review.
  • Human step explains typed questions, how a run waits, and who may answer.
  • Agent step explains the step that runs an agent.
  • The Python SDK reference lists cb.function_step, cb.shell_step, cb.human_step and the naming rules with their error messages.