Skip to content

fix(store): mongo update_data version-CAS must return retryable Ok(None), not Err - #56

Open
b7r6 wants to merge 1 commit into
mainfrom
b7r6/mongo-update-data-upsert-defeats-version-cas
Open

b7r6 wants to merge 1 commit into
mainfrom
b7r6/mongo-update-data-upsert-defeats-version-cas

Conversation

@b7r6

@b7r6 b7r6 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

What and why

Lane A stability fix from the findings catalog (see nativelink-findings-2026-10-05.csv
on the meta/findings-catalog-2026-10-05 branch), rebased onto OSS main
@bf4b3aa855. This fork PR exists to validate the change on CI that is
representative of upstream PR lanes (public read-only cache, same endpoints)
before any upstream submission.

How was this verified?

The branch carries its own regression tests (fails-without where the fix
class allows it — see the branch's test commits). This PR's purpose is the
full representative CI run; green here rehearses the exact checks an
upstream PR would face.

Risk

Fork-internal validation PR; nothing lands anywhere by merging this. The
underlying fix's risk assessment happens at upstream-submission time.

AI assistance

Agent-assisted pipeline (Claude) for rebase and PR mechanics under my
direction; the fix itself carries verification in its tests.

@b7r6
b7r6 force-pushed the b7r6/mongo-update-data-upsert-defeats-version-cas branch 3 times, most recently from ac2ba37 to b651a3d Compare October 8, 2026 15:12
@b7r6
b7r6 force-pushed the b7r6/mongo-update-data-upsert-defeats-version-cas branch from b651a3d to affcbc0 Compare October 14, 2026 17:40
@b7r6
b7r6 force-pushed the b7r6/mongo-update-data-upsert-defeats-version-cas branch from affcbc0 to 5a1125c Compare October 15, 2026 11:19
@b7r6

b7r6 commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

Folded into #55 (same branch now carries both Mongo update fixes), so this one is superseded.

…ne), not Err

ExperimentalMongoStore::update_data used find_one_and_update(...).upsert(true). On a version-CAS conflict (a concurrent writer already bumped the version) the {_id, version} filter matches nothing, so upsert tries to INSERT a doc with the existing _id and MongoDB returns a DuplicateKeyError (E11000), surfaced as Err(Internal). The version-CAS contract (and the Redis backend, which returns Ok(None)) require a conflict to be retryable; instead concurrent updates on a Mongo-backed record spuriously failed. Fix: .upsert(current_version == 0) so only a genuine first-create upserts; a non-matching filter on an existing record now returns Ok(None) (retryable). Adds a deterministic fails-without regression and corrects an existing (ignored) scheduler test that had pinned the buggy Err behavior.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@b7r6
b7r6 force-pushed the b7r6/mongo-update-data-upsert-defeats-version-cas branch from 5a1125c to 11f8389 Compare October 21, 2026 17:39
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.

1 participant