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
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 withoutretry= uses:
Which failures retry
An attempt uses up one ofmaximum_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 a4xxanswer 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_attemptsis more than1.
- 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.
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 onIdempotency-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.
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. Plainfetchdoesn’t add it for you. Effective API writes made througheffective.api.*carry it asIdempotency-Keyautomatically. - No idempotency protocol? Use a natural unique business key, or a policy with
maximum_attempts: 1. Leaving outretry=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.