Guarantees
This page states what Steady promises, what it does not, and why. The rules here are exercised by
the tests in src/, against the memory store and, with STEADY_TEST_DATABASE_URL set, a real
Postgres.
Steps: exactly-once results, at-least-once bodies
“Exactly once” in Steady means: each step position of a run gets exactly one recorded result, and once it is recorded, the flow always sees that result. It does not mean the body runs once.
A step goes through three moments: the body starts, the body finishes, the result is recorded. The record is a single atomic statement that appends the journal row and advances the run’s cursor together, and only the current lease holder can make it.
| The process dies… | On resume |
|---|---|
| before the body starts | the body runs (first time) |
| while the body runs | the body runs again |
| after the body finished, before the result was recorded | the body runs again |
| after the result was recorded | the recorded result is returned; the body does not run |
So a step body is executed at least once, and more than once only when the process dies (or
loses its lease) during that step. Every such run of the body is an attempt of the step’s retry
policy (see Retries), so a step whose body keeps crashing the runner stops after
maxAttempts instead of running forever. Write bodies to be idempotent:
- Pass an idempotency key to the API you call (
stripe.charges.create(..., { idempotencyKey })), for example`${f.runId}:charge`. - Make writes upserts keyed by something stable.
- Check before acting when the external system lets you (“is the email already sent for this id?”).
The journal never has two completed rows for one position, even when two runners race: the record is conditional on the lease owner and on the expected cursor.
Determinism between steps
On every resume the flow function runs again from the top and replays the journal. Code outside
f.* calls therefore runs many times. It must make the same f.* calls in the same order given
the same input and recorded results.
Safe between steps: computing on the input and on step results, if/for over them, building
strings. Not safe between steps: Date.now(), Math.random(), crypto.randomUUID(), reading a
database or an API, reading environment variables that may change. Put those inside a step and use
its recorded result.
If the code changes so that a recorded position no longer matches, the run fails with
ReplayMismatchError (for example the journal recorded "render" but the flow called "send").
The same happens when the flow returns before replaying every recorded position. Steady never
reuses a result for a different step. A renamed step is a new step: deploy renames only when no
run is in flight past that point, or keep the old name.
Retries
A step that throws is retried by its policy (default: 3 attempts in total, 1 s backoff doubling up
to 5 minutes, no jitter). Between attempts the run is parked as pending with a wake time, so the
next attempt happens on the first tick at or after now + backoff. With a one-minute tick, any
backoff under a minute effectively means “next tick”.
Every attempt counts, including the ones that never report back. Before a step body runs,
Steady records the attempt number on the run (attempts) in a fenced write. If the body never
finishes (the process died, for example at a serverless maxDuration, or the lease was lost), or
its result cannot be recorded, the next runner that resumes the run sees that the attempt was
used. When the attempt that never reported back was the last one allowed, the body does not run
again: the step fails with “Attempt N of step … did not finish” like any exhausted step.
An attempt can also be used up without the body running at all: if the write that records the
attempt commits but its response is lost (a dropped connection, a timeout), the runner cannot tell
that it committed and stops before the body, and the next runner sees the attempt as used. With
maxAttempts: 1 such a step then fails with “did not finish” although its body never ran. Keep
maxAttempts at 2 or more for steps with side effects (the default is 3); the step is then at most
N attempts, and a lost response costs one of them, not the step.
When attempts are exhausted, or nonRetryable(error) returns true, a failed journal entry is
recorded and StepFailedError is thrown into the flow. If the flow catches it, the flow continues,
and the failure replays identically on later resumes. If not, the run ends failed with the error
text (a dead letter). retryNow(runId) re-opens a failed run at the failed step with fresh
attempts; earlier steps are not run again.
A result that is not JSON-serializable, larger than 64 KB, or that contains a NUL character
(\u0000, which Postgres jsonb cannot store) fails the step immediately without retry (retrying
would produce the same result). NUL characters are removed from stored error texts and log lines.
A write the database refuses as data (SQLSTATE class 22, data exception) fails the run instead of
being treated as an outage, since the same write would be refused again. A stored value that cannot
be decrypted (DecryptionError) affects only its run: by default (onDecryptionError: "retry")
the run is released for 5 minutes with its attempts untouched and fails after 24 hours of failed
decryption; with "fail" it fails at once.
Leases and concurrency
- A claim leases a run to one runner (
lease_owner,lease_until), inside one statement usingFOR UPDATE SKIP LOCKED. Two concurrent claims never receive the same run. - Every write by a runner is conditional on
lease_owner = me AND lease_until > now. A runner that lost its lease (it was paused, its heartbeat failed, the lease expired and another runner took the run) cannot record anything; its tick reports the run aslost. - While a run executes, a heartbeat extends the lease every
leaseMs / 3(never more often than once a second). A step body that blocks the event loop longer thanleaseMscan lose its lease. - A dead runner’s lease expires after at most
leaseMs; the next tick releases it and another runner resumes the run from the journal. - Lease times are computed and checked with the runner’s clock (
createSteady({ clock }), default the system clock), not the database clock. Keep runner clocks in sync (NTP).
Idempotent start
start(flow, input, { key }) inserts with ON CONFLICT DO NOTHING on a unique index over
(tenant, flow, key) and returns the existing run when there is one, untouched, with
created: false. Fifty concurrent starts with the same key create one run. Without a key, every
call creates a new run.
Signals and timeouts
- A signal is stored, then the target run is marked due if it waits for that name. Nothing is
executed by
signal()itself. waitForSignalconsumes the oldest eligible unconsumed signal with that name. Signals sent before the wait are buffered; consuming one is part of the same atomic record as the journal entry, so a signal is consumed once.- Deadline rule. A wait with a timeout only accepts signals created at or before its deadline
(
createdAtis the sender’s clock). If the runner is down and the tick is late, a signal that is stored and created before the deadline still wins when the tick runs, and a signal created after it does not. - Late-signal rule. When a wait times out, it has decided: Steady records the deadline for
that signal name and flags every signal of that name still unconsumed as
late, whatever itscreatedAtsays. That includes a signal stamped before the deadline whose insert landed after the runner looked (its sender computed the time earlier), and any signal that arrives later. Late signals stay unconsumed and visible inhistory(). A later wait of the same name ignores them unless it passesacceptLate: true; signals sent after that later wait started are accepted normally. - A run that waits for a signal is due as soon as an unconsumed, not late signal of that name is stored, even when its wake-up was missed (a signal that committed while the run was parking and a runner that died before it looked again): the claim checks for such signals itself.
- A run holds at most 1,000 unconsumed signals. The next
signal()throwsLimitExceededErrorand stores nothing.
Example: an intro meeting waits for joined with a 20-minute timeout, gets null, marks a
no-show, sleeps two days and waits for joined again. A joined that arrived 25 minutes after
the first invite is late; it does not answer the second wait. A joined sent during the second
wait does.
Sleep
A sleep records its wake time once. On replay, the recorded wake time is used, so a sleep is never extended by a resume. The run continues on the first tick at or after the wake time.
Schedules, outages and DST
- A due schedule starts one run per firing, keyed
schedule:<key>:<firing ISO time>. Two runners firing the same slot, or a crash between starting the run and advancing the schedule, still produce one run. - No catch-up storm. After an outage the schedule fires once, and its next firing is computed
from now. Three hours of a
*/15schedule missed means one run on recovery, not twelve. - Re-registering a schedule with an unchanged cron and zone keeps its next firing time.
- Times are evaluated in the schedule’s IANA zone. A wall time that does not exist (the spring
forward gap) fires at the same distance after the gap: 02:30 in a 02:00 to 03:00 gap fires at
03:30. A wall time that occurs twice (fall back) fires once, at its first occurrence, so a
*/30schedule skips the repeated hour.
Cancellation
cancel(runId) flips a pending, sleeping, waiting or running run to cancelled at once. A runner
that is executing it is refused at its next write and reports cancelled. A step body that was in
flight may already have had its side effect; its result is discarded. Cancelled runs are never
resumed.
Payloads and caps
Sizes are UTF-8 bytes of the JSON text. Oversize data is rejected with PayloadTooLargeError;
nothing is stored and nothing is silently truncated. Inputs, signal payloads and schedule inputs
with a NUL character are refused with ValidationError.
| What | Limit |
|---|---|
| Run input, schedule input | 64 KB |
| Step result, flow output | 64 KB |
| Signal payload | 16 KB |
| Log line | 1 KB |
| Stored error text | 1 KB (cut with a ...[truncated N bytes] marker; never a stack trace) |
| Operations (steps, sleeps, waits, once) per run | 10,000 (the next one fails the run) |
| Log lines per run | 10,000 (the next one fails the run, even if the flow catches errors) |
| Unconsumed signals per run | 1,000 (the next signal() is refused) |
history() and onEvent summarize values over 8 KB as { $truncated: true, bytes, preview }.
Stored values are never changed by summarizing.
What Steady does not guarantee
- That a step body runs only once. See above: make bodies idempotent.
- Timing finer than your tick interval. A sleep of 10 seconds with a one-minute tick wakes up to a minute later.
- Progress without a tick. If nothing calls
tick(), nothing runs: no sleep ends, no schedule fires, no retry happens. - Ordering between runs. Due runs are claimed oldest due time first, but with several workers and runners, runs execute in parallel.
- Safety of code you change under live runs, beyond detecting a mismatch. There is no versioning.