↑↓ to navigate Enter to open "…" all these words ANDOR to combine

Architecture Decision Record

ADR-047: Runtime Revocation of Soft-Deleted Users' Active Sessions

Status

Accepted (2026-07-15). Revised 2026-08-07 (validator hoisted into a shared generic, the 30-second constant moved, the two apps revoke at different speeds). Revised 2026-08-23: the pipeline registration moved out of WebApplicationExtensions into the named-step MiddlewarePipelineBuilder (ADR-079), and a tenant-resolution step (ADR-073) now sits between authentication and rate limiting. Revised 2026-09-03 (MMCA.Common 1.185.0): the deleted-marker write was lifted out of the apps into DeleteUserHandlerBase, so the revocation window is now uniform across every consumer and the per-app asymmetry the 2026-08-07 revision recorded is gone. Revised 2026-10-01 (ADC's erasure tail re-described, middleware tests listed, anchors refreshed). Revised 2026-10-06: the deleted marker now lives 15 minutes while a "not deleted" answer still caches for 30 seconds, and the marker is honored on every host, including one with no validator. Revised 2026-10-07: a "not deleted" answer is no longer cached at all and the marker is read from the shared store, so an Identity host runs the validator query on every authenticated request and the 30-second window is gone. Revised 2026-10-21: the shared erasure base now also revokes and anonymizes the account's refresh sessions before the save, both middleware write-failure tests exercise a failed marker write, and anchors are refreshed. Revised 2026-10-26: anchors refreshed after line shifts in the pipeline builder, the cache service, the shared erasure base and ADC's delete handler. Revised 2026-10-28: anchors refreshed after line shifts in ADC's delete handler and the cache registration. Revised 2026-11-08: the marker lifetime is stated as 20 minutes (the earlier text said 15, which is the default access-token lifetime alone), writers use the longer of 20 minutes and the access-token lifetime plus clock skew, and DeleteUserHandlerBase writes through ISoftDeletedUserMarkerWriter, so a host no longer writes its own marker. Revised 2026-11-23: the marker now means "deleted or locked" (an administrator's lock and a machine-client revocation write it, an unlock clears it, and only the marker rejects a locked user's already-issued access token), the marker key moved to the cross-service xsvc:user:deleted:{userId}, a view-as guard step sits between this middleware and authorization, the erasure base blanks the account's email snapshot on view-as grants and schedules the push-installation delete before the save, Store's delete command is now ITransactional so both apps write the marker before the commit, a host with a non-memory IDistributedCache but no hybrid cache service now fails to resolve ICacheService instead of building a plain distributed one, and anchors are refreshed.

Context

Soft-delete is the framework's default deletion model (ADR-005): AuditableBaseEntity.Delete() sets IsDeleted = true and EF global query filters hide the row, but the record survives for audit, referential integrity, and undelete. Deactivating a user account is therefore a soft-delete, not a row removal.

Authentication is stateless JWT (ADR-004): Identity mints an access token, and every service validates it by signature and expiry without a per-request lookup against the account store. That is exactly what makes it scale, and it is also the problem here. A JWT is a bearer credential that stays valid until it expires; nothing in signature validation asks "is this account still active?" So when an administrator soft-deletes a user, that user's already-issued access token keeps passing validation on every service until it expires on its own. The same gap applies to the SSR session cookie that carries the JWT for fresh browser GETs (ADR-022): the cookie handler populates HttpContext.User from a token the API already issued, so a deleted user's prerender path also stays authenticated until the token lifetime runs out.

Closing that gap the textbook way (a token deny-list or a per-request account-status check) reintroduces exactly the stateful, per-request store lookup that stateless JWT was chosen to avoid. We wanted the deletion to take effect quickly without coupling every extracted service to the Identity database. Avoiding a database round trip on every authenticated request was an aim too, and the current design keeps it only on hosts that do not run Identity: on an Identity-hosting service it pays one account-status query per authenticated request, because a cached "not deleted" answer held by one replica would outlive a delete made on another (see the Decision).

Decision

Add a shared-pipeline middleware, SoftDeletedUserMiddleware (Source/Presentation/MMCA.Common.API/Middleware/SoftDeletedUserMiddleware.cs:40, BR-133), that rejects an authenticated caller with HTTP 401 once the caller's account has been soft-deleted or locked. A deleted-or-locked marker in the shared cache store answers on every host; an Identity-hosting service also falls back to an uncached account-status query, which checks deletion only, when no marker is set.

  • It runs after authentication, before authorization. That position is data in a named-step pipeline builder (ADR-079), not a hand-ordered sequence of Use* calls: UseCommonMiddlewarePipeline (Source/Presentation/MMCA.Common.API/Startup/WebApplicationExtensions.cs:49) delegates to the private ApplyPipeline helper (WebApplicationExtensions.cs:171), which seeds the framework steps from MiddlewarePipelineBuilder.CreateDefault() (WebApplicationExtensions.cs:173; Source/Presentation/MMCA.Common.API/Startup/Pipeline/MiddlewarePipelineBuilder.cs:31-159). This middleware is the SoftDeletedUserFilter step (MiddlewarePipelineStepNames.cs:59), applied as app.UseMiddleware<SoftDeletedUserMiddleware>() at MiddlewarePipelineBuilder.cs:124. Consecutive steps fix its place: UseAuthentication (:104), then TenantResolutionMiddleware (:112, ADR-073, which has to sit immediately after authentication because its claim strategy reads HttpContext.User), then UseRateLimiter (:120, ADR-019), then this middleware (:124), then the read-only view-as guard, ViewAsGuardMiddleware (:126-133, ADR-137), and only after them UseAuthorization (:137). So HttpContext.User is already populated when the check runs, and the check still gates every downstream endpoint. The order is frozen by a fitness function rather than by a comment: MiddlewarePipelineOrderTestsBase.ExpectedStepNames asserts SoftDeletedUserFilter after RateLimiting and ahead of ViewAsGuard and Authorization (MMCA.Common/Source/Hosting/MMCA.Common.Testing/Conformance/MiddlewarePipelineOrderTestsBase.cs:53-56). MiddlewarePipelineBuilder.Build()'s startup-validated invariants (MiddlewarePipelineBuilder.cs:260-283) do not name this step, so a host that moves it through the configure overload is caught by that fitness function, not at startup.
  • Anonymous requests pass straight through. When ICurrentUserService.UserId is null the middleware calls the next delegate and returns without any lookup (SoftDeletedUserMiddleware.cs:75-83), so unauthenticated traffic pays nothing.
  • The account-status check is an abstraction, implemented once in the framework. ISoftDeletedUserValidator (Source/Core/MMCA.Common.Application/Interfaces/Infrastructure/Auth/ISoftDeletedUserValidator.cs:7) exposes a single IsUserSoftDeletedAsync(userId, ...) method (ISoftDeletedUserValidator.cs:15). One shared generic implementation, SoftDeletedUserValidator<TUser> (MMCA.Common/Source/Core/MMCA.Common.Application/Users/SoftDeletedUserValidator.cs:20-36), runs the filter-bypassing existence query repository.ExistsAsync(u => u.Id == userId && u.IsDeleted, ignoreQueryFilters: true, ...) (SoftDeletedUserValidator.cs:31-34) against whichever aggregate it is closed over (TUser : AuditableAggregateRootEntity<UserIdentifierType>, SoftDeletedUserValidator.cs:21). Each app closes it over its own User at registration and writes no subclass of its own (services.TryAddScoped<ISoftDeletedUserValidator, SoftDeletedUserValidator<User>>() at MMCA.ADC.Identity.Application/DependencyInjection.cs:43 and MMCA.Store.Identity.Application/DependencyInjection.cs:48). The query bypasses the soft-delete global query filter deliberately, because a plain read would hide the very row it needs to find.
  • Only the deleted answer is cached, and it is read from the shared store. The key shape and the marker lifetime live in a shared class rather than inside the middleware, because a module that deletes an account has to write the exact key the middleware reads and a private constant in the presentation layer is unreachable from an application-layer handler. SoftDeletedUserCache.MarkerDuration is TimeSpan.FromMinutes(20) (Source/Core/MMCA.Common.Application/Auth/SoftDeletedUserCache.cs:41), the 15-minute default access-token lifetime plus the 5-minute default JWT clock skew, so the marker outlives every token issued before the delete or lock (its remarks, SoftDeletedUserCache.cs:27-40). That constant is the floor: SoftDeletedUserCache.MarkerDurationFor(accessTokenLifetime, clockSkew) returns the longer of it and the lifetime plus skew (:51-55), and MarkDeletedForAsync writes with that duration (:111), and SoftDeletedUserCache.KeyFor(userId) builds xsvc:user:deleted:{userId} under the invariant culture (SoftDeletedUserCache.cs:73-74). The xsvc: prefix is CrossServiceCacheKeys.Prefix (Source/Core/MMCA.Common.Application/Interfaces/CrossServiceCacheKeys.cs:27): the Identity service writes the marker and every other service reads it, so the key is not qualified with each host's own namespace. The middleware builds the key (SoftDeletedUserMiddleware.cs:85) and reads it through ICacheService.GetFromSharedStoreAsync<bool?> (:94-96), never from a replica's local copy (:91-93): HybridCacheService overrides that member so the read skips its process-local tier (Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:266-285, its remarks at :251-265), while the interface default falls back to GetAsync for a store with no local tier (Source/Core/MMCA.Common.Application/Interfaces/ICacheService.cs:69-70, its remarks at :63-67). A cached true short-circuits to 401 with no database call (SoftDeletedUserMiddleware.cs:108-115), before the validator is even resolved. On a host with a validator, a cached false passes through (:127-134), but only an earlier framework version ever wrote one; this one never does. A miss runs the validator (:142-144); a deleted answer writes the marker (:155-172, the SetAsync at :162-164) for the host's lifetime, which the private MarkerDurationFor helper takes from the registered ITokenService.AccessTokenLifetime plus the bearer clock skew, falling back to MarkerDuration only when no token service is registered (:186-189), and answers 401 (:174-175), and a live answer falls through to the next delegate (:178) without being written back. A "not deleted" answer is never cached, because each replica would keep its own copy and it would outlive a delete made elsewhere (:136-138). So on an Identity-hosting service a live user costs one shared-store read and one status query on every authenticated request, as the class summary states (:20-22).
  • The check fails open. Every external call on the path is wrapped: a cache read failure is logged and falls through to the validator query (SoftDeletedUserMiddleware.cs:98-106), a validator failure is logged and the request proceeds (:146-153), and a failed marker write for a deleted user only costs the next request another lookup (:166-171). HybridCacheService.GetFromSharedStoreAsync is itself fail-soft (HybridCacheService.cs:279-284), so with that cache a read fault reaches the middleware as a miss rather than an exception. The class states the reasoning in its own remarks (SoftDeletedUserMiddleware.cs:25-39): failing closed would turn any cache or database blip into a total outage for every authenticated request, because this middleware sits on the hot path of all of them, while failing open leaves a residual exposure bounded by the access-token lifetime (15 minutes by default, the figure the remarks give; a host that raises it widens the bound) and by the refresh-token revocation the deletion or lock already performed (SoftDeletedUserMiddleware.cs:33-37).
  • Services that do not host Identity honor the marker but have no fallback query. The class summary states it (SoftDeletedUserMiddleware.cs:10-23): the marker is honored on every host. The validator is resolved lazily via context.RequestServices.GetService<ISoftDeletedUserValidator>() (SoftDeletedUserMiddleware.cs:117) rather than as an InvokeAsync parameter, and only after the cached-true check. In an extracted service that does not host Identity (for example Store's Catalog or Sales service), no implementation is registered, so a set marker still answers 401, while a cache miss, a cached false or an unreachable cache passes the request through (SoftDeletedUserMiddleware.cs:118-125; the method remarks at :50-66): Identity is the source of truth. Resolving the validator as a constructor/parameter dependency would instead 500 every request in those services. MMCA.Helpdesk wires the same pipeline (MMCA.Helpdesk/Source/Hosts/MMCA.Helpdesk.Web/Program.cs:170) but hosts only a Tickets module and registers no validator, so it takes the same marker-only path.
  • The marker also carries a lock, and only the marker rejects a locked user's issued tokens. The same key means "deleted or locked" (SoftDeletedUserCache.cs:6-12). An administrator's lock writes it and an unlock clears it, both through ISoftDeletedUserMarkerWriter (Source/Core/MMCA.Common.Application/Auth/Administration/UserAdministrationServiceBase.cs:264, :277, the class remarks naming the marker at :17; ADR-116); the lock writes the marker first and then revokes the account's live refresh sessions (UserAdministrationServiceBase.cs:122-129, the revocation at :127-128), and the removal goes through SoftDeletedUserCache.ClearMarkerAsync (SoftDeletedUserCache.cs:129-137). A machine-client revocation writes it for the client's service account (Source/Core/MMCA.Common.Application/Auth/MachineClients/MachineClientService.cs:234, ADR-140). The validator query checks deletion only (SoftDeletedUserValidator.cs:31-34), so a locked user's already-issued token is rejected by the marker alone on every host, Identity included; once the marker expires, the sign-in and refresh gates refuse the locked account a new token (SoftDeletedUserMiddleware.cs:17-20): ADC's CheckNotLocked over User.IsLocked (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/AuthenticationService.cs:172-173) runs on sign-in (:108), refresh (:126) and external login (:424), and Store refuses an inactive User.IsActive on sign-in and refresh (MMCA.Store/Source/Modules/Identity/MMCA.Store.Identity.Application/Users/AuthenticationService.cs:116, :128).

SoftDeletedUserMiddlewareTests (MMCA.Common/Tests/Presentation/MMCA.Common.API.Tests/Middleware/SoftDeletedUserMiddlewareTests.cs) holds twenty tests. Eleven cover the branches: anonymous pass-through (SoftDeletedUserMiddlewareTests.cs:25); the four no-validator cases, a cache miss passing through, a set marker answering 401, a cached false passing through, and a cache read failure passing through (:44, :68, :88, :106); a deleted user found by the validator caching the marker for MarkerDuration (:127); a host with a raised access-token lifetime writing a marker that covers it (:145); a live non-deleted pass and a live deleted 401 (:169, :194); and a cached-deleted 401 and a cached non-deleted pass (the legacy-written entry), both with no database call (:211, :229). Six sit under the fail-open policy: a cache read failure with a deleted or a live user (:251, :270), cache and validator both failing (:298), a validator failure (:321), and two marker-write failures for a deleted user (:347, :379). Both arm a throwing SetAsync against a user the validator finds deleted, so both exercise a failed write: :347 also asserts the next delegate is never called and the write was attempted once for MarkerDuration (:370-374), while :379 asserts only the 401 (:397). Three pin the shared-store behavior: the marker is read from the shared store and never through GetAsync (:404), a live user is not written back (:426), and a deleted user still writes the marker for MarkerDuration (:450).

The marker write is part of the shared erasure workflow, so the window is uniform. Without a marker an Identity-hosting service still rejects a soft-deleted account on its next request, through the uncached validator query (SoftDeletedUserMiddleware.cs:136-144), unless a cached false written by an earlier framework version survives (:127-134) or the query faults and fails open (:146-153); a service with no validator keeps serving the account's still-valid tokens until the token itself expires (:118-125). Writing the marker at delete time collapses that to the next request on every host, and spares the Identity host the query. That write is not left to each app's delete handler: it is a step of DeleteUserHandlerBase.HandleAsync, the shared account-erasure workflow in MMCA.Common.Application (MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/DeleteUser/DeleteUserHandlerBase.cs:212-219), so every app that derives from the base gets the identical revocation window with no per-app code.

  • The base requires the marker writer to do it. ISoftDeletedUserMarkerWriter is a required constructor parameter of the base (DeleteUserHandlerBase.cs:98, in the primary constructor at :96-103, documented at :67-70), registered by AddApplication (Source/Core/MMCA.Common.Application/DependencyInjection.cs:52-54), so an app cannot derive from it and silently skip the marker; the compiler asks for the dependency. The base takes no ICacheService: SoftDeletedUserMarkerWriter holds the cache and the host's ITokenService and writes through SoftDeletedUserCache.MarkDeletedForAsync with MarkerDurationFor(tokenService.AccessTokenLifetime) (Source/Core/MMCA.Common.Application/Auth/SoftDeletedUsers/SoftDeletedUserMarkerWriter.cs:16-21).
  • It runs after the save and before the post-save afterCommit tail. The order is the app's OnAfterSoftDeleteAsync hook (:159; the base documents it as "the app's erasure tail" at :240), then Anonymize (:166), then RefreshSessionRevocation.RevokeAndAnonymizeAllAsync (:177-179), which revokes and anonymizes the account's refresh sessions in the same unit of work when the host registered an optional IRefreshSessionStore (:100; its parameter documentation at :72-78), then, when the subclass forwards the grant store, viewAsGrants.ForgetUserAsync (:185-188, ADR-137), then, when it forwards a scheduler, the scheduling of a DeleteUserPushInstallationsInternalCommand (:195-204, ADR-114; a scheduling failure fails the erasure), then SaveChangesAsync (:206), then markerWriter.MarkDeletedAsync(command.UserId, cancellationToken) (:214), then the queued afterCommit actions (:221-224). The save is the commit only when the command is not ITransactional; under an ITransactional command the marker and the afterCommit actions run before the transaction commits (the base summary, DeleteUserHandlerBase.cs:22-25). Both apps' DeleteUserCommand is ITransactional, ADC's (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/UseCases/DeleteUser/DeleteUserCommand.cs:22) and Store's (MMCA.Store/Source/Modules/Identity/MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserCommand.cs:25, its remarks at :12), so in both the marker precedes the commit. The base's own remarks give the reason (:40-43): the post-save afterCommit tail is unbounded app work (deleting a blob, calling storage) that can be slow or throw, and every second it takes is a second the deleted account's token still works, so revoking first bounds the exposure to the cache round trip regardless of what the app queued behind it. Neither deployed app queues an afterCommit action today (ADC schedules its blob delete inside the transaction instead, below), so the ordering guards future app work rather than any current tail.
  • It is best effort, and deliberately so. A non-cancellation exception is caught and logged as a warning via the base's own private SoftDeletedMarkerFailed logger message (DeleteUserHandlerBase.cs:216-219, the call at :218; declared at :265-266) rather than failing an erasure that has already been saved. A failed write costs only the shortening on hosts without a validator: there the token keeps working until it expires, as the base's remarks say (DeleteUserHandlerBase.cs:29-37). An Identity-hosting service still rejects the account on its next request through the validator query, as described above.
  • Apps are told not to write it themselves. The afterCommit parameter's own documentation says the base already wrote the marker ahead of the tail, so a subclass must not queue a second write (DeleteUserHandlerBase.cs:245-252).

Both deployed apps therefore revoke at the same speed. MMCA.ADC's DeleteUserHandler (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs) carries no marker code of its own (its remarks at :28-32 defer to the base) and forwards the ISoftDeletedUserMarkerWriter it takes (:39) to the base (:44), together with its view-as grant store and internal-command scheduler (:38, :43). Its OnAfterSoftDeleteAsync tail raises the cross-service UserDeleted integration event on the aggregate (:70) and schedules the avatar blob delete as a durable internal command enrolled in the erasure transaction (:79-82, the call at :81; :87-97; ADR-114) rather than queuing it post-commit; MMCA.Store's handler (MMCA.Store/Source/Modules/Identity/MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs) keeps its linked-Customer cascade and gains the marker behavior purely by forwarding the ISoftDeletedUserMarkerWriter it takes (:38) to the base (:42). Neither app contains a marker write.

Rationale

  • Bounds the stateless-JWT revocation gap cheaply. Stateless JWT (ADR-004) has no built-in revocation, so a deactivated account would otherwise stay usable for the full remaining token lifetime. The deleted marker turns "valid until the token expires" into "rejected on the next request", and where no marker was written an Identity-hosting service still rejects on the next request through the validator query, which is the point of the middleware.
  • The shared-store marker is what keeps non-Identity hosts stateless-friendly. A service that does not host Identity never queries the account store; it pays one shared-store read per authenticated request. The Identity host gives that up on purpose: it pays one status query per authenticated request, because a cached "not deleted" answer held in one replica's local tier would outlive a delete made on another (SoftDeletedUserMiddleware.cs:136-138), and correctness across replicas was chosen over the lookup rate.
  • The validator abstraction keeps the middleware in the framework. The middleware lives in MMCA.Common.API and depends only on ISoftDeletedUserValidator, so it needs no reference to any app's User entity. The query itself is generic over the app's aggregate (SoftDeletedUserValidator<TUser>), so each Identity module supplies only the type argument and the registration, not a copy of the query.
  • Lazy resolution is what makes it safe everywhere. One pipeline runs in Identity-hosting and non-Identity hosts alike; resolving the validator lazily lets the same middleware run the full check where Identity lives and enforce only the marker where it does not, without a per-host pipeline variant.

Trade-offs

  • Next-request revocation on the Identity host costs a query per request. With no "not deleted" cache, every authenticated request on an Identity-hosting service runs one shared-store read and one account-status query (SoftDeletedUserMiddleware.cs:20-22). There is no lookup window to tune: the database load scales with authenticated traffic on that host instead of with live users. The marker floor is compile-time (SoftDeletedUserCache.MarkerDuration, SoftDeletedUserCache.cs:41, 20 minutes), but a writer lengthens it for a raised access-token lifetime through MarkerDurationFor (:51-55). DeleteUserHandlerBase takes a required ISoftDeletedUserMarkerWriter (DeleteUserHandlerBase.cs:98), whose implementation writes the marker with MarkerDurationFor(tokenService.AccessTokenLifetime) (SoftDeletedUserMarkerWriter.cs:20), so a host that raises the lifetime cannot keep a shorter marker by omission. The Application-layer writers assume the 5-minute default clock skew (SoftDeletedUserCache.cs:22; SoftDeletedUserMarkerWriter.cs:7-9), while the middleware's own write passes the host's bearer clock skew (SoftDeletedUserMiddleware.cs:186-189).
  • The marker only covers erasures that go through the shared base. The framework now both supplies the key and TTL (SoftDeletedUserCache.KeyFor and MarkerDurationFor, SoftDeletedUserCache.cs:73-74, :51-55) and writes the marker on the app's behalf through ISoftDeletedUserMarkerWriter (DeleteUserHandlerBase.cs:214), so no app can forget it. What the base cannot cover is a soft-delete that never reaches it: an administrative IsDeleted = true applied by a migration, a support script or any handler other than a DeleteUserHandlerBase subclass writes no marker. Those deletions still revoke on the next request on an Identity-hosting service through the validator query (SoftDeletedUserMiddleware.cs:136-144), except while a legacy cached false survives (:127-134) or the query fails open (:146-153), and not at all before token expiry on a service with no validator (:118-125). Uniformity here is uniformity across the erasure use case, not across every path that can set the flag.
  • A cache fault silently degrades the window rather than failing. The write is swallowed and logged at Warning (DeleteUserHandlerBase.cs:216-219), which is the right trade for an already-committed irreversible erasure, but it means the shortened window is a best-effort property: the caller gets a success result either way, and only the log says whether revocation was actually accelerated.
  • Failing open is a deliberate availability-over-strictness trade. A cache or database failure on this path lets the request through instead of rejecting it (SoftDeletedUserMiddleware.cs:98-106, :146-153), so while either store is unhealthy a deleted user keeps being served for the remaining lifetime of an already-issued access token. The alternative, failing closed, would convert the same blip into a 401 for every authenticated request in the application.
  • The marker-only posture trusts the marker. In a service with no validator registered, a soft-deleted user is rejected only when the deleted marker is present in that service's cache; on a miss, a cached false or a cache failure the token is accepted for its remaining lifetime there, on the assumption that Identity is the source of truth. Only Identity-hosting hosts re-check the database; extracted non-Identity services enforce the revocation only through the marker.
  • Cache-scope-dependent. The marker reaches every replica and service only when a distributed store backs the cache. The default ICacheService is MemoryCacheService when no non-memory IDistributedCache is registered (Source/Core/MMCA.Common.Infrastructure/DependencyInjection.Caching.cs:79-99, the fallback at :96-98), and there GetFromSharedStoreAsync is a plain GetAsync (ICacheService.cs:69-70), so a marker written by the Identity host is not visible to another process, and a validator-less host on a memory-only cache never sees it. A host that registers a non-memory IDistributedCache without AddCommonHybridCache does not fall back silently: resolving ICacheService throws an InvalidOperationException naming the call (DependencyInjection.Caching.cs:86-93).
  • Enforcement depends on registration. An Identity-hosting service that fails to register ISoftDeletedUserValidator silently degrades to the marker-only path, the same audit-the-inventory caveat other opt-in framework capabilities carry (ADR-005).

ADR-005 (soft-delete is the deletion model whose still-authenticated tokens this middleware revokes; deleting a user is a soft-delete, not a row removal), ADR-004 (the stateless RS256/JWKS validation that has no built-in revocation, which this bounds without a per-request store lookup), ADR-022 (the SSR session cookie carries the same JWT into the prerender path this middleware also gates), ADR-079 (the shared named-step HTTP pipeline that now owns this middleware's registration and its order), ADR-073 (multi-tenancy, whose TenantResolutionMiddleware step sits between authentication and the rate limiter, ahead of this one), ADR-019 (the rate limiter that runs immediately before it, for its own authentication-dependent reason), ADR-137 (read-only view-as: its guard step runs right after this one, the middleware's marker lifetime uses its bearer clock skew, and the erasure base blanks the account on view-as grants), ADR-116 (user administration, whose lock and unlock write and clear this marker), ADR-140 (machine clients, whose revocation writes this marker for the service account), ADR-114 (internal commands, through which the erasure schedules ADC's avatar delete and the push-installation delete inside the transaction).

Revision (2026-08-07)

Re-verified against current source. The decision is unchanged, but three things it described have moved: the validator implementation, the home of the 30-second constant, and the claim that both apps revoke at the same speed.

  1. The per-app validators were hoisted into one shared generic. The ADR cited a filter-bypassing existence query duplicated in each app (MMCA.ADC.Identity.Application/Users/SoftDeletedUserValidator.cs:10,21-24 and the Store equivalent). Neither file exists now. The query lives once in the framework as SoftDeletedUserValidator<TUser> (MMCA.Common/Source/Core/MMCA.Common.Application/Users/SoftDeletedUserValidator.cs:20-34, its own remarks at :11-17 stating no per-app subclass is needed), closed over each app's User at registration (MMCA.ADC.Identity.Application/DependencyInjection.cs:35, from :32; MMCA.Store.Identity.Application/DependencyInjection.cs:44, from :39). The behavior of the query is what it was; only its location changed.
  2. The 30-second value moved out of the middleware. There is no CacheDuration member in SoftDeletedUserMiddleware any more. The figure is SoftDeletedUserCache.MarkerDuration => TimeSpan.FromSeconds(30) (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/SoftDeletedUserCache.cs:29), referenced by the middleware's cache write at SoftDeletedUserMiddleware.cs:132. The extraction is what lets a delete handler write the same key and TTL the middleware reads (SoftDeletedUserCache.cs:42-43, :53-61).
  3. The fail-open policy is now recorded. The middleware wraps its cache read, validator query and cache write in handlers that let the request proceed on failure (SoftDeletedUserMiddleware.cs:93-100, :118-125, :135-140), a trade-off argued in the class's own remarks (:16-30). The ADR asserted neither the behavior nor the reasoning before; both are now in the Decision and Trade-offs sections.
  4. The uniform revocation window was wrong for ADC. ADC's DeleteUserHandler writes the deleted marker in an after-commit callback (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs:68-80), so its revocation lands on the next request rather than after the passive window. Store's handler does not (MMCA.Store/Source/Modules/Identity/MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs:35-60), so Store is the app the original "at most 30 seconds" wording actually described. The asymmetry is stated in the Decision and carried as its own trade-off.
  5. Line anchors re-verified. The middleware class declaration is at SoftDeletedUserMiddleware.cs:31 (from :15; lines 1-30 are usings plus the class remarks), the null-UserId pass-through at :65-73 (from :43-51), the lazy validator resolution at :75 (from :53) with its no-validator pass-through at :76-83 (from :54-61), the key build at :85 and cache read at :91 (from :63-66), the cached-true 401 at :102-106 (from :66-71), the cache-miss validator call at :114-116 with the cache write at :131-133 and the deleted-401 at :143-147 (from :73-84), and the fall-through at :150 (from :86). Unchanged and re-checked: the pipeline registration (WebApplicationExtensions.cs:109, with :96,108 and :110 around it, both superseded on 2026-08-23, see below), ISoftDeletedUserValidator.cs:7,15, the Helpdesk no-op path (MMCA.Helpdesk/Source/Hosts/MMCA.Helpdesk.Web/Program.cs:111, superseded below), and MMCA.Common/Tests/Presentation/MMCA.Common.API.Tests/Middleware/SoftDeletedUserMiddlewareTests.cs.

Revision (2026-08-23)

Re-verified against current source. The decision, the cache design, the fail-open policy and the per-app asymmetry are all unchanged; what moved is where the middleware's position is expressed, and one new neighbour now sits ahead of it.

  1. The registration left WebApplicationExtensions.cs entirely. That file no longer calls UseAuthentication, UseRateLimiter, UseMiddleware<SoftDeletedUserMiddleware> or UseAuthorization at all: UseCommonMiddlewarePipeline (WebApplicationExtensions.cs:48, and the configure overload at :60) only routes into the private ApplyPipeline helper (:140), which seeds MiddlewarePipelineBuilder.CreateDefault() (:142). Every :96, :108, :109 and :110 anchor the Decision and the 2026-08-07 revision carried is therefore dead. The step registrations now live in MMCA.Common/Source/Presentation/MMCA.Common.API/Startup/Pipeline/MiddlewarePipelineBuilder.cs: UseAuthentication at :110, UseRateLimiter at :126, UseMiddleware<SoftDeletedUserMiddleware>() at :130, UseAuthorization at :134. The behavior is what it was; the order became data in a named-step builder (ADR-079).
  2. A tenant-resolution step now runs between authentication and rate limiting. TenantResolutionMiddleware is applied at MiddlewarePipelineBuilder.cs:118 under the TenantResolution step name (ADR-073), so the current run of steps is Authentication (:110), TenantResolution (:118), RateLimiting (:126), SoftDeletedUserFilter (:130), Authorization (:134). The ADR's own claim, that the check runs after authentication and before authorization, still holds exactly; it is simply no longer adjacent to UseAuthentication. That new step follows the same opt-in, inert-unless-configured posture this middleware established, and its own comment names this middleware as the precedent (MiddlewarePipelineBuilder.cs:114-117).
  3. The order is now held by a fitness function. MiddlewarePipelineOrderTestsBase.ExpectedStepNames (MMCA.Common/Source/Hosting/MMCA.Common.Testing/Conformance/MiddlewarePipelineOrderTestsBase.cs:38-58) lists SoftDeletedUserFilter between RateLimiting and Authorization (:51-53), so a reorder fails a test. Note the limit: MiddlewarePipelineBuilder.Build() validates four load-bearing adjacencies at startup (MiddlewarePipelineBuilder.cs:257-280) and none of them names this step, so a host that moves it with the configure overload gets no startup error, only the fitness-function failure.
  4. Helpdesk anchor corrected. app.UseCommonMiddlewarePipeline() is at MMCA.Helpdesk/Source/Hosts/MMCA.Helpdesk.Web/Program.cs:130, after var app = builder.Build(); (:124) and app.MapDefaultEndpoints() (:129); the :111 and :117 anchors earlier drafts carried are both dead. The substance is unchanged: Helpdesk wires the shared pipeline, registers no ISoftDeletedUserValidator, and takes the no-op path.
  5. Re-checked and unchanged: SoftDeletedUserMiddleware.cs:31 (class declaration), :65-73 (anonymous pass-through), :75 and :76-83 (lazy resolution, no-validator pass-through), :85, :91, :102-106, :114-116, :131-133, :143-147, :150 (the cache/validator path), :93-100, :118-125, :135-140 (fail-open handlers), ISoftDeletedUserValidator.cs:7,15, SoftDeletedUserValidator.cs:20-34 with its constraint at :21 and query at :31-34, SoftDeletedUserCache.cs:29,42-43,53-61, the two registrations (MMCA.ADC.Identity.Application/DependencyInjection.cs:35, MMCA.Store.Identity.Application/DependencyInjection.cs:44), the two delete handlers (ADC DeleteUserHandler.cs:68-80, Store DeleteUserHandler.cs:35-60), and MMCA.Common/Tests/Presentation/MMCA.Common.API.Tests/Middleware/SoftDeletedUserMiddlewareTests.cs.

Revision (2026-09-03, MMCA.Common 1.185.0)

Re-verified against current source. The middleware, the cache design, the 30-second window and the fail-open policy are all unchanged. What changed is who writes the deleted marker, and with it the central asymmetry this record has carried since 2026-08-07.

  1. The marker write moved into the framework. DeleteUserHandlerBase.HandleAsync now writes it itself, between SaveChangesAsync and the app's post-commit tail (MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/DeleteUser/DeleteUserHandlerBase.cs:137-149, the call at :142-144). The base's remarks argue the ordering (:31-36): the app's tail is unbounded work, and every second of it is a second a deleted account's token still works, so the revocation goes first and the exposure is bounded by the cache round trip alone.
  2. ICacheService became a required constructor parameter. The base is now DeleteUserHandlerBase<TUser, TCommand>(IUnitOfWork unitOfWork, ICacheService cacheService, ILogger logger) (DeleteUserHandlerBase.cs:58-61). This is a breaking constructor change for every subclass, and it is the mechanism that makes the guarantee real: an app cannot derive from the base and quietly omit the marker, because the compiler asks for the dependency.
  3. The window is uniform, so the "two apps revoke at different speeds" claim is retired. Item 4 of the 2026-08-07 revision and the trade-off that restated it are superseded. ADC's hand-rolled after-commit closure and its local LogSoftDeletedMarkerFailed partial were deleted from MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs, leaving only its avatar-blob tail; Store gained the behavior without writing any marker code, by adding an ICacheService parameter to MMCA.Store/Source/Modules/Identity/MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs and forwarding it to the base. Both landed in the 1.185.0 consumer sweep.
  4. Best effort is now a framework property rather than an app one. The base catches any non-cancellation exception from the write and logs it at Warning through UserUseCaseLog.SoftDeletedMarkerFailed (DeleteUserHandlerBase.cs:146-149; MMCA.Common/Source/Core/MMCA.Common.Application/Users/UserUseCaseLog.cs:23), for the reason the remarks give (:24-29): the erasure is already committed and irreversible, so a cache fault must not turn it into a failure the caller would retry. On failure the revocation falls back to the passive 30-second bound.
  5. Subclasses are told not to duplicate it. The afterCommit parameter's documentation states that the base already wrote the marker ahead of the tail (DeleteUserHandlerBase.cs:175-181), so a second write from an app hook is a documented mistake rather than a silent duplicate.
  6. Store registration anchor corrected. ISoftDeletedUserValidator is registered at MMCA.Store.Identity.Application/DependencyInjection.cs:44; the :46 anchor the Decision and both earlier revisions carried is dead. ADC's is unchanged at MMCA.ADC.Identity.Application/DependencyInjection.cs:35.
  7. Re-checked and unchanged: SoftDeletedUserMiddleware.cs:31, :65-73, :75, :76-83, :85, :91, :102-106, :114-116, :131-133, :143-147, :150, :93-100, :118-125, :135-140, ISoftDeletedUserValidator.cs:7,15, SoftDeletedUserValidator.cs:20-34, SoftDeletedUserCache.cs:29,42-43,53-61, and the pipeline anchors in MiddlewarePipelineBuilder.cs (:110,118,126,130,134).

Revision (2026-10-01)

Re-verified against current source (MMCA.Common v1.216.0). The decision, the middleware, the 30-second window, the fail-open policy and the shared marker write are unchanged. One description was wrong and the anchors had drifted.

  1. ADC's erasure tail is no longer only an avatar-blob tail. ADC's OnAfterSoftDeleteAsync raises the UserDeleted integration event on the aggregate, so the outbox row commits with the erasure (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs:59), and schedules the avatar blob delete as a durable internal command inside the erasure transaction (DeleteUserHandler.cs:68-71, :76-86; ADR-114) instead of a post-commit closure. It still writes no marker (:25-27). The Decision paragraph is corrected.
  2. The middleware tests cover the fail-open policy. SoftDeletedUserMiddlewareTests holds twelve tests: the six branches the Decision listed (SoftDeletedUserMiddlewareTests.cs:25-121) plus six fail-open cases (:143, :162, :190, :213, :236, :265). The Decision now lists them.
  3. Anchors refreshed. ApplyPipeline is at WebApplicationExtensions.cs:168 with the CreateDefault() call at :170; MiddlewarePipelineBuilder.CreateDefault() spans :31-151, with Authentication :105, TenantResolution :113, RateLimiting :121, SoftDeletedUserFilter :125 and Authorization :129; Build() is :252-275 and its four invariants still do not name this step. DeleteUserHandlerBase.cs: constructor :62-65, SaveChangesAsync :139, marker try/catch :144-153 (call :146-148, log :150-153), afterCommit loop :155-158, ordering remarks :35-39, best-effort remarks :25-33, afterCommit documentation :179-185. The registrations are at MMCA.ADC.Identity.Application/DependencyInjection.cs:37 and MMCA.Store.Identity.Application/DependencyInjection.cs:47; Helpdesk's app.UseCommonMiddlewarePipeline() is at Program.cs:142 and Helpdesk still registers no validator.

Revision (2026-10-06)

Re-verified against current source. The decision, the pipeline position, the fail-open policy and the shared marker write are unchanged; the cache lifetimes and the behavior of hosts without a validator moved.

  1. The marker and the lookup cache now have different lifetimes. SoftDeletedUserCache.MarkerDuration is TimeSpan.FromMinutes(15) (SoftDeletedUserCache.cs:32), sized to the default access-token lifetime, no longer 30 seconds. The middleware caches a deleted answer for MarkerDuration and a "not deleted" answer for its private 30-second NotDeletedLookupDuration (SoftDeletedUserMiddleware.cs:39, chosen at :147). The Decision, Rationale and Trade-offs now say which figure is which.
  2. The marker is honored on hosts with no validator. The cache is read and a cached true answers 401 before the validator is resolved (SoftDeletedUserMiddleware.cs:102-109, then :111), so a service that does not host Identity, Helpdesk included, rejects a marked user instead of no-opping; only a cache miss, a cached false or a cache failure passes through there (:112-119). The "no-op" bullet, the Rationale's "stay inert" wording and the no-op trade-off are rewritten.
  3. Marker failure logging lives on the base. UserUseCaseLog.cs no longer exists; SoftDeletedMarkerFailed is a private LoggerMessage on DeleteUserHandlerBase (DeleteUserHandlerBase.cs:199-200, called at :152).
  4. The middleware tests number sixteen, adding four no-validator cases and the marker-duration write (SoftDeletedUserMiddlewareTests.cs:44-127); the fail-open tests now sit at :226, :245, :273, :296, :319, :348.
  5. Anchors re-verified against current source: middleware declaration :33, remarks :18-32, anonymous pass-through :74-82, key :84, read :90; KeyFor SoftDeletedUserCache.cs:45-46, MarkDeletedAsync :56-64; ApplyPipeline WebApplicationExtensions.cs:170 with CreateDefault() at :172; SoftDeletedUserValidator.cs:20-36; ADC registration MMCA.ADC.Identity.Application/DependencyInjection.cs:38; afterCommit documentation DeleteUserHandlerBase.cs:179-186.

Revision (2026-10-07)

Re-verified against current source (MMCA.Common v1.233.0). The pipeline position, the validator abstraction, the lazy resolution, the fail-open policy and the shared marker write are unchanged. What moved is the lookup cache: a "not deleted" answer is no longer cached, and the marker is read from the shared store, so the 30-second window the Decision, Rationale and Trade-offs described is gone.

  1. A live answer is never cached. NotDeletedLookupDuration no longer exists. The middleware writes only the deleted marker (SoftDeletedUserMiddleware.cs:152-169) and states why a live answer is not written (:133-135), so an Identity-hosting service pays one shared-store read and one validator query on every authenticated request (:17-19). A cached false is still honored on such a host, but only an earlier framework version wrote one (:124-131). The Context, Decision, Rationale and the first two Trade-offs are rewritten; the revocation bound without a marker is now the next request on an Identity host, not 30 seconds.
  2. The marker is read from the shared store. The read is ICacheService.GetFromSharedStoreAsync<bool?> (SoftDeletedUserMiddleware.cs:91-93), which HybridCacheService serves from L2 only (HybridCacheService.cs:140-165) and which is itself fail-soft (:167-172). The interface default is a plain GetAsync (ICacheService.cs:60-66), and MemoryCacheService is the default when no non-memory IDistributedCache is registered (DependencyInjection.Caching.cs:59-80), so the cache-scope trade-off is rewritten to keep its memory-only half and drop the per-instance window.
  3. The marker is not always written after the commit. Under an ITransactional command the base's save is not the commit, so the marker and the afterCommit actions run before it (DeleteUserHandlerBase.cs:18-21). ADC's DeleteUserCommand is ITransactional (MMCA.ADC.Identity.Application/Users/UseCases/DeleteUser/DeleteUserCommand.cs:22); Store's is not (MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserCommand.cs:17). The ordering bullet now says "after the save".
  4. A failed marker write no longer falls back to a 30-second path. On an Identity host the validator still rejects on the next request; only a host with no validator waits for token expiry, which is what the base's remarks describe (DeleteUserHandlerBase.cs:25-33).
  5. The middleware tests number nineteen. Three were added: the marker read from the shared store (SoftDeletedUserMiddlewareTests.cs:374), a live user not written back (:396), and a deleted user still writing the marker (:420). The cached-false test (:205) now covers a legacy-written entry, and InvokeAsync_CacheWriteThrows_PassesThrough (:320) arms a throwing write for a live user that the middleware never performs, so only :349 exercises a failed write.
  6. Anchors re-verified against current source: middleware declaration :37 (from :33), summary :10-20 (from :13-15), class remarks :22-36 (from :18-32), method remarks :51-57 (from :56-59), anonymous pass-through :72-80 (from :74-82), key :82 (from :84), read :91-93 (from :90), read fail-open :95-103 (from :92-100), cached-true 401 :105-112 (from :102-109), validator resolution :114 (from :111), no-validator pass-through :115-122 (from :112-119), validator call :139-141 (from :127-129), validator fail-open :143-150 (from :131-138), marker write :152-169 (from :140-158) with its fail-open :163-168 (from :152-157), deleted 401 :171-172 (from :160-164), fall-through :175 (from :167); SoftDeletedUserCache.cs sizing remarks :22-29 (from :22-31); tests :170, :187, :205, :227, :246, :274, :297, :320, :349 (each one line later than before). Unchanged and re-checked: SoftDeletedUserCache.cs:32, :45-46, :56-64, and DeleteUserHandlerBase.cs :62-65, :139, :144-153, :155-158, :179-186, :199-200.

Revision (2026-10-21)

Re-verified against current source. The middleware, the pipeline position, the shared-store marker read, the fail-open policy and the shared marker write are unchanged. What moved is the erasure workflow ahead of the save, the description of the two write-failure tests, and the anchors.

  1. The erasure base revokes refresh sessions before the save. DeleteUserHandlerBase takes an optional IRefreshSessionStore (DeleteUserHandlerBase.cs:78, documented at :66-72) and calls RefreshSessionRevocation.RevokeAndAnonymizeAllAsync (:155-157) before SaveChangesAsync (:159), so the revocation and the anonymized session rows commit with the erasure. ADC forwards the store to the base (DeleteUserHandler.cs:37-38), as does Store (MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserHandler.cs:35). The ordering bullet now names that step; the marker still follows the save and precedes the afterCommit actions.
  2. Both write-failure tests exercise a failed write. The live-user write test the 2026-10-07 revision described no longer exists. The two tests are InvokeAsync_DeletedUserAndMarkerWriteThrows_StillReturns401 (SoftDeletedUserMiddlewareTests.cs:323) and InvokeAsync_CacheWriteThrowsForDeletedUser_Returns401 (:355); each arms a throwing SetAsync for a user the validator finds deleted (:328-335, :360-367). The count stays nineteen. The Decision paragraph is corrected.
  3. Anchors re-verified against current source: ADC registration MMCA.ADC.Identity.Application/DependencyInjection.cs:41 (from :38; Store's :47 holds); HybridCacheService.GetFromSharedStoreAsync :216-235 with remarks :201-215 (from :140-165) and its fail-soft catch :229-234 (from :167-172); DeleteUserHandlerBase.cs ICacheService parameter :76 in the constructor :74-79 (from :62-65), SaveChangesAsync :159 (from :139), marker try/catch :164-173 (from :144-153) with the call :166-168 (from :146-148) and the log :170-173, :172 (from :150-153, :152), afterCommit loop :175-178 (from :155-158), summary :19-22 (from :18-21), best-effort remarks :30-34 (from :25-33), ordering remarks :37-40 (from :35-39), afterCommit documentation :199-206 (from :179-186), SoftDeletedMarkerFailed declaration :219-220 (from :199-200); ADC DeleteUserHandler.cs remarks marker sentence :27-29 (from :25-27), UserDeleted :62 (from :59), schedule :71-74 (from :68-71), ScheduleAvatarBlobDeletionAsync :79-89 (from :76-86); tests :380, :402, :426 (from :374, :396, :420). Unchanged and re-checked: tests :25, :44, :68, :88, :106, :127, :145, :170, :187, :205, :227, :246, :274, :297.

Revision (2026-10-26)

Re-verified against current source. The middleware, its place between RateLimiting and Authorization, the shared-store marker read, the fail-open policy, the marker write in the shared erasure base and ADC's in-transaction avatar schedule are unchanged. Only anchors moved.

  1. Anchors re-verified against current source: UseCommonMiddlewarePipeline WebApplicationExtensions.cs:49 (from :48), ApplyPipeline :171 (from :170) with the CreateDefault() call :173 (from :172); MiddlewarePipelineBuilder.CreateDefault() :31-150 (from :31-151), UseAuthentication :104 (from :105), TenantResolutionMiddleware :112 (from :113), UseRateLimiter :120 (from :121), SoftDeletedUserMiddleware :124 (from :125), UseAuthorization :128 (from :129), Build() :251-274 (from :252-275, still four invariants, none naming this step); MiddlewarePipelineOrderTestsBase.cs RateLimiting, SoftDeletedUserFilter, Authorization :53-55 (from :51-53); ICacheService.cs default GetFromSharedStoreAsync :69-70 with its fallback remarks :63-67 (from :60-66); HybridCacheService.GetFromSharedStoreAsync :217-236 with remarks :203-216 (from :216-235, :201-215) and its fail-soft catch :230-235 (from :229-234); DeleteUserHandlerBase.cs marker try/catch :165-174 (from :164-173) with MarkDeletedAsync :167-169 (from :166-168) and the log :171-174, :173 (from :170-173, :172), afterCommit loop :176-179 (from :175-178), erasure-tail summary :195 (from :194), afterCommit documentation :200-207 (from :199-206), SoftDeletedMarkerFailed declaration :220-221 (from :219-220); ADC DeleteUserHandler.cs remarks marker sentence :27-30 (from :27-29), ICacheService :35 (from :34), base call :39 (from :38), UserDeleted :63 (from :62), schedule :72-75 (from :71-74), ScheduleAvatarBlobDeletionAsync :80-90 (from :79-89). Unchanged and re-checked: MiddlewarePipelineStepNames.cs:59; DeleteUserHandlerBase.cs summary :19-22, best-effort remarks :30-34, ordering remarks :37-40, refresh-store documentation :66-72, constructor :74-79 with ICacheService :76 and IRefreshSessionStore :78, OnAfterSoftDeleteAsync :137, Anonymize :144, RevokeAndAnonymizeAllAsync :155-157, SaveChangesAsync :159.

Revision (2026-10-28)

Re-verified against current source. The middleware, its place between RateLimiting and Authorization, the shared-store marker read, the fail-open policy, the marker write in the shared erasure base, ADC's in-transaction avatar schedule and the memory-only default cache are unchanged. Only anchors moved: ADC's delete handler gained a constructor parameter ahead of ICacheService.

  1. Anchors re-verified against current source: ADC DeleteUserHandler.cs remarks marker sentence :27-31 (from :27-30; the sentence ends "nothing here re-stamps the marker" at :31), ICacheService :36 (from :35), base call :40 (from :39), UserDeleted :64 (from :63), schedule block :66-76 with the ScheduleAvatarBlobDeletionAsync call at :75 (from :72-75), ScheduleAvatarBlobDeletionAsync :81-91 (from :80-90); DependencyInjection.Caching.cs ICacheService factory :75-96 (from :59-80), with the non-memory IDistributedCache check at :77-78 and the MemoryCacheService fallback at :93.

Revision (2026-11-23)

Re-verified against current source. The pipeline position (after authentication, before authorization), the shared-store marker read, the uncached validator query, the lazy resolution, the fail-open policy and the marker write in the shared erasure base are unchanged. What moved is what the marker means, the step that now follows this one, the erasure steps ahead of the save, Store's transaction posture and the anchors.

  1. The marker means "deleted or locked". An administrator's lock writes it and an unlock clears it through ISoftDeletedUserMarkerWriter (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/Administration/UserAdministrationServiceBase.cs:264, :277; ADR-116), the removal through the new SoftDeletedUserCache.ClearMarkerAsync (SoftDeletedUserCache.cs:129-137), and a machine-client revocation writes it (MachineClientService.cs:234, ADR-140). The validator checks deletion only (SoftDeletedUserValidator.cs:31-34), so a locked user's already-issued token is rejected by the marker alone (SoftDeletedUserMiddleware.cs:11-20; SoftDeletedUserCache.cs:6-12). The Decision gains a bullet for it.
  2. The middleware's own marker write follows the host's token lifetime. The SetAsync passes the private MarkerDurationFor(context.RequestServices) (SoftDeletedUserMiddleware.cs:163), which uses the registered ITokenService.AccessTokenLifetime plus the bearer clock skew and falls back to MarkerDuration only with no token service (:186-189). A matching test was added (SoftDeletedUserMiddlewareTests.cs:145), so the suite holds twenty tests, eleven of them branch tests.
  3. The key carries the cross-service prefix. KeyFor builds xsvc:user:deleted:{userId} (SoftDeletedUserCache.cs:73-74; CrossServiceCacheKeys.Prefix at CrossServiceCacheKeys.cs:27).
  4. A view-as guard step now separates this middleware from authorization. ViewAsGuardMiddleware runs at MiddlewarePipelineBuilder.cs:126-133 (ADR-137), before UseAuthorization at :137, and the fitness list orders SoftDeletedUserFilter, ViewAsGuard, Authorization (MiddlewarePipelineOrderTestsBase.cs:54-56).
  5. The erasure base takes the marker writer, not the cache. Its constructor (:96-103) takes ISoftDeletedUserMarkerWriter (:98) and no ICacheService; the base calls markerWriter.MarkDeletedAsync (DeleteUserHandlerBase.cs:214), and SoftDeletedUserMarkerWriter writes through MarkDeletedForAsync with MarkerDurationFor(tokenService.AccessTokenLifetime) (SoftDeletedUserMarkerWriter.cs:16-21, registered at MMCA.Common.Application/DependencyInjection.cs:52-54). The fixed-lifetime SoftDeletedUserCache.MarkDeletedAsync (SoftDeletedUserCache.cs:84-92) has no caller in Common Source/. Both apps forward the writer (ADC DeleteUserHandler.cs:39, :44; Store DeleteUserHandler.cs:38, :42). The Decision bullet, the closing paragraph and the Trade-offs are corrected.
  6. Two pre-save erasure steps were added. When forwarded, the base blanks the account on view-as grants (DeleteUserHandlerBase.cs:185-188, ADR-137) and schedules a DeleteUserPushInstallationsInternalCommand whose scheduling failure fails the erasure (:195-204, ADR-114). The ordering bullet names both.
  7. Store's delete command is now ITransactional. MMCA.Store.Identity.Application/Users/UseCases/DeleteUser/DeleteUserCommand.cs:25 (remarks :12), like ADC's (:22), so in both apps the marker precedes the commit. The ADC/Store contrast in the ordering bullet is removed.
  8. A non-memory distributed cache without the hybrid service now fails. With a non-memory IDistributedCache and no AddCommonHybridCache, resolving ICacheService now throws InvalidOperationException (DependencyInjection.Caching.cs:86-93); MemoryCacheService is returned only with no such cache (:96-98). The cache-scope trade-off says so.
  9. Related ADRs added: ADR-137, ADR-116, ADR-140 and ADR-114.
  10. Anchors re-verified against current source: SoftDeletedUserMiddleware.cs class :40 (from :37), summary :10-23 (from :10-20), cost sentence :20-22 (from :17-19), class remarks :25-39 (from :22-36), method remarks :50-66 (from :51-57), anonymous pass-through :75-83 (from :72-80), key :85 (from :82), shared-store comment :91-93 (from :88-90), read :94-96 (from :91-93), read fail-open :98-106 (from :95-103), cached-true 401 :108-115 (from :105-112), validator resolution :117 (from :114), no-validator pass-through :118-125 (from :115-122), cached false :127-134 (from :124-131), no-cache comment :136-138 (from :133-135), validator call :142-144 (from :139-141), validator fail-open :146-153 (from :143-150), marker write :155-172 with SetAsync :162-164 (from :152-169, :159-161), write fail-open :166-171 (from :163-168), deleted 401 :174-175 (from :171-172), fall-through :178 (from :175); SoftDeletedUserCache.cs MarkerDuration :41 (from :38), remarks :27-40 (from :25-36), default skew :22 (from :20), MarkerDurationFor :51-55 (from :48-52), KeyFor :73-74 (from :45-46), MarkDeletedForAsync write :111 (from :95); MiddlewarePipelineBuilder.cs CreateDefault() :31-159 (from :31-150), Build() :260-283 (from :251-274, still four invariants, none naming this step), Authorization :137 (from :128); MiddlewarePipelineOrderTestsBase.cs :53-56 (from :53-55); HybridCacheService.GetFromSharedStoreAsync :266-285 with remarks :251-265 and fail-soft catch :279-284 (from :217-236, :203-216, :230-235); DependencyInjection.Caching.cs factory :79-99 (from :75-96); registrations MMCA.ADC.Identity.Application/DependencyInjection.cs:43 (from :41) and MMCA.Store.Identity.Application/DependencyInjection.cs:48 (from :47); DeleteUserHandlerBase.cs summary :22-25 (from :19-22), best-effort remarks :29-37 (from :30-34), ordering remarks :40-43 (from :37-40), refresh-store documentation :72-78 (from :66-72), IRefreshSessionStore :100 (from :78), hook :159 (from :137), Anonymize :166 (from :144), RevokeAndAnonymizeAllAsync :177-179 (from :155-157), SaveChangesAsync :206 (from :159), marker try/catch :212-219 (from :165-174), log :218 (from :173), afterCommit loop :221-224 (from :176-179), erasure-tail summary :240 (from :195), afterCommit documentation :245-252 (from :200-207), SoftDeletedMarkerFailed :265-266 (from :220-221); ADC DeleteUserHandler.cs remarks :28-32 (from :27-31), base call :44 (from :40), UserDeleted :70 (from :64), schedule :79-82 with the call :81 (from :66-76, :75), ScheduleAvatarBlobDeletionAsync :87-97 (from :81-91); Helpdesk Program.cs:170 (from :149); tests :169, :194, :211, :229, :251, :270, :298, :321, :347, :370-374, :379, :397, :404, :426, :450 (each 24 lines later than before). Unchanged and re-checked: WebApplicationExtensions.cs :49, :171, :173, MiddlewarePipelineStepNames.cs:59, MiddlewarePipelineBuilder.cs :104, :112, :120, :124, ICacheService.cs:69-70, ISoftDeletedUserValidator.cs:7,15, SoftDeletedUserValidator.cs:20-36, tests :25, :44, :68, :88, :106, :127.