Skip to content

Harden duplicate-key classification (#92) - #114

Merged
AGiorgetti merged 5 commits into
developfrom
fix/92-duplicate-key-classification
Nov 18, 2026
Merged

AGiorgetti merged 5 commits into
developfrom
fix/92-duplicate-key-classification

Conversation

@AGiorgetti

@AGiorgetti AGiorgetti commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #92.

Prefer MongoDB write categories and command codes over broad exception-message substring matching. Use structured key patterns when available; otherwise match complete index tokens in legacy duplicate-key messages. Preserve checkpoint retries, duplicate commit detection, and stream concurrency handling in both sync and async paths. Add representative response/message regressions and a changelog note. No production dependency or schema change. Approved breaking API cleanup: remove the unused MongoCommitIndexes.CheckpointNumberMMApV1 and CheckpointNumberWiredTiger public constants; migration guidance is in Changelog.md.

Verification

  • Public-constant removal is commit d1ae29e48342f510ad626f25e501ca4aadd80639. No source references remain. Exact-head CI run 44131308641 passed Ubuntu and Windows builds and all seven full-suite jobs, each with 2,092 passed, zero failed and zero skipped: .NET 8/9/10 with Driver 3.0.0 and 3.13.0 on MongoDB 7.0.45, plus .NET 10 / Driver 3.13.0 on MongoDB 9.0.4. No local build/test or .NET Framework 4.7.2 test execution was performed for this head. Earlier results below predate this removal.
    Rebased onto develop after fix: align async read disposal with synchronous reads #115/Align async Mongo exception boundaries with synchronous reads (#108) #116 at head 114a3bbaade5925602ea563c6f140987cc7b7c70.
  • CI run 44118106103 passed both Ubuntu and Windows builds.
  • All seven full-suite jobs passed 2,092 tests each, with zero failures or skips: .NET 8/9/10 with Driver 3.0.0 and 3.13.0 on MongoDB 7.0.45, plus .NET 10 / Driver 3.13.0 on MongoDB 9.0.4.
  • Independent review found no blocking issue; sync/async commit classification remains necessary and the merged read/observer behavior is unchanged.
  • Current head was not tested locally: submodule clone was blocked by a connection reset. .NET Framework 4.7.2 execution was not repeated for this head.
  • Earlier pre-rebase verification included 31 focused tests across eight framework/driver lanes; those historical results are not current-head verification.

Co-authored by Alessandro Giorgetti and Codex (OpenAI).

Co-authored-by: Alessandro Giorgetti <alessandro.giorgetti@live.com>

Co-authored-by: Codex (OpenAI) <codex@openai.com>
@AGiorgetti
AGiorgetti force-pushed the fix/92-duplicate-key-classification branch from 8bcad01 to 114a3bb Compare November 17, 2026 15:46
AGiorgetti and others added 2 commits November 17, 2026 17:06
Co-authored-by: Alessandro Giorgetti <alessandro.giorgetti@live.com>

Co-authored-by: Codex (OpenAI) <codex@openai.com>
Document the approved public API removal and migration guidance.

Co-authored-by: Alessandro Giorgetti <alessandro.giorgetti@live.com>

Co-authored-by: Codex (OpenAI) <codex@openai.com>
@AGiorgetti
AGiorgetti marked this pull request as ready for review November 17, 2026 17:05
@AGiorgetti AGiorgetti self-assigned this Nov 17, 2026
@AGiorgetti
AGiorgetti requested a balanced review from Copilot November 17, 2026 17:05

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.

🟡 Changes recommended

A null MongoWriteException.WriteError can cause a NullReferenceException in both commit paths, masking the original write-concern failure and bypassing storage-error translation.

1 open issue
What changed in this PR

Hardens duplicate-key classification in the MongoDB persistence adapter for #92, preserving distinct checkpoint retry, duplicate-commit, and concurrency handling across synchronous and asynchronous writes.

Changes:

  • Adds a shared classifier that prioritizes driver categories, error codes, and structured key patterns, with an exact-token legacy message fallback.
  • Adds regression cases for structured errors and legacy messages.
  • Removes two obsolete public constants and documents migration guidance.
File Description
src/​NEventStore.Persistence.MongoDB/​MongoPersistenceEngine.cs Uses the shared classifier for synchronous commit failures.
src/​NEventStore.Persistence.MongoDB/​MongoPersistenceEngine.Async.cs Applies matching classification to asynchronous commit failures.
src/​NEventStore.Persistence.MongoDB/​MongoFields.cs Removes obsolete checkpoint message constants.
src/​NEventStore.Persistence.MongoDB/​DuplicateKeyClassifier.cs Implements structured and legacy duplicate-key classification.
src/​NEventStore.Persistence.MongoDB.Tests/​AcceptanceTests/​Issues/​Issue92DuplicateClassification.cs Covers structured responses, legacy formats, and misleading text.
Changelog.md Documents classification changes, constant removal, and migration.

Review effort: Balanced

Preserve write-concern-only failures for storage-error translation instead of dereferencing a missing WriteError. Add regression coverage including misleading duplicate-key message text.

Co-authored-by: Alessandro Giorgetti <alessandro.giorgetti@live.com>

Co-authored-by: Codex (OpenAI) <codex@openai.com>

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.

🟡 Changes recommended

The classifier can mistake an index clause embedded in a duplicate-key value for the checkpoint index, causing both commit paths to retry collisions that changing the checkpoint cannot resolve.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Add conflicting metadata and message cases for duplicate-key classification

src/​NEventStore.Persistence.MongoDB.Tests/​AcceptanceTests/​Issues/​Issue92DuplicateClassification.cs:24

The structured cases all omit index information from the message, so they still pass if message parsing takes precedence or an unknown pattern incorrectly falls back to _id_. Add conflicting metadata/message cases, including an unknown compound pattern containing _id, to protect both commit paths from incorrectly retrying a concurrency failure as a checkpoint collision.

1 resolved since last review

Review effort: Balanced

Bound legacy index parsing to the first duplicate-value delimiter. Cover embedded index clauses and authoritative conflicting key patterns.

Co-authored-by: Alessandro Giorgetti <alessandro.giorgetti@live.com>

Co-authored-by: Codex (OpenAI) <codex@openai.com>

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.

🟢 Approval recommended

There are no active review issues for the duplicate-key classification changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@AGiorgetti AGiorgetti closed this Nov 18, 2026
@AGiorgetti
AGiorgetti deleted the fix/92-duplicate-key-classification branch November 18, 2026 10:32
@AGiorgetti
AGiorgetti restored the fix/92-duplicate-key-classification branch November 18, 2026 10:36
@AGiorgetti AGiorgetti reopened this Nov 18, 2026
@AGiorgetti
AGiorgetti merged commit b794a9e into develop Nov 18, 2026
19 checks passed
@AGiorgetti
AGiorgetti deleted the fix/92-duplicate-key-classification branch November 18, 2026 10:43
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.

[P3] Harden duplicate-key classification against driver message-format changes

2 participants