Skip to main content
A retry block declares a reusable retry policy. It is not a step: it never runs on its own. A ts function or ts effect selects it with retry=<policy-id>, and every call of that declaration uses it. Without one, functions and effects use the default policy below.

Syntax

retry id=pas-write-retry
A declaration selects it by ID on its info line:
Like schemas and secrets, a policy can be declared anywhere in the document, before or after the declarations that use it.

Fields

All four fields are required. Unknown fields are invalid. A duration is a positive whole number and one unit, with no spaces: ms, s, m, h or d, for example 500ms, 2s or 1m.

Default policy

A function or effect without retry= uses:
A selected policy replaces all four values.

Which failures retry

An attempt uses up one of maximum_attempts and is retried, after the backoff wait, when:
  • An effect throws. An uncaught error in an effect is retried, so a brief outage at the other end doesn’t fail the run. Throw new FatalError(...) from the effect’s context when another attempt can’t help, such as a 4xx answer or failed validation. The step then fails at once.
  • The attempt times out. Timeouts are retried under the same count.
  • The run loses contact with an attempt after it started. The code may have run, so the attempt counts. A pure function is simply recomputed. An effect runs again only if maximum_attempts is more than 1.
These never retry:
  • a FatalError;
  • an error thrown by a pure function, because running it again gives the same answer;
  • hitting a fixed compute or memory limit (resource-exhausted);
  • a result that doesn’t match the result schema;
  • cancellation; and
  • the code failing to load.
When the attempts run out, the step fails with local-code-failed, or operation-timeout for a timeout, and the message notes that the policy is exhausted. Some failures happen before any code starts, and the platform knows it. Those are retried separately, on their own limit, and don’t use up maximum_attempts.

Example

The policy administration system deduplicates on Idempotency-Key, so the cancellation can retry safely. The mail vendor has no idempotency protocol, so the printed notice is ordered at most once:
cancel-policy.procedure.md
Both hosts, their paths, header names and both secrets are illustrative. Use each system’s own API and idempotency convention.
With maximum_attempts: 1, the intervals and coefficient still have to be present and valid, but they never take effect.

Retries are not exactly once

A policy with more than one attempt limits how often the code may run. It doesn’t make a write happen once, and it doesn’t make the other system idempotent. A write can reach your system and its answer still be lost; a retry then sends it again.
  • For writes, send operation.idempotencyKey. It is the same for every attempt of the same call. Pass it in the header or field your system uses for idempotency. Plain fetch doesn’t add it for you. Effective API writes made through effective.api.* carry it as Idempotency-Key automatically.
  • No idempotency protocol? Use a natural unique business key, or a policy with maximum_attempts: 1. Leaving out retry= keeps the three-attempt default and can duplicate the write. With one attempt, an unknown outcome fails the step for a person to check, instead of retrying.
  • Some Effective API writes don’t deduplicate the key. Their generated reference says so. An effect that is allowed one of them must select a retry= policy: maximum_attempts: 1, or more attempts when the effect checks the receiving system before it writes again.
Resuming is separate from retrying: when a run resumes, a call that already finished is not run again. Its recorded result is used. See writes to your systems.

Common errors

See also