Repository navigation
GH-4570: let a deduplication claim ride the Polecat transaction - #4573
Merged
Merged
Conversation
The Polecat half of GH-4505. Same guarantee as the Marten implementation -- the claim commits with the handler's work and rolls back with it, so a chain that throws or answers a ProblemDetails never claimed at all and there is no compensating release to order against the response -- but it cannot be the same mechanism. Wolverine's message store on Polecat is built from SqlClientFactory.CreateDataSource(connectionString): the same SQL Server database as the document store, but a different connection pool. Queuing a storage operation onto the session, the way the Marten twin does, would still write on a connection of its own. The claim is enlisted as an ITransactionParticipant instead, which is handed the live connection and transaction -- the pattern StoreIncomingEnvelopeParticipant already uses. The optimistic check does NOT share a round trip here. Polecat.Batching.IBatchedQuery has no AddItem<T>(IQueryHandler<T>) equivalent to enlist a raw-SQL existence check into, so the check runs standalone through the session's AdvancedSql. That is a missed optimisation rather than a correctness gap: the guarantee comes from the claim riding the transaction, not from where the check ran. An optional id still costs no round trip at all. Scoping the commit-race classifier matters more here than on PostgreSQL. SqlException carries no table name, so a blanket Number == 2627 || 2601 test -- which is what PolecatIntegration's existing discard rule does, GH-4565 -- matches a duplicate-key failure from the application's own documents just as readily and would report it to the caller as "already handled". The table name is only in the message text, which is where this looks. Also lifts RefuseDuplicateClaimAtCommitFrame out of Wolverine.Marten into Wolverine.Persistence.Codegen. It was byte-identical apart from the classifier, and Fisher would have made a third copy. Marten now takes it from core. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VDUrBeB4tTnKj4AExCS1nj
jeremydmiller
added a commit
that referenced
this pull request
Sep 24, 2026
The Fisher half of GH-4505, after Marten (#4568) and Polecat (#4573). Same guarantee: the claim commits with the handler's work and rolls back with it, so a chain that throws or answers a ProblemDetails never claimed at all and there is no compensating release to order against the response. On SQLite the mechanism is a correctness requirement rather than a preference. Wolverine's message store here is built from new WolverineSqliteDataSource(store.Options.ConnectionString) -- the same FILE, a different pooled connection. Two connections to one file are two writers, and the second blocks on the first from inside the first one's transaction, which hangs rather than failing. So the claim is enlisted as an ITransactionParticipant, handed the live connection and transaction, and even the optimistic existence check goes through the session's own AdvancedSql rather than the store's data source. Fisher has no database-per-tenant composition, so unlike the Marten and Polecat twins there is no tenancy cardinality to guard. The commit-race classifier is scoped to the deduplication table, sharing the table-name parsing GH-4565 added for the inbox: a bare SQLITE_CONSTRAINT test would match a duplicate key raised by the application's own documents in the same transaction and report it to the caller as "already handled". It is exposed through FisherDeduplicationFailures rather than off SqliteMessageStore directly, because the frame renders the declaring type into generated source and that type is internal -- InternalsVisibleTo does not reach generated code. The commit race IS reachable on SQLite, which #4571 left open. One writer means the two commits serialize on the file lock rather than racing inside a transaction, but both executions still hold a claim the other cannot see, so the loser still trips the primary key. The single-writer model changes when it finds out, not whether it does. Claude-Session: https://claude.ai/code/session_01VDUrBeB4tTnKj4AExCS1nj Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 24, 2026
Closed
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.
Closes #4570. The Polecat half of #4505; Marten shipped in #4568, Fisher is #4571.
Same guarantee, different mechanism
The claim commits with the handler's work and rolls back with it, so a chain that throws or answers a
ProblemDetailsnever claimed at all — no compensating release, no status-code test, nothing to raceagainst the response.
But it could not be the same mechanism. Marten works by queuing an
IStorageOperationonto the session,which is safe because Wolverine's message store there is built from Marten's own
NpgsqlDataSource.Polecat's is not:
Same SQL Server database, different connection pool. So the claim is enlisted as an
ITransactionParticipant, which is handed the liveSqlConnectionandSqlTransaction— the patternStoreIncomingEnvelopeParticipantalready uses for inbox rows.The check does not share a round trip here
Polecat.Batching.IBatchedQueryhas noAddItem<T>(IQueryHandler<T>):IBatchedQuerymembersAddItem·CheckExists·Execute·Load·LoadMany·Query·QueryByPlanCheckExists·EventsExist·Execute·FetchForWritingByTags·QueryByPlanThere is nothing to enlist a raw-SQL existence check into, and
QueryByPlancomposes other batchoperations rather than injecting SQL. So the check runs standalone through the session's
AdvancedSql.That is a missed optimisation, not a correctness gap — the guarantee comes from the claim riding the
transaction, not from where the check ran. An optional id still costs no round trip at all. An upstream
ask for an
AddItemequivalent would close the gap later; it is recorded on #4570.Scoping the classifier matters more on SQL Server
SqlExceptioncarries no table name. A blanketNumber == 2627 || 2601test — which is exactly whatPolecatIntegration's existing discard rule does (#4565, a live bug) — matches a duplicate-key failureraised by the application's own documents just as readily, and would report it to the caller as
"already handled". The table name is only in the message text, which is where
PolecatDeduplicationFailureslooks. The negative control below shows it is there:
The guard is not
CanApplySame as Marten, and worth re-flagging because getting it wrong is silent and total:
CanApplyis true forany chain that merely takes an
IDocumentSession, and a claim enlisted in a transaction nothing commits isnever written — the endpoint reports itself as deduplicated while every replay runs. The guard requires the
CreateDocumentSessionFrameand theDocumentSessionSaveChangespostprocessor.Multi-database tenancy falls through to claim-and-release, and so does an unreadable tenancy — a null
Options.Tenancyis treated as "not single" rather than assumed safe.Also in this commit: the wrapper moves to core
RefuseDuplicateClaimAtCommitFramewas byte-identical to the Marten copy apart from the classifier, andFisher would have made a third. It now lives in
Wolverine.Persistence.Codegen, parameterised by aMethodInfo, and Marten takes it from there. Marten's deduplication tests are unchanged and still pass.Verification
Clean pinned
dotnet build wolverine.slnx -c Release -f net9.0 --no-incremental— 0 errors, 0 warnings.PolecatTests 327/329 (2 skipped), which is the existing baseline plus the 7 new tests. Marten's
deduplication suites re-run after the wrapper refactor: 8/8 and 2/2.
The concurrency test forces the collision with a barrier holding both executions past their check before
either commits — two plain concurrent sends pass against a build with no commit-race handling at all,
because the optimistic check refuses the second whenever the first has already committed. Verified as a
negative control: with
CommitRaceWrappernulled out, the loser escapes as the rawSqlExceptionquotedabove; restored, green. Re-run twice in a row to confirm it is not order-dependent.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VDUrBeB4tTnKj4AExCS1nj