Skip to content

7.0 fixes: Oracle dead-letter duplicates and scheduling hang, Cosmos DB replay, dead-letter ids under IdAndDestination, test isolation (#6153-#6157) - #6160

Merged
jeremydmiller merged 9 commits into
mainfrom
gh-7-0-unassigned-fixes
Dec 4, 2026

Conversation

@jeremydmiller

@jeremydmiller jeremydmiller commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Closes #6153
Closes #6154
Closes #6155
Closes #6156
Closes #6157
Closes #6158
Closes #6166
Closes #6167

Three more bugs turned up along the way. Each is filed separately and fixed here:

#6155 Oracle: a dead letter that already exists failed the move forever

What was wrong. OracleMessageStore.MoveToDeadLetterStorageAsync had no ORA-00001 handling. When the dead letter already existed, every later attempt failed. That happens after a retried move whose first attempt committed, or when a message comes back and fails again. The receiver then kept rescheduling a message it could never retire.

The change. ORA-00001 on the dead-letter insert now means "already dead lettered", as it does for MessageDatabase. Oracle rolls back only the failed statement, so the inbox delete earlier in the same transaction still commits and the inbox row is retired.

The test. OracleTests.dead_letter_that_already_exists_6155 runs under both IdOnly and IdAndDestination:

  • it dead-letters the same envelope twice, with the inbox row back in between;
  • it retries a move whose first attempt committed.

Before the fix all 4 cases failed with ORA-00001. Now all 4 pass.

#6158 Oracle: under IdAndDestination, a dead-letter move deleted another destination's inbox row

What was wrong. The same method deleted the inbox row with WHERE id = :id. Under IdAndDestination that also deleted the row of the same message received at another destination. That copy is a different message whose handler may not have run yet. This is the same class of bug as #4701.

The change. The delete now matches id and received_at, like DeleteIncomingEnvelopeAsync and MessageDatabase. An envelope with no destination (GH-3166) still matches on its id alone, as before.

The test. I added a shared compliance test, dead_lettering_one_destination_leaves_the_same_id_at_another_destination_alone, which runs only under IdAndDestination. It failed on OracleMessageStore_with_IdAndDestination_Identity before the fix and passes now. It also passes on the other stores.

#6156 Oracle: MoveFromOutgoingToScheduledAsync could wait forever on its own row lock

What was wrong. On ORA-00001, the cleanup deleted the outgoing row on a second connection. The first transaction still held that row's lock from its SELECT ... FOR UPDATE, so the delete waited on the method's own lock.

The change. The duplicate is now caught around the scheduled write. The outgoing row is then deleted and committed in the same transaction, and the second connection is gone.

The test. basic_functionality.move_from_outgoing_to_scheduled_when_the_scheduled_row_already_exists. The scheduled write is a MERGE, which updates a row it can see. So the duplicate only comes from a scheduled row that another transaction inserted and had not yet committed. The test sets up that race with a second connection, checks that the move is waiting, then commits. The move is bounded at 30 seconds so a hang fails the test instead of hanging the suite. Before the fix it timed out after 30 seconds. Now it passes.

#6154 Cosmos DB: replaying dead letters did nothing

What was wrong. ReplayMatchingAsync and EditAndReplayAsync set Replayable = true, but nothing moved a replayable dead letter back into the inbox.

The change. New CosmosDbMessageStore.MoveReplayableDeadLettersToIncomingAsync. It writes each replayable, unarchived dead letter into the inbox the same way the relational MoveReplayableErrorMessagesToIncomingOperation does: incoming, owned by any node, not scheduled, attempts 0. CosmosDbDurabilityAgent runs it at the start of every recovery tick, before the inbox recovery that then runs the message.

The inbox document and the dead letter are in different partitions, so there is no TransactionalBatch:

  • The inbox document is written first and the dead letter deleted second. A failure in between leaves a duplicate, never a loss.
  • The delete is conditional on the dead letter's ETag. A dead letter that was edited again or archived after it was read is left for the next pass.

I added InternalsVisibleTo("CosmosDbTests") so the tests can call the mover directly.

The tests. CosmosDbTests.replaying_dead_letters_6154 covers:

  • the move itself (status, owner, attempts, destination; dead letters that are not replayable stay put);
  • an edited body;
  • an archived dead letter being left alone;
  • end to end through the agent: a message dead-lettered on its first attempt runs again after a replay.

Before the fix the end-to-end test timed out. All 4 pass now.

#6153 RavenDB and Cosmos DB: dead-letter ids under IdAndDestination (backward compatible)

What was wrong. Under IdAndDestination the dead-letter id left out the destination (dlq/{id} on RavenDB, deadletter|{id} on Cosmos DB). When one envelope id was dead-lettered at two destinations, the second dead letter overwrote the first, so one destination's dead letter was lost.

The change. No API change and no data migration.

  • New dead letters under IdAndDestination get an id that includes the destination:
    • RavenDB: dlq/{incoming identity}, that is dlq/{id}/{destination}.
    • Cosmos DB: deadletter|{id}|{destination}, with the destination made safe for a Cosmos id the same way as the inbox identity.
  • IdOnly, and an envelope with no destination, keep the old ids. IdOnly lookups are unchanged: the same load or point read by dlq/{id} / deadletter|{id}.
  • Lookups by envelope id under IdAndDestination find both the old and the new id shapes, so dead letters already stored keep working. This covers DeadLetterEnvelopeByIdAsync, QueryAsync and the bulk operations with MessageIds, and EditAndReplayAsync.
    • RavenDB loads the legacy dlq/{id} plus every dlq/{id}/... document by id prefix (LoadStartingWithAsync). That is answered from the documents, never from a possibly stale index.
    • Cosmos DB queries the dead-letter partition by envelopeId, which every dead letter has always carried.
  • RavenDB's bulk operations (replay, discard, archive, restore) now act on the matched document ids instead of rebuilding dlq/{id} from the envelope id.
  • EditAndReplayAsync edits every destination's dead letter for that id, as the relational stores update every row with the id.

The tests.

  • Shared compliance tests (IdAndDestination only): the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters and replay_and_discard_by_id_reach_the_dead_letter_of_every_destination. Both failed on RavenDB and Cosmos DB before the fix. They pass now, and pass on Oracle, PostgreSQL and SQL Server.
  • RavenDbTests.dead_letter_ids_under_id_and_destination_6153 and CosmosDbTests.dead_letter_ids_under_id_and_destination_6153 pin the backward compatibility:
    • IdOnly keeps the old id;
    • a dead letter with no destination keeps the old id;
    • a dead letter written under the old id is still found, replayed, edited and discarded by id;
    • old and new dead letters for one id are found together (and on Cosmos DB, both are moved back into the inbox).

#6166 SQLite: under IdAndDestination the dead letter table was keyed by id alone

What was wrong. CISqlite failed two of the new shared compliance tests on this PR, deterministically: the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters and replay_and_discard_by_id_reach_the_dead_letter_of_every_destination. The SQLite dead letter table was keyed by id under every identity mode. So the second destination's dead letter for one envelope id hit the primary key. MessageDatabase read that duplicate as "already dead lettered", completed the move and deleted the inbox row, and that dead letter was lost. This is the same loss as #6153.

The change. Under IdAndDestination the key is now (id, received_at), as it is for this store's inbox and for the dead letters of every other relational store. received_at is NOT NULL, because a dead letter without a destination is written with DatabaseConstants.UnknownReceivedAt. IdOnly is unchanged.

The tests.

#6167 SQLite: every migration that rebuilds a table failed under the migration lock

What was wrong. The SQLite migration lock is an open BEGIN EXCLUSIVE transaction on the migrating connection (GH-2666). Weasel.Sqlite applies a change SQLite cannot ALTER, such as a primary key, with SQLite's table rebuild procedure on that same connection. That procedure sets PRAGMAs and opens its own transaction, which failed with cannot start a transaction within a transaction.

So no SQLite migration that needs a rebuild could ever run. On main today, switching an existing database from IdOnly to IdAndDestination fails host startup. Without this fix, #6166's key change would also have broken startup for every existing SQLite IdAndDestination database.

The change. Under the lock, SqliteMessageStore now checks whether the pending migration rebuilds a table. If it does, the store commits the lock and the rebuild runs in its own transaction, which SQLite serialises with every other writer. The base migration reads the schema again before applying anything. Every other migration keeps the exclusive lock.

There is still a window: two processes upgrading one SQLite file at the same moment can both decide to rebuild. MigrateAsync retries once and reads the schema again.

The test. SqliteTests.rebuild_migration_under_the_migration_lock_6167 switches an existing database to IdAndDestination. The inbox gets its (id, received_at) key and keeps its row. Before the fix the same switch failed with the nested-transaction error.

#6157 Test isolation

SQL Server. SqlServerMessageStoreTests shared the receiver schema. A new class fixture, SqlServerMessageStoreSchema, gives it receiver_run_{8 hex}, unique to the run.

  • The schema is dropped when the class finishes.
  • A schema of that shape left behind by a killed run, with nothing created in it for a day, is swept when the class starts.
  • Two concurrent runs of the class on one SQL Server each passed 105/105.
  • I did not reproduce the "before" failure. Running two processes on the shared receiver schema would have broken other sessions' suites on this machine's SQL Server.

PostgreSQL. PostgresqlMessageStore_DQL_expiration now drops its dlq_expiration schema at the start of each test. Before the fix, no_expiration_column_normally failed on this machine's reused container (1 of 2 failed). After it, 2 of 2 passed in two runs in a row. No assertion changed.

What I ran

Apple Silicon Mac, net10.0. Containers: Oracle (gvenzl/oracle-free:23-slim), PostgreSQL on 5433, SQL Server on 1434, embedded RavenDB, and the Cosmos DB vnext emulator through Testcontainers, which runs on arm64.

Run Result
dotnet build wolverine.slnx -c Release -f net10.0 (on the final tree, with main through #6152 and #6159 merged in) 0 errors, 0 warnings
SqliteTests (full, final tree) 634 passed, 2 skipped, 0 failed
MySqlTests (full, before the merge of main) 578/578 passed
*IdAndDestination_Identity* and *dead_letter_move_is_atomic* (#6152) classes, final tree PostgreSQL 110/110, SQL Server 111/111, MySQL 104/104
OracleTests (full) 460/460 passed
RavenDbTests (full) 480/480 passed
CosmosDbTests (full, box quiet) 409/409 passed
SqlServerTests (full) 1030 passed, 2 skipped (existing skips), 0 failed
PostgresqlTests (full) 1295 passed, 2 skipped (existing skips), 0 failed
SqlServerTests.Persistence.SqlServerMessageStore* after the rebase onto #6148 312/312 passed

The first full CosmosDbTests run had 9 failures in agent-timing tests: scheduled_promotion_semantics (2), scheduled_job_compliance (1), durability_recovery_capacity (3), destination_recovery_isolation_5587 (2), and the new end-to-end replay test. That run overlapped the full SQL Server suite on the same machine. All 9 tests passed when rerun on their own (18/18 in those classes), and the full suite then passed 409/409 with the box quiet.

The full Oracle, RavenDB, Cosmos DB, SQL Server and PostgreSQL runs above were on the tree before main (#6148, #6152, #6159) was merged in.

Every suite that runs the shared MessageStoreCompliance has now been run: Oracle, RavenDB, Cosmos DB, SQL Server, PostgreSQL, SQLite and MySQL. PolecatTests, MartenTests and the EF Core suites have no MessageStoreCompliance subclass, so none of the new compliance tests run there.

The branch is updated with a merge of origin/main instead of a rebase, because the repository rules refuse a force push.

🤖 Generated with Claude Code

jeremydmiller and others added 6 commits December 3, 2026 17:08
…he move, which deletes only its own inbox row

MoveToDeadLetterStorageAsync had no ORA-00001 handling, so a dead letter that already existed (a retried
move whose first attempt committed, or a message that came back and failed again) failed the move on
every attempt. A duplicate now means "already dead lettered", as it does for MessageDatabase: Oracle
rolls back only the failed insert, so the delete in the same transaction still commits and the inbox
row is retired.

The delete matched the inbox row on the id alone, so under IdAndDestination it also deleted the row of
the same message at another destination (GH-6158). It now matches id and received_at, like
DeleteIncomingEnvelopeAsync and MessageDatabase, and keeps the id-only match for an envelope with no
destination.

dead_letter_that_already_exists_6155 dead-letters the same envelope twice, and retries a committed
move, under both identity modes: 4 of 4 failed with ORA-00001 before, 4 of 4 pass now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… row in its own transaction on a duplicate

On ORA-00001 the cleanup deleted the outgoing row on a second connection while the move's transaction
still held that row's lock from its SELECT ... FOR UPDATE, so the delete waited on the method's own
lock forever. Oracle rolls back only the failed statement, so the duplicate is now caught around the
scheduled write and the outgoing row is deleted and committed in the same transaction.

The scheduled write is a MERGE, so the duplicate only comes from a scheduled row another transaction
had inserted and not committed. basic_functionality.move_from_outgoing_to_scheduled_when_the_scheduled_row_already_exists
sets that race up with a second connection and bounds the move at 30 seconds: it timed out before,
and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r has its own id

Under MessageIdentity.IdAndDestination the dead letter was stored at dlq/{envelope id}, so the same
envelope id dead lettered at two destinations kept only the second dead letter while both inbox
documents were deleted.

New dead letters under IdAndDestination are stored at dlq/{incoming identity}, which carries the
destination. IdOnly, and an envelope with no destination, keep dlq/{id}. Nothing is migrated: the
lookups by envelope id (DeadLetterEnvelopeByIdAsync, QueryAsync and the bulk operations by MessageIds,
EditAndReplayAsync) load the old dlq/{id} document and, under IdAndDestination only, every
dlq/{id}/... document by id prefix, which RavenDB answers from the documents and never from a stale
index. The bulk operations act on the matched document ids rather than rebuilding an id from the
envelope id.

Shared compliance tests (MessageStoreCompliance, IdAndDestination only):
- the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters
- replay_and_discard_by_id_reach_the_dead_letter_of_every_destination
- dead_lettering_one_destination_leaves_the_same_id_at_another_destination_alone (GH-6158)
The first two failed on RavenDB before; the third failed on Oracle before GH-6158's fix.
RavenDbTests.dead_letter_ids_under_id_and_destination_6153 pins the id shapes and that a dead letter
written under the old id is still found, replayed, edited and discarded by id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… back into the inbox

ReplayMatchingAsync and EditAndReplayAsync marked dead letters replayable, but nothing in
Wolverine.CosmosDb moved a replayable dead letter back into the inbox, so a replay never ran the
message.

CosmosDbMessageStore.MoveReplayableDeadLettersToIncomingAsync writes each replayable, unarchived dead
letter into the inbox as the relational MoveReplayableErrorMessagesToIncomingOperation does (incoming,
owned by any node, not scheduled, no attempts), and the durability agent runs it at the start of every
recovery tick, before the inbox recovery that then runs the message. The inbox document and the dead
letter are in different partitions, so there is no TransactionalBatch: the inbox document is written
first and the dead letter deleted second, so a failure in between leaves a duplicate, never a loss. The
delete is conditional on the dead letter's ETag, so one edited again or archived since it was read is
left for the next pass.

replaying_dead_letters_6154: the move itself, an edited body, an archived dead letter left alone, and
end to end through the agent (a message dead lettered on its first attempt runs again after a replay).
The end-to-end test timed out before; all 4 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ter has its own id

Under MessageIdentity.IdAndDestination the dead letter was stored at deadletter|{envelope id}, and the
move upserts it, so the same envelope id dead lettered at two destinations kept only the second dead
letter while both inbox documents were deleted.

New dead letters under IdAndDestination are stored at deadletter|{id}|{destination}, with the
destination made safe for a Cosmos DB id the same way as the inbox identity. IdOnly, and an envelope
with no destination, keep deadletter|{id}, and IdOnly lookups are the same point reads as before.
Nothing is migrated: under IdAndDestination the lookups by envelope id (DeadLetterEnvelopeByIdAsync,
QueryAsync and the bulk operations by MessageIds, EditAndReplayAsync) query the dead-letter partition
by envelopeId, which every dead letter has always carried, so they find the old and the new id shapes.

Before, the shared compliance tests the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters
and replay_and_discard_by_id_reach_the_dead_letter_of_every_destination failed on Cosmos DB; they pass
now. dead_letter_ids_under_id_and_destination_6153 pins the id shapes and that a dead letter written
under the old id is still found, replayed, edited, discarded and moved back into the inbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…run, and the DQL expiration tests start from no schema

SqlServerMessageStoreTests used the shared receiver schema, so two SqlServerTests processes against
one SQL Server counted each other's rows, got each other's claims and deadlocked on the same tables.
A class fixture (SqlServerMessageStoreSchema) now gives it receiver_run_{8 hex}, unique to the run,
dropped when the class is done; a schema of that shape left by a killed run, with nothing created in
it for a day, is swept on the way in. Two concurrent runs of the class: 105/105 each.

PostgresqlMessageStore_DQL_expiration.no_expiration_column_normally failed on a reused container,
because the dlq_expiration schema and the expires column the other test adds outlived earlier runs.
Each test now drops the schema first. Before: 1 of 2 failed on this machine's reused container; after:
2 of 2, twice in a row. No assertion changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremydmiller jeremydmiller added this to the 7.0 milestone Dec 3, 2026
Copilot AI balanced review requested due to automatic review settings December 3, 2026 23:13

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

jeremydmiller and others added 3 commits December 3, 2026 20:47
…GIN EXCLUSIVE migration lock

The SQLite migration lock is an open BEGIN EXCLUSIVE transaction on the migrating connection (GH-2666).
Weasel.Sqlite applies a change SQLite cannot ALTER, such as a primary key, by SQLite's table rebuild
procedure: it sets PRAGMAs and opens its own transaction on the same connection, and that failed with
"cannot start a transaction within a transaction". No such migration could run. Switching an existing
database from IdOnly to IdAndDestination failed host startup on main.

Under the lock, the store now checks whether the pending migration rebuilds a table. If it does, the
store commits the lock and the rebuild runs in its own transaction, which SQLite serialises with every
other writer. The base migration reads the schema again before applying anything. Every other
migration keeps the exclusive lock.

rebuild_migration_under_the_migration_lock_6167 switches an existing database to IdAndDestination: the
inbox gets its (id, received_at) key and keeps its row. Before the fix the same switch failed with the
nested-transaction error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by (id, received_at)

The SQLite dead letter table was keyed by the id alone under every identity. Under IdAndDestination,
the same envelope id dead lettered at a second destination hit that key. MessageDatabase read the
duplicate as "already dead lettered", completed the move and deleted the inbox row, so that
destination's dead letter was lost. The shared compliance tests from #6153 caught it in CISqlite.

Under IdAndDestination the key is now (id, received_at), as it is for the inbox here and for the dead
letters of every other relational store. received_at is NOT NULL, because a dead letter with no
destination is written with DatabaseConstants.UnknownReceivedAt. IdOnly is unchanged. An existing
table migrates by a table rebuild, which needs GH-6167.

Before the fix, the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters and
replay_and_discard_by_id_reach_the_dead_letter_of_every_destination failed on
SqliteMessageStore_with_IdAndDestination_Identity; both pass now.
dead_letter_key_under_id_and_destination_6166 pins the key under both identities, and that a dead
letter table keyed by id alone migrates with its rows and then keeps a second destination's dead
letter beside the old one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremydmiller
jeremydmiller merged commit 2efca34 into main Dec 4, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants