Fix ancillary store outbox schema for projection side effects (GH-2887)#2888
Merged
Conversation
MartenToWolverineOutbox.CreateBatch built a MessageContext bound to the runtime's default (main) message store, so projection-batch side-effect envelope writes for an ancillary Marten store targeted the MAIN store's schema. On an ancillary store living on a separate physical database (IntegrateWithWolverine(x => x.SchemaName = ...)), those tables do not exist -> 42P01 and the side-effect message is never delivered. Thread the ancillary store's marker type into the outbox (via MartenOverrides.StoreType, overridden in MartenOverrides<T> to typeof(T)) and OverrideStorage to the ancillary store's own message store when set. The main store keeps StoreType => null and the default storage, unchanged. Adds Bug_2887 repro test on a separate physical database with a per-store envelope schema and durable local queues. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 28, 2026
Closed
This was referenced Jun 2, 2026
Merged
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.
Problem
Fixes #2887.
In a modular monolith with a main Marten store plus an ancillary store on a separate physical database, integrated via
IntegrateWithWolverine(x => x.SchemaName = "debtors"), an async multi-stream projection that callsslice.PublishMessage(...)inRaiseSideEffectsfails with:The projection-batch outbox writes its envelopes to
public.wolverine_*(the main store's schema) instead of the ancillary store's configureddebtorsschema. On the ancillary database thosepublictables don't exist, so the batch fails and the side-effect message is never delivered.A shared database masks the bug — the main store's
public.wolverine_*tables happen to exist there, so the wrong-schema write silently succeeds. It only surfaces when the ancillary store is on its own database.Root cause
MartenToWolverineOutbox.CreateBatch(session)builds a freshMessageContext, whoseStoragedefaults toruntime.Storage— the main/default message store (schemapublic).MartenEnvelopeTransactionthen builds schema-qualified envelope SQL from that store and runs it on the projection's (ancillary) session connection.The same outbox class is used for every store and had no idea which store it belonged to. By contrast,
OutboxedSessionFactory<T>correctly callsOverrideStorage(...)to retarget the ancillary store — the projection-batch path never did.Fix
Thread the ancillary store's marker type into the outbox and retarget storage when present:
MartenToWolverineOutboxtakes an optionalType? storeType; when set, callscontext.OverrideStorage(runtime.Stores.FindAncillaryStore(storeType)).MartenOverridesexposesprotected virtual Type? StoreType => null(main store keeps default storage, unchanged);MartenOverrides<T>overrides it totypeof(T).Test
Adds
Bug_2887_ancillary_outbox_schema_on_separate_database— an ancillary store on a separate physical database (bug2887_refs) with a per-store envelope schema (debtors), durable local queues, and an async multi-stream projection that publishes a side effect. Fails with the exact42P01before the fix; passes after.Verification
42P01), passes after.multi_stream_projection_with_side_effects_on_ancillary_store,end_to_end_publish_messages_through_marten_to_wolverine,Bug_2669,Bug_2382ancillary): 11/11 passed.🤖 Generated with Claude Code