Security and recovery
Recovery verification
From docs/verification/recovery.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.
Spinto claims to show what the workflow runtime recorded when a worker died, a queue lost a job, or a run sat waiting with nobody to advance it. These scripts make those things happen to real runs, with real queue workers and a real Postgres store, and keep a snapshot of the rows at every stage, so the claim can be checked against evidence rather than taken on trust.
Laravel for Rust workflows run their steps at least once. A step that a worker was running when it died runs again, so its side effect can happen twice. Nothing here shows exactly-once execution, and Spinto never claims it.
- Running the scripts
- The scenarios
- Evidence and verdicts
- What the runs showed
- What Spinto showed
- What this means for Spinto
Running the scripts
The scripts drive the example application in examples/onboarding. Migrate its database first; the scripts read DATABASE_URL from the environment, or from the example’s .env:
cd examples/onboarding && cargo run -- migrate && cd ../..
scripts/verify/worker-interruption.sh /path/to/evidence/worker-interruption
scripts/verify/recovery-suite.sh /path/to/evidence/recovery-suite
scripts/verify/recovery-suite.sh /path/to/evidence/recovery-suite stranded-recovered # one scenario
Keep the evidence directory outside the repository. Each script builds the example with cargo build, or uses SPINTO_VERIFY_BIN if you set it, and records the binary’s hash, the commit, and the database it ran against. Every wait has a time limit, and every worker a script starts is stopped when it exits, even after a failure or Ctrl-C. A run of the whole suite takes about three minutes, most of it the minute a killed worker’s job takes to be reclaimed.
The scripts change the example’s database only through the application: demo:start, demo:approve, demo:reinstate, workflow:recover, workflow:retry, and the workers. The one exception is the stranded-run scenario, which deletes the run’s rows from the jobs table to stand in for a lost queue.
The scenarios
worker-interruption.sh runs one long scenario: a run that fails provisioning twice on purpose, then has its worker killed with SIGKILL while it builds the welcome pack. recovery-suite.sh runs five shorter ones:
| Scenario | What happens | What must be true |
|---|---|---|
killed-mid-step |
A worker is killed with SIGKILL 2 seconds into a 20-second step. A second worker is started at once |
The step wasn’t recorded as finished. The second worker runs it again, from the start, and the run completes. The step’s side effect ran more times than the store’s tries for it. The steps before and after it ran once |
stopped-during-sleep |
The worker is stopped with SIGTERM while the run sleeps for 15 seconds. A worker is started again 5 seconds after the sleep ended |
Nothing advanced the run while no worker ran; its wake-up job was due and still queued. The new worker completes the run, and the step after the sleep runs once |
stranded-recovered |
While the run sleeps, its queued jobs are deleted. A worker keeps running past the sleep’s end | The run stays waiting: a worker can’t advance a run it has no job for. workflow:recover wakes it, and it completes with the step after the sleep run once |
approved-offline |
The worker is stopped while the run waits for approval, and the approval is delivered with no worker running | The run doesn’t advance, and the approval is a due job in the queue. A new worker processes it, provisioning runs once, and the run completes |
retried-after-fatal |
The customer is suspended, so provisioning fails with workflow::fatal. The customer is reinstated and the run retried with workflow:retry |
The fatal error wasn’t retried, and the step is out of tries. After workflow:retry only the failed step runs again; the steps before it keep their recorded results. The run completes |
Evidence and verdicts
Each scenario writes a directory named after it:
| File | Contents |
|---|---|
NN-<stage>.jsonl |
The run’s row, its steps, its queued jobs and its side effects, as JSON lines, taken at that stage |
reader/NN-<stage>.* |
At the same moment: what Spinto’s reader returned (.json), the rows and workflow:show --json it was compared with, and the result (.compare.txt) |
checks.txt |
Each expectation, ok or FAIL, and the side-effect and tries counts |
verdict.txt |
One line: VERDICT <scenario> PASS|FAIL run=<id> reader=<match|mismatch|blocked> |
workflow-show.txt, workflow-show.json |
The runtime’s own view of the finished run |
side-effects.txt |
Every execution of every step’s external work, with its attempt number |
worker-*.log, commands.log |
The workers’ and commands’ output |
The evidence directory also gets timeline.log, every event with a UTC timestamp, and verdicts.txt, every verdict line followed by SUITE PASS n/n or SUITE FAIL n/n. The script exits non-zero when any scenario fails.
At every snapshot, the scripts also run demo:reader <run>, which prints Reader::run as spinto.v1 JSON, the way the reader’s own PostgreSQL test drives it. The comparison, scripts/verify/compare_reader.py, checks:
- the run’s status against its row and against
workflow:show --json - every entry’s status, tries and timeout against the rows and
workflow:show - that none of the reader’s own evidence checks failed
It also records what Spinto would show at that moment: the run’s activity, the graph’s frontier and the current entry. A worker keeps running between the reads, so a disagreement is read again twice before it counts. A mismatch at any stage fails the scenario. While the reader can’t read, the comparison is recorded as blocked and doesn’t fail it.
What the runs showed
All runs were on Postgres with the database queue:
| Run | Result |
|---|---|
Before the reader existed: the suite and worker-interruption.sh |
SUITE PASS 5/5 and PASS. Reader comparison blocked |
With the reader: worker-interruption.sh |
PASS, reader match at all 6 stages |
| With the reader: the suite | SUITE FAIL 4/5. stranded-recovered stopped early; the other four passed with the reader matching at every stage |
stranded-recovered alone, twice |
Once FAIL, once PASS with the reader matching |
| The whole suite again | SUITE PASS 5/5, reader match at every stage |
The two failures were a queue worker standing still. Each time, a job was due and unreserved in jobs while the scenario’s only worker was alive and idle, and the worker didn’t take it for the 60 seconds the scenario allows. The first time it was a new run’s first job; the second, the job workflow:recover had just queued. Both times a worker started afterwards took the job within milliseconds, nothing in the store changed during the wait, and the worker logged no errors. Checked right after each stall, no other worker was using the database. The cause isn’t known yet. It isn’t Spinto, which only reads, and it doesn’t change what the passing runs show. The scripts now record the workers, the database’s sessions and every queued job when a wait times out (stall-*.txt in the scenario’s directory), so the next occurrence carries its own diagnosis.
What the rows showed:
- A killed step leaves no row. Right after the
SIGKILL, the run wasrunningwithleased_untilabout a minute ahead, and the step being run had no row inworkflow_stepsat all. The queue job was reserved with one attempt. Nothing in the store said a step was in progress, or which one. - The rerun hides the first execution. About 60 seconds later the second worker reclaimed the job and ran the step from the start. Both executions saw attempt
1, and the finished step’s row hastries = 1and the rerun’sstarted_at. The side-effect table has two rows for the step. The store has one. - A sleep with no worker just waits. The run stayed
waitingpast its wake time with its wake-up job due, and completed within a second of a worker starting. - A lost wake-up strands a run silently. With its jobs deleted, the run stayed
waiting, with awake_atin the past, while a healthy worker ran.workflow:recoverreported1 workflow run woken.and the run completed. The example schedulesworkflow:recoverevery five minutes, so in a running application a stranded run waits at most that long. - A resume is a queued job. An approval delivered with no worker running was stored, and queued as a due job. The run advanced only when a worker started.
workflow:retryreruns from the failed step. The steps before it kept their results and didn’t run again.- A run’s
wake_atisn’t always its next wake-up. After the approval, while the run wasrunning, its row still held the approval wait’s seven-day timeout. The timeout’s job stays queued until it fires and finds the run gone past it.
What Spinto showed
Once the reader existed, every snapshot also recorded what Spinto made of the run, and it agreed with the rows and with workflow:show at every stage of every scenario that ran to the end. Its own runtime-agreement and schema checks passed each time. Agreeing with the store isn’t the same as telling the whole story, though:
| Moment | Spinto showed | What was really happening |
|---|---|---|
A worker was killed inside build welcome pack |
running, at provision workspace |
The step being run has no row until it finishes, so the current entry is the last one with a row |
| The sleep ended with no worker running | sleeping, at cooling-off period |
The sleep was over; the run was waiting for any worker to pick up its due job |
| The wake-up job was lost, 10 seconds after the sleep ended | sleeping, at cooling-off period |
The run was stranded and would stay so until workflow:recover ran |
| The approval was delivered with no worker running | awaitingResume, at the approval wait |
The decision was stored; the run was waiting for a worker, not for a person |
What this means for Spinto
- Spinto must not present
triesas the number of times a step ran. It is the number of tries the runtime recorded, and a killed worker’s try isn’t recorded. - A
runningrun’s current entry is the last entry that has a row, not the step a worker is running. Spinto should say that the step after it is in progress, or may be, rather than point at the finished one. - A
runningrun whoseleased_untilhas passed has a worker that died or stalled. Spinto can say so, and say that the step it was running will start again from the beginning when the job is reclaimed. - A
waitingrun whosewake_athas passed is overdue, whatever it is waiting on. Spinto should show it as overdue rather than as sleeping. From the workflow tables alone, Spinto can’t tell a lost job from a late one. Only with the database queue could it check thejobstable for the run’s job. - A wait whose value has been delivered isn’t waiting for a person any more.
workflow_waits.resumed_atsays so, and Spinto should show the run as waiting for a worker. wake_atmeans the next wake-up only while a run iswaitingorpending.