Skip to content

Resolve tenant EF consumer contexts in delivery scopes - #408

Merged
thomhurst merged 1 commit into
mainfrom
issue-403-scoped-tenant-consumer
Nov 10, 2026
Merged

thomhurst merged 1 commit into
mainfrom
issue-403-scoped-tenant-consumer

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

EF consumers whose native scoped DbContext factory requires an authorized tenant currently fail during startup composition, before an incoming tenant exists. With AddRelayerTenancy, compose without resolving a startup context and validate the selected context before each delivery/retry transaction instead. Fixed-store consumers retain startup validation.

The existing EF transaction and execution-strategy boundaries now read scope-specific inbox/outbox settings, authorize through application-owned native factories after header restoration, and validate retry/verification scopes. The existing immutable outbox configuration uses EF native options metadata so validation avoids enumerating potentially lazy interceptor sequences. No tenant cache or resolver facade is introduced.

Closes #403

Part of #38. Durable tenant/store/header metadata binding remains #404; native catalog dispatch and its shared connection budget remain #405. Saga model startup validation remains documented separately.

Native/existing reuse: EF Core 10.0.14 native scoped AddDbContext options callbacks and IDbContextOptionsExtension; Npgsql EF 10.0.3 NpgsqlDataSource configuration and native execution strategies; Relayer tenant restoration, consumer transaction/inbox boundary, outbox interceptors and retry/verification scopes. No native capability is duplicated. Inspected pinned source: EF scoped registration, EF interceptor collections, Npgsql strategy factory.

Validation: Release solution build; all 296 PostgreSQL tests (including native retries and three tenant databases/schemas); npm ci and website build; all 8 EF consumer benchmark Dry cases. Dry is execution coverage, not steady-state performance evidence. Extended the existing MemoryDiagnoser benchmark with tenancy on/off alongside native retries/isolation; added performance because validation and strategy selection now occur per tenant delivery. Native scoped configuration construction remains scoped; validation adds native option lookups and capability branches, without a per-attempt iterator, capturing callback or tenant cache.

Website reference/guide, roadmap/home status, design §6.6 and D45 reflect the implemented boundary. The existing five low-severity npm audit findings match #101; dependency manifests are unchanged.

Validation evidence archived at /Users/tom/git/Relayer-evidence/pr-408/3bb5beae030d53f4283129ae83f0008a1de25f75/ with SHA-256 inventory verified against original logs. Includes reports, benchmark inputs/results, pinned source captures and final compiled binaries. Retained while the PR is open.

@thomhurst thomhurst added the performance Run the advisory benchmark regression gate on this PR label Nov 10, 2026
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f3225f8-36f3-4de5-affd-0405c718dd60
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thomhurst

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T03:24:34.096218Z 3bb5bea Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Review of PR 408

I read the diff against AGENTS.md and checked the tenancy probe against the composition code.

Correctness

  • services.GetService<TenantContext>() in Create is safe. ConsumePipelineBuilder composes inside a scope, and TenantContext is scoped and returned to its pool on scope disposal.
  • The scoped path still validates provider, pooling and outbox options before each transaction. It also re-validates inbox and outbox capabilities on every retry and verification scope. The reasoning there is sound.
  • Moving outbox discovery from enumerating the interceptors to FindExtension<OutboxConfiguration> removes a per-attempt iterator allocation. ShouldUseSameServiceProvider => other is ConfigurationInfo avoids a new EF internal service provider per tenant.
  • Tests cover tenant isolation, native retries with re-authorization per scope, rollback, and unauthorized or missing tenants. They also cover fail-before-transaction validation of the selected context.

Notes (non-blocking)

  • EntityFrameworkCoreConsumer.InvokeAsync(context, next) is now unused when scopedValidation is true. Keep it only if fixed-store composition still calls it.
  • Interlocked.Increment in the test factory is fine. A short comment next to Authorizations == 4 explaining the count (strategy context, two attempt scopes, verification) would help future maintainers; there is one in the test already, so this is optional.

Performance

  • The PR states the per-message cost, extends the existing MemoryDiagnoser benchmark with a tenancy axis, and adds the performance label. This matches AGENTS.md.

Docs

  • decisions D45, design §6.6, the website reference and guide, and the roadmap are all updated. This matches AGENTS.md.

I found no blocking issues.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 3bb5beae03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@thomhurst

thomhurst commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner Author

The earlier Codex wait is resolved: summary comment 6757844319 now reports completed with no findings for head 3bb5bea. Claude run 42747374115/1 is CLEAR for the same head. Rechecked every review surface: no reviews, inline comments or review threads requiring disposition. Claude’s optional notes need no change: fixed-store composition still uses the boundary directly and the authorization-count explanation already exists.

Verified the complete archived evidence inventory and all 35 SHA-256 hashes at /Users/tom/git/Relayer-evidence/pr-408/3bb5beae030d53f4283129ae83f0008a1de25f75/. No code changes or new validation in this unit. Proceeding through the guarded promotion and auto-merge script.

@thomhurst
thomhurst marked this pull request as ready for review November 10, 2026 03:22
@thomhurst
thomhurst enabled auto-merge (squash) November 10, 2026 03:23
@thomhurst
thomhurst merged commit 14d693a into main Nov 10, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Run the advisory benchmark regression gate on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compose EF Core consumers with tenant-required scoped DbContexts

1 participant