C.W.K.
Stream
Lesson 02 of 04 · published

The Resumable State Machine

~15 min · firelink, state-machine, resumable, saga

Level 0Cold Ash
0 XP0/32 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"Birth touches the world in stages. Every stage is remembered before the next one starts — so a crash leaves a save point, not a wreck."

Many External Effects, In Order

Birthing a repo isn't one action; it's a chain of real-world effects: prepare a scaffold, create a local Git repo, request a private remote, push the initial commit, publish, update the roster, update the network ledger, update the operation registry, verify. Each of those touches something outside the process — the filesystem, GitHub, ledger files. If any one fails halfway, you must not be left guessing which effects already happened. So Birth runs as a resumable state machine: an ordered set of states, each one persisted the moment it completes, before the next external effect begins.

Persist the Step, Then Take the Next

The discipline is simple and strict: persist every completed step before starting the next external effect. If the remote was created, that fact is durable before the push is attempted. So when the push fails, the run resumes from 'remote created' — it doesn't re-create the remote, doesn't re-init the repo, doesn't double anything. A failure leaves an explicit, resumable run parked at its last good state, and a retry continues from there rather than colliding with its own partial work. Birth is never called complete on partial state, and a normal retry never fights the leftovers of a previous attempt.

Stage, Publish Atomically, Then Verify

Two more safety moves bracket the chain. First, Birth builds the scaffold in a Firelink-owned staging location and only atomically publishes the new directory into place once local preparation fully succeeds — so a half-built shell never appears at the real path. Second, the final step doesn't trust its own bookkeeping: it rebuilds the new member through the FamilyRegistry and FamilyReconciler and confirms it composes correctly before reporting success. The birth isn't done because the steps ran; it's done because the composed, reconciled family actually contains the new member.

For any multi-step operation with external side effects, persist each completed step before the next one starts, and make failure resume from the last good state instead of restarting. A chain that remembers where it got to turns a mid-way crash from 'unknown damage' into 'pick up here' — and the final proof of success is re-deriving the result, not trusting that the steps ran.

Code

Each external step becomes a durable state before the next·bash
# Birth orchestrates real effects. Each completes and is PERSISTED as a
# state before the next external effect starts, so a crash is resumable.

git init cwkNewThing                       # -> state: local-git-created   (persist)
git -C cwkNewThing add -A
git -C cwkNewThing commit -m "scaffold shell"   # scaffold only, no product
gh repo create cwkNewThing --private       # -> state: private-remote-created (persist)
git -C cwkNewThing push -u origin main     # -> state: initial-push-complete  (persist)

# If the push dies HERE, the run is parked at 'private-remote-created'.
# The retry resumes from there: it does NOT re-init the repo or re-create
# the remote. No step is repeated, no partial work is fought.
#
# ...then roster-updated -> network-updated -> registry-updated ->
#    registry-VERIFIED (rebuild via FamilyRegistry+Reconciler) -> complete.

External links

Exercise

Sketch a multi-step operation you've built or used that touches more than one external system (create a user + send a welcome email + provision a workspace, say). List the steps in order. Now imagine a crash after step 2 of 4. Does your design know exactly where it stopped, and can a retry resume without redoing steps 1 and 2? If not, add a persisted state after each step and describe how the retry uses it.
Hint
The failure mode to hunt: a retry that re-runs step 1 (a second user, a second email) because nothing recorded that step 1 already succeeded. The fix is a durable 'completed step N' marker written before step N+1 begins — the same shape as Birth's states.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.