Skip to content

[MongoDB Storage V3] Force create new replication stream if old one is invalidated - #755

Merged
rkistner merged 16 commits into
mainfrom
fix-restarting-replication-stream
Aug 20, 2026
Merged

[MongoDB Storage V3] Force create new replication stream if old one is invalidated#755
rkistner merged 16 commits into
mainfrom
fix-restarting-replication-stream

Conversation

@rkistner

@rkistner rkistner commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

When a replication stream is invalidated, for example due to a lost Postgres replication slot, or a MongoDB resume token falling outside the oplog window, we call restartReplication to start again from scratch. The implementation works by creating a copy of the current sync config.

The issue is that with incremental reprocessing on MongoDB storage v3, this is effectively a no-op. The fix is simple: Force creating a new replication stream, since there is no way we can recover within the existing replication stream. Unfortunately, there is no way to make incremental reprocessing work for us here.

The same applies to the two /process APIs., used by the dashboard "Defragment" action. In the future, we can investigate other ways to achieve the defragmenting goals.

Additional fixes

The comment here highlighted a class of issues, some existing before this PR: When we have one replication stream with both PROCESSING and ACTIVE sync configs, we must not update both sync configs to ERRORED. ERRORED is specifically used to keep serving the last ACTIVE stream to clients until we have a new one, so we should not have multiple.

This refactors the process both for restartReplication and for updateSyncRules to correctly handle that case, and additionally use transactions to be safe against concurrent modifications.

This changed the PR from a single forceNewReplicationStream flag to a much larger refactor.

Not many of the existing code issues could be reached directly, due to the original bug here "hiding" those issues. But these became directly apparent once we forced creating a new stream, which would then not correctly stop the existing ones in many cases.

AI Usage

Issue detected by Codex. Fix implemented by Codex gpt-5.6. Checked manually and using Claude Opus 5.

@changeset-bot

changeset-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ddd04e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-module-mongodb-storage Patch
@powersync/service-core Patch
@powersync/service-schema Patch
@powersync/service-module-convex Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mssql Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres Patch
@powersync/service-image Patch
@powersync/service-module-core Patch
@powersync/service-module-postgres-storage Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rkistner
rkistner marked this pull request as draft August 17, 2026 13:16

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15bbefa17e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .changeset/orange-loops-laugh.md Outdated
Comment thread modules/module-mongodb-storage/src/storage/MongoBucketStorage.ts Outdated
@rkistner
rkistner force-pushed the fix-restarting-replication-stream branch from 15bbefa to 3829de4 Compare August 17, 2026 13:22
@rkistner
rkistner marked this pull request as ready for review August 18, 2026 07:52

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85ee728925

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread modules/module-mongodb-storage/src/storage/MongoBucketStorage.ts Outdated
@rkistner
rkistner marked this pull request as draft August 18, 2026 08:36
@rkistner
rkistner marked this pull request as ready for review August 18, 2026 09:56
@stevensJourney
stevensJourney self-requested a review August 19, 2026 12:00

@stevensJourney stevensJourney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The changes look solid and well explained to me. I could not think of any potential issues from this.

@rkistner
rkistner merged commit cc121b3 into main Aug 20, 2026
77 of 78 checks passed
@rkistner
rkistner deleted the fix-restarting-replication-stream branch August 20, 2026 07:47
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