---
title: "Failure transparency proof"
description: "Dex has a computer-checked proof that failures add only one thing you can observe: repeated external effects. The proof holds under the conditions in What the proof assumes."
canonical_url: "https://docs.superdurable.io/evaluate-dex/correctness-and-expressiveness/failure-transparency-proof/"
source: "docs/content/correctness-and-expressiveness/failure-transparency-proof.mdx"
locale: "en"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Failure transparency proof

Dex has a computer-checked proof that failures add only one thing you can
observe: repeated external effects. The proof holds under the conditions in
[What the proof assumes](https://docs.superdurable.io/evaluate-dex/correctness-and-expressiveness/failure-transparency-proof.md#what-the-proof-assumes).

- [Download the paper, which covers both proofs (PDF)](https://docs.superdurable.io/papers/dex-expressiveness.pdf)
- [Formal sources on GitHub](https://github.com/superdurable/dex/tree/main/formal)

<a id="the-claim"></a>

## The claim

The proof covers these failures:

- the server crashes and restarts from its durable log;
- a standby server takes over;
- a Step method attempt fails, for example on a Worker error, a timeout, or a
  Worker disconnect, and Dex retries it;
- a Worker keeps running an attempt after Dex gave up on it;
- a Worker result arrives twice, or arrives after its attempt was replaced;
- a client sends the same `StartFlow` request again.

It compares runs with these failures to runs of the same Flow without them,
in three parts.

- **Remove the repeats, and a sequence without failures remains.** Remove
  every repeated external effect from the events of a run with failures so
  far. The rest is a sequence that the Flow can produce without failures, for
  the same requests minus the `StartFlow` retries.
- **Every sequence without failures stays possible.** A run in which no
  failure happens produces it.
- **Fair runs end the same way.** Take the whole event sequence of a fair run
  with failures, and remove the repeats. The result is the whole event
  sequence of a fair run without failures. Both runs complete, both get
  stuck, or both keep running. The reverse direction is proved for requests
  without `StartFlow` retries. A retry advances the server's clock, so it
  can change which timer is due first.

Each repeated effect is an exact copy of an earlier effect of the same Step
method.

[Correctness and Expressiveness](https://docs.superdurable.io/evaluate-dex/correctness-and-expressiveness.md) states
what this proof and the
[Expressiveness proof](https://docs.superdurable.io/evaluate-dex/correctness-and-expressiveness/expressiveness-proof.md)
show together.

<a id="what-it-means-for-you"></a>

## What this means for your code

Make each external call safe to repeat and safe to arrive late. A retry can
run a Step method's external calls again. An older attempt can make a call
late, after a newer attempt made the same call. The proof does not prevent
these repeats.

A common way to do this is an idempotency key that the external system
deduplicates on.
Build it from the Flow run, the Step execution, the method, and the effect.
[Idempotency keys](https://docs.superdurable.io/concepts/step.md#idempotency-keys) says more about keys.

When a client retries a request:

- `StartFlow`: reuse the request ID of the first start. Set the option that
  returns the existing run on both the first start and the retry. Keep the
  default ID reuse policy. The proof covers the retry only if the server's log
  orders it before Dex purges the closed run. See
  [Start options](https://docs.superdurable.io/concepts/flow.md#start-options).
- `PublishToChannel`: a request sent again after a lost response is a second
  request, and it can publish the message twice.
- `StopFlow`: a retry without a run ID can stop a newer run of the same Flow
  ID. Pass the run ID.

<a id="why-repeats-stay-simple"></a>

## Why repeats stay simple

A Step method can run in several attempts. Every attempt reads the same
snapshot: Dex takes it at the first attempt, and every retry reuses it.

The proof assumes that a Step method's effects depend only on what Dex passes
it, and not on which attempt is running. Then every attempt computes the same
external effects, in the same order.

An attempt makes its effects one after another, so each effect first appears
in list order. The first copy can come from any attempt, including an old one
that Dex gave up on. Every later copy is a repeat. No attempt adds a new
effect or changes the order of the first copies.

<a id="what-the-proof-assumes"></a>

## What the proof assumes

The proof holds under these conditions:

- **The scope of the expressiveness proof.** One Flow is started once and
  receives Channel messages. Under failures, RPCs, SubFlows, `StopFlow`, and
  Attribute locks are outside the proof.
- **SYNC methods only.** An **ASYNC** method can lose its start in a server
  crash. It then runs again on a new snapshot, so its effects can differ.
- **Retries continue until an attempt succeeds, and every error is retryable.** Running out of
  retries, or a non-retryable error, fails the Flow. Without failures, a Flow
  fails only when its own code fails it. A long server outage can use up the
  retry time.
- **Failures retry; no failure policy applies.** A policy that proceeds after a failure changes what
  runs next.
- **Code ignores its attempt.** Effects and results do not depend on the
  attempt number, the first attempt time, the last error, or the last
  heartbeat value. Code that resumes from a heartbeat checkpoint is outside the
  proof.
- **Attributes are the ordinary kind, not hard-delete.** Dex reads them again on every attempt.
- **Every attempt command names its task.** The server tags each command of a
  started attempt, such as its result, a heartbeat, or its failure, with the
  task that ran it. Every logged command of this kind carries the tag.
- **The clock only moves forward.** On one server, the clock does not step
  back between checking that a timer is due and stamping the command that
  fires it.
- **Timers fire in order.** Each firing takes the earliest due timers first,
  ordered by fire time, and timers due at the same time in a fixed order. The
  real server has a short window in which it can fire a timer while an
  earlier-due timer still waits. Both proofs leave that window out.
- **One server at a time.** A standby takeover is covered. Several servers
  that own the same Flows at once are not.

The ending part of the claim holds for fair runs. A run is fair when:

- Every request of the outcome word gets its final outcome, in order. The
  outcome word lists the client requests in the order of their final
  outcomes. A request lost before any outcome is not in it.
- The server's clock grows without bound.
- Failures happen only finitely often, and the server comes back after each
  crash.
- A timer that stays armed and due eventually fires.
- A Step method that stays ready to start while the server is up eventually
  starts.
- Every Worker task, including an abandoned one, eventually finishes or is
  dropped.
- Every finished result eventually commits or is ignored.
- Every attempt that a crash interrupted is eventually handled, or cleared by
  a later crash.

<a id="what-it-does-not-say"></a>

## Server time and real time

The proof measures time in the server's stamps. By those stamps, a timer never
fires before its time. A server clock that runs ahead can still fire it early
in real time.

<a id="how-it-was-checked"></a>

## How it was checked

- **A written failure model.** Every failure rule is written down with the
  server code that implements it. Reviewers checked each rule against that
  code.
- **A computer-checked proof.** The proof is written in the Lean proof
  assistant, which checks every step.
- **Tests before the proof.** A fuzzer walked random runs with crashes,
  retries, and late attempts, and checked the argument at every step.
- **Examples and counterexamples.** The proof assistant checks example runs
  with a crash, retries, and a late repeated effect, and applies the proof to
  them. It also checks runs that break an assumption, such as code that reads
  its attempt number, and shows that the claim then fails.
- **Fault tests of the server code.** Outside the proof, a
  [deterministic simulation](https://github.com/superdurable/dex/tree/main/server-zd/crates/dexzd-simulation)
  runs the real server engine against simulated object storage, clocks,
  Workers, and clients. It injects slow and lost storage responses, 5xx
  errors, crashes with writes still in flight, takeovers by a new process
  while the old one still writes, and Workers that hang, fail, or disconnect.
  It then checks that every acknowledged write survives and that no read sees
  uncommitted or stale state. It also covers most of what the failure proof
  leaves out: RPCs, including
  [transactional RPCs](https://docs.superdurable.io/reference/server/data-primitive-semantics.md#transactional-reads-and-writes),
  Attribute locks, child Flows started as SubFlows, StopFlow, and hard-delete
  Attributes. Failure policies and recovery Steps run in its apply-level
  stage, which tests the state machine that applies each command, without the
  engine around it. ASYNC durability is not part of its workload. CI runs it
  nightly.
- **Integration tests.** The
  [server integration tests](https://github.com/superdurable/dex/tree/main/server-zd/integ)
  run real Workers against a real server. These tests cover the features
  outside the proof:

| Feature                             | Integration tests                                  |
| ----------------------------------- | -------------------------------------------------- |
| ASYNC Steps                         | `create_test.go`, `any_command_close_test.go`      |
| RPCs, including transactional RPCs  | `rpc_test.go`                                      |
| Attribute locks                     | `locking_test.go`                                  |
| SubFlows                            | `subflow_test.go`                                  |
| Failure policies and recovery Steps | `wf_state_execute_method_fail_and_proceed_test.go` |
| Heartbeats                          | `pull_worker_test.go`                              |
| Time Travel                         | `reset_by_state_id_test.go`                        |
| StopFlow                            | `wf_stop_test.go`                                  |

## Next

- [Correctness and expressiveness](https://docs.superdurable.io/evaluate-dex/correctness-and-expressiveness.md)
- [Expressiveness proof](https://docs.superdurable.io/evaluate-dex/correctness-and-expressiveness/expressiveness-proof.md)
- [Step guarantees](https://docs.superdurable.io/concepts/step.md#guarantees)
