Skip to content

docs(mutators): document tx.retryOn() - #315

Open
arv wants to merge 4 commits into
mainfrom
arv/tx-retry-docs
Open

arv wants to merge 4 commits into
mainfrom
arv/tx-retry-docs

Conversation

@arv

@arv arv commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Documents tx.retryOn(), a new server-transaction API for re-running a mutator after a transient failure. The API hasn't shipped yet, so this should merge once it's in a release.

What

A new Retrying Mutators section in mutators.mdx, after "Dropping Down to Raw SQL", plus a one-line pointer from "Handling Errors". It covers:

  • When retrying helps: losing a race with a concurrent write (40001, 40P01, 23505).
  • An example that registers a predicate with a capped exponential backoff; the re-run sees the winner's row and succeeds.
  • That the predicate also sees errors Postgres raises at COMMIT, which the mutator body can't catch.
  • The rules: server only; register before anything that can fail; covers only the registering run; attempt numbering; backing off by returning a promise and what that holds open; calls add up and the first yes wins; a throwing predicate counts as no; the predicate can't use tx; only database writes roll back; at most 5 runs per push.

@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
zero-docs Ready Ready Preview Oct 6, 2026 3:26pm UTC

Request Review

@arv
arv marked this pull request as ready for review October 6, 2026 15:25
@arv
arv requested review from aboodman and a lite review from Copilot October 6, 2026 15:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Clarify omitted retry contract details, rollback boundaries, and the 40P01 deadlock code.

Review effort: Lite
Findings: 2 Low severity

Open (2)
What changed in this PR

Documents the upcoming server-side tx.retryOn() API for retrying transient mutator failures.

Changes:

  • Adds retry guidance and usage example.
  • Documents backoff, limits, and transaction behavior.
  • Links to the guidance from “Handling Errors.”
File Description
contents/​docs/​mutators.mdx Adds tx.retryOn() documentation and error-handling guidance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


## Retrying Mutators

Some failures, like losing a race with a concurrent write (`40001`, `23505`), go away if the mutator just runs again. Register a predicate with `tx.retryOn()`: if the run fails, including at `COMMIT`, Zero asks it whether to run the mutator again in a fresh transaction.
)
```

Call `tx.retryOn()` at the top of the mutator, before anything that can fail. It's only available on the server, and the predicate runs after the transaction has finished, so it can't use `tx`. Returning a promise lets you back off, but keep delays short since the rest of the push waits for it. Zero runs a mutator at most five times per push, and you should only use this for mutators that are safe to run more than once.

This branch was successfully deployed

1 active deployment
Preview — c2e71b9a Deployed Oct 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants