Watching your workflows
Expected behaviors
From docs/checks.md at commit 548821a.
Spinto 0.1.0. These docs follow the main branch. Spinto isn't on crates.io yet, so you install it from a clone.
An expected behavior is a rule your application states about its own workflow runs, such as “the welcome pack builds within 10 seconds” or “approval comes before provisioning”. Spinto evaluates each behavior against every run of its workflow and shows the result in the run’s evidence: pass, fail, blocked or not run, with the expected value, the observed value and the records it compared. A behavior’s result sits beside the run’s status and never changes it. A run can be completed while one of its checks fails.
- Declaring a behavior
- Writing the check
- Outcomes
- What the run page and agents see
- Why a failing check never fails the run
- Testing behaviors
- Limits
Declaring a behavior
A behavior names its workflow, a label, and a function from the run to a Verdict. Pass behaviors to the provider with expect:
// src/app.rs
providers.add(
spinto::Spinto::new()
.authorize(SpintoAccess)
.expect(crate::checks::behaviors()),
);
// src/checks.rs
use spinto::checks::{Behavior, Verdict};
use spinto::contracts::{CheckOutcome, Known, RunDetail};
pub fn behaviors() -> [Behavior; 1] {
[Behavior::new(
"customers.onboard",
"build welcome pack finishes within 10 s",
welcome_pack_is_quick,
)]
}
fn welcome_pack_is_quick(run: &RunDetail) -> Verdict {
let expected = "at most 10 s";
let Some(entry) = run.entries.iter().find(|entry| entry.id == "step:build welcome pack") else {
return Verdict::new(CheckOutcome::NotRun, expected, Known::NotYet);
};
let verdict = match &entry.duration_ms {
Known::Value { value } if *value <= 10_000 => {
Verdict::new(CheckOutcome::Pass, expected, Known::value(format!("{value} ms")))
}
Known::Value { value } => {
Verdict::new(CheckOutcome::Fail, expected, Known::value(format!("{value} ms")))
}
Known::NotYet => Verdict::new(CheckOutcome::NotRun, expected, Known::NotYet),
_ => Verdict::new(CheckOutcome::Blocked, expected, Known::unknown("no finish time")),
};
verdict.compared(entry)
}
The workflow name is the one the workflow is registered under, #[workflow(name = "customers.onboard")]. Behaviors for other workflows never run against this workflow’s runs. The label names the behavior on the run page and in its check’s ID, so give each behavior of a workflow its own label.
The onboarding example declares two behaviors in examples/onboarding/src/checks.rs. demo:start builds the welcome pack in 20 seconds by default, so its runs complete while “build welcome pack finishes within 10 s” fails.
Writing the check
A check is a pure function. It gets the run’s RunDetail, the same record the run page shows, and returns a Verdict:
| field | what to put in it |
|---|---|
outcome |
CheckOutcome::Pass, Fail, Blocked or NotRun (see Outcomes) |
expected |
what the behavior expects, in words a reader can compare: at most 10 s, 1 try |
observed |
what the run showed, as a Known<String>: Known::value("20.0 s"), or Known::NotYet, Known::unsupported(reason) and the other states when the run doesn’t show it |
compared |
each record the check read, added with .compared(entry) for an Entry or .compared(&run.run) for the run itself; Spinto takes each record’s ID and provenance (table and key) from it |
Read what the run recorded: its entries, their tries (attempts), times and durations, waits, and attributes. Don’t read run.status, and don’t query the database, call an API or read the clock: Spinto evaluates the check each time it reads the run, inside the request, and the same run must always give the same result. A check that panics fails the request, the way a panicking handler does.
Durations and times are the store’s own columns. A step’s started_at is when its first try started, so a step that retried counts its backoff in its duration.
Outcomes
| outcome | when |
|---|---|
| pass | The run recorded what the behavior needs, and it matches. |
| fail | The run recorded what the behavior needs, and it doesn’t match. |
| blocked | The data the behavior needs wasn’t recorded: tries from before Spinto observed the run, a try a stopped worker cut short (the runtime doesn’t count it), a purged value. |
| not run | The run hasn’t reached what the behavior compares, such as a step it hasn’t run yet or never ran. |
Prefer blocked to pass whenever the records can’t prove the behavior. The example’s “build welcome pack runs exactly once” counts every try of the step, including a try a stopped worker cut short (AttemptOutcome::Interrupted), which the runtime never counts and only Spinto’s observer records. When Spinto didn’t observe the step’s tries, the runtime’s tries = 1 can’t rule out an uncounted try, so the check is blocked, never passed. In a real run whose worker was killed in the middle of the welcome pack, the step ran twice (demo:effects shows two executions), the runtime recorded one try, and the check said blocked.
What the run page and agents see
Each result is an EvidenceCheck in the run’s evidence, after Spinto’s own checks against the store and the runtime:
{
"id": "expectation:build welcome pack finishes within 10 s",
"label": "build welcome pack finishes within 10 s",
"outcome": "fail",
"detail": "Expected at most 10 s; observed 20.0 s. Compared step:build welcome pack (workflow_steps: run_id=01a2351c-b909-7597-8069-1ccadfca9fba, kind=step, name=build welcome pack).",
"source": "derived"
}
idstarts withexpectation:(EXPECTATION_PREFIXinsrc/contracts/checks.rsandresources/js/contracts/checks.ts). Spinto’s own checks never do, so a page or an agent tells a host’s expectation from Spinto’s evidence by the prefix.detailnames the expected value, the observed value, and each compared record with its table and key, orfixture,observed by Spintoorlaravel::workflow::findwhen it has no table.sourceisderived: the result is computed from the records, not read from anywhere.
The run page (GET {SPINTO_PATH}/runs/{run}) and the MCP tool inspect_workflow_run both call spinto::checks::checked, so a person and an agent see the same results for the same run. Results are computed on every read and never stored.
The Verification page (GET {SPINTO_PATH}/verification) lists every workflow with declared behaviors and each behavior’s result on the workflow’s 25 newest finished runs: completed, failed or cancelled. It reads each run as the run page does and evaluates it with the same evaluate, through spinto::checks::results, so a result there always matches the run’s own page, and each result links to that page. The page doesn’t poll; reload it to check again. Older runs aren’t checked there, only on their own pages.
Why a failing check never fails the run
A run’s status is the runtime’s record of what happened: the run completed, failed, or was cancelled. workflow:retry, workflow:recover, the queue and every other tool that reads the store act on that status. An expected behavior is your application’s judgement about the run, made later, by code that may change after the run ended. Mixing the two would let a new check rewrite history, and would make the dashboard disagree with workflow:show.
So the two stay apart, both ways:
- A check never changes the run’s status. Spinto only reads the workflow store, and a result is added to the run’s evidence, never to its status. A run that completed with a failing check shows
completedand the failing check. - The run’s status never changes a check. Spinto evaluates every declared behavior for every run of the workflow, whatever its status, and never reads the status to decide an outcome. A failed run’s welcome pack can still pass its time bound. A check that needs a step the run never reached says not run.
tests/checks.rs and examples/onboarding/tests/checks.rs check both: evaluating leaves the status alone, and the same run with its status changed gives the same results.
Testing behaviors
spinto::checks::evaluate(&behaviors, &detail) returns the checks the run page would show. It does no I/O, so test a behavior against a saved RunDetail:
use spinto::checks::evaluate;
use spinto::contracts::{CheckOutcome, RunDetail};
#[test]
fn a_slow_welcome_pack_fails() {
let run: RunDetail = serde_json::from_str(include_str!("slow-run.json")).unwrap();
let checks = evaluate(&app::checks::behaviors(), &run);
assert_eq!(checks[0].outcome, CheckOutcome::Fail);
}
Save a run’s detail from the run page’s Inertia response (props.detail) or from inspect_workflow_run. A saved or edited detail proves how a check reads, never what the runtime does: check runtime behavior against real runs on a real worker.
Limits
- Behaviors are checked when a run is opened, on its page or through
inspect_workflow_run, and on the Verification page for each workflow’s 25 newest finished runs. Run lists and counts don’t evaluate them. - A behavior sees one run. Rules across runs, such as “no customer is onboarded twice”, aren’t expected behaviors.
- The runtime keeps a step’s try count and last error only. Until Spinto observes a step’s tries, a behavior about individual tries can only be blocked or fail on a count above one.
- A behavior keyed on a step’s name reads “not run” when that name looks like a credential, because the run shows it as
[redacted N].