Skip to content

Isolate SaveChanges audit state per DbContext#378

Merged
cdcavell merged 18 commits into
mainfrom
agent/issue-374-context-audit-state-active
Jul 19, 2026
Merged

Isolate SaveChanges audit state per DbContext#378
cdcavell merged 18 commits into
mainfrom
agent/issue-374-context-audit-state-active

Conversation

@cdcavell

@cdcavell cdcavell commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • isolate mutable SaveChanges audit state by ApplicationDbContext instance
  • route save lifecycle callbacks through a scoped coordinator that maintains one existing ApplicationSaveChangesPipeline per context using weak context keys
  • add IApplicationMutationAuditReceiptRegistry for explicit context-specific receipt lookup with factory-created contexts
  • keep the normal IApplicationMutationAuditReceiptAccessor bound to the scoped ApplicationDbContext
  • preserve the existing interceptor, audit-store contracts, and single-context pipeline behavior

Tests

Added regression coverage that:

  • creates two ApplicationDbContext instances from IDbContextFactory<ApplicationDbContext> in one scope
  • pauses the first context during asynchronous audit append while the second context completes its save
  • verifies distinct audit rows and mutation batch identifiers
  • verifies each context resolves only its own completed receipt
  • verifies audited values do not cross between contexts
  • verifies the updated DI registrations and disabled-provider behavior
  • disables SQLite pooling in the temporary-file test fixture for reliable Windows cleanup

Documentation

Added guidance covering:

  • context-keyed audit state isolation
  • receipt lookup for scoped and factory-created contexts
  • weak-key lifetime behavior
  • EF Core's prohibition on concurrent operations against the same context instance
  • concurrency responsibilities for custom mutable scoped audit services

Validation

GitHub Actions CI passed:

  • solution build and analyzer validation
  • dotnet format verification
  • full test suite
  • coverage generation and repository threshold enforcement
  • security-critical coverage thresholds
  • dependency review
  • CodeQL analysis
  • template smoke tests on Ubuntu, Windows, and macOS
  • Docker build, Compose startup, and health verification
  • non-default no-auth/SQL Server scaffold validation

Fixes / Closes #374

Comment thread .github/workflows/format-issue-374.yml Outdated
Comment on lines +15 to +19
- name: Checkout branch
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: agent/issue-374-context-audit-state-active
fetch-depth: 0
@cdcavell
cdcavell marked this pull request as ready for review July 19, 2026 20:49
@cdcavell
cdcavell merged commit 3d639ae into main Jul 19, 2026
10 checks passed
@cdcavell
cdcavell deleted the agent/issue-374-context-audit-state-active branch July 19, 2026 20:50
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.

Isolate SaveChanges audit state per ApplicationDbContext instance

2 participants