fix(pds): prevent relay desync after failed write#162
Merged
Conversation
`applyWrites` was assigning the new `Repo` to in-memory state before sequencing the firehose event. If anything threw between then and `sequenceCommit` succeeding (e.g. mid-flight failure on an image post), Cloudflare rolled back the SQLite writes but the in-memory `Repo` stayed advanced. The next successful write then emitted a firehose commit whose `since` rev the relay had never seen, and the relay marked the repo desynced — requiring a manual `requestCrawl` to recover. `this.repo` is now only assigned after the sequence + broadcast succeed in all four write paths (`rpcCreateRecord`, `rpcDeleteRecord`, `rpcPutRecord`, `rpcApplyWrites`), and any failure in that window invalidates the in-memory cache so the next access reloads from storage.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
atproto-pds | 159948e | May 10 2026, 02:51 PM |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
requestCrawlre-established it.applyWritesupdatedthis.repoin memory before sequencing the firehose event. If anything threw between the in-memory assignment and a successfulsequenceCommit, Cloudflare rolled back the SQLite writes but JS state stayed advanced. The next successful write then emitted a firehose commit whosesincerev the relay had never seen, so it marked the repo desynced.rpcCreateRecord,rpcDeleteRecord,rpcPutRecord,rpcApplyWrites), only assignthis.repo = updatedRepoaftersequenceCommitandbroadcastCommitsucceed. Wrap the post-applyWritesblock in try/catch that calls a newinvalidateRepoCache()helper on failure (defense in depth — forces a reload from storage on the next access).Test plan
pnpm --filter @getcirrus/pds test:unit— 273 tests passrequestCrawl