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

Architecture Decision Record

ADR-144: Offline Writes and Delta Reads (Client Write Queue, Server Change Feed with Tombstones)

Status

Accepted (2026-11-12). Released in MMCA.Common v1.289.0 (MMCA.Common/CHANGELOG.md:511); the reference adopter is MMCA.ADC. Revised 2026-11-23: the reference adopter's UI calls SetBookmarkedAsync directly, its BookmarkService wrapper being gone; anchors refreshed after v1.315.0.

Context

The framework already lets a client read while offline: ILocalCacheStore keeps JSON documents on the device, over localStorage in the browser (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/BrowserLocalCacheStore.cs:6) and as files in an mmca-cache folder under the app data directory on MAUI (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Capabilities/DeviceStorage/MauiLocalCacheStore.cs:7). Writes had no such path. A client write is an HTTP call through HttpResultExecutor, which turns a request that never got an answer into an Http.TransportFailure or Http.Timeout failure (ADR-013); with the device offline, every write failed and the user's intent was lost. The reference adopter makes this concrete: an attendee in a conference hall with no signal taps the star on a session and the bookmark never reaches the server.

A client that keeps a local copy also needs to bring it up to date cheaply when it reconnects. The list endpoints answer "what exists now", which forces a full re-read and cannot report a row that was deleted, because the soft-delete query filter hides it (ADR-005).

Three existing decisions shape the answer. ADR-017 makes idempotency a per-action opt-in through [Idempotent] (MMCA.Common/Source/Presentation/MMCA.Common.API/Idempotency/IdempotentAttribute.cs:15-16): a request to such an action that carries a client-minted Idempotency-Key is answered from a replay cache kept 24 hours by default (MMCA.Common/Source/Presentation/MMCA.Common.API/Idempotency/IdempotencySettings.cs:16), so the same request sent twice runs once. ADR-035 round-trips a RowVersion as a weak ETag in If-Match, so a write based on stale data answers 412. ADR-136 puts a service worker in front of the installable web app and has it never cache a page or a response, because server-rendered pages carry the signed-in user's data.

Decision

MMCA.Common ships two opt-in pieces: a durable client-side write queue in MMCA.Common.UI, and a server change feed on EntityControllerBase that returns the rows changed since a point in time with soft-deleted rows as tombstones. Neither is wired by the framework itself (MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:411, MMCA.Common/Source/Presentation/MMCA.Common.API/Pagination/SupportsChangeFeedAttribute.cs:7).

The client write queue

  1. Registration. AddOfflineWriteQueue(configure) registers IOfflineWriteQueue as OfflineWriteQueue, scoped, and TimeProvider.System unless one is registered (MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:417-418). In the browser hosts the connectivity service and local store the queue reads are scoped too (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DependencyInjection.cs:113, :115); the MAUI head registers its local store as a singleton (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:63). AddOfflineWriteHandler<THandler>() adds one scoped IOfflineWriteHandler per write kind, and registering the same type again adds nothing (MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:438). The queue indexes handlers by an ordinal match on Kind, the first registered for a kind winning (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:57, :98-101).

  2. Storage on each head. The whole queue is one List<PendingWrite> under OfflineWriteQueueOptions.StorageKey, default mmca.offline-writes (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueueOptions.cs:7), kept in the device's ILocalCacheStore, and the queue is available wherever the host registered a device store: its IsAvailable is the store's (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:113). Three cases follow from the registrations. With the default NullLocalCacheStore, which AddUIShared registers only when nothing else did (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DependencyInjection.cs:61), IsAvailable is false (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/NullLocalCacheStore.cs:7) and EnqueueAsync answers OfflineWrites.Unavailable (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:130-134). A host that calls AddBrowserDeviceCapabilities gets BrowserLocalCacheStore (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DependencyInjection.cs:115), whose IsAvailable is true (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/BrowserLocalCacheStore.cs:20): browser localStorage behind the mmca.localCache. key prefix (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/BrowserLocalCacheStore.cs:12), reached through JS interop. The composed Blazor web-host call makes that call after AddUIShared (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:107-109), so this case covers WebAssembly and a Blazor Server circuit alike: on a server circuit the writes are kept in the browser's storage, and the queue works only while the circuit is up, because every read and write crosses that circuit's JS interop and a disconnected one answers nothing (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/CapabilitiesJsModule.cs:41-44). On MAUI the store is MauiLocalCacheStore, a file under the app data directory (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Capabilities/DeviceStorage/MauiLocalCacheStore.cs:7, MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:63). Every change re-reads, edits and writes the list back under one SemaphoreSlim and raises PendingChanged (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:449-473); the semaphore belongs to one queue instance (:62), so it serializes the callers of that instance only (see Trade-offs).

  3. The pending write. PendingWrite carries Kind, IdempotencyKey, BasedOnRowVersion, PayloadJson (serialized with JsonSerializerOptions.Web), CoalesceKey, UserScope, EnqueuedOn and Attempts (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/PendingWrite.cs:15-40). The caller supplies the idempotency key, the row version and the coalesce key through OfflineWriteOptions, all optional (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteOptions.cs:7-14); with no key the queue mints a GUID in N form (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:140). A row version is rendered as the ADR-035 weak ETag for If-Match (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/PendingWrite.cs:47).

  4. Per-user scoping. Each write is stamped with the signed-in user's id, read afresh from the AuthenticationStateProvider (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:144, :493-499). Listing, cancelling and replaying see only the current user's writes, oldest first (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:254-257). A local sign-out clears the whole local store, and with it every user's queued writes (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthUIService.cs:542, :599).

  5. The coalesce key. CancelPendingAsync(coalesceKey) removes every queued write of the current user with that key (ordinal) and raises no WriteSettled (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/IOfflineWriteQueue.cs:40-44, MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:193-208).

  6. The cap. MaxPendingWrites defaults to 200 (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueueOptions.cs:17); an enqueue past it answers OfflineWrites.QueueFull (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:152-155, :173-176). MaxAge defaults to 24 hours (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueueOptions.cs:10-14), the same as the server's default idempotency window (MMCA.Common/Source/Presentation/MMCA.Common.API/Idempotency/IdempotencySettings.cs:16); the two are separate settings. A pass removes as Expired, unsent, a write older than MaxAge at the start of the pass (item 8), which keeps a replay inside the server's window except at its edge (see Trade-offs).

  7. When it replays. ReplayAsync does nothing unless the store is available, the device is online and no other replay is running: a compare-exchange makes it single flight (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:213-216). A replay starts in three situations: the queue starts one, unawaited, whenever connectivity changes to online (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:501-520); OfflineWriteNotifier runs one on its first interactive render while online (MMCA.Common/Source/Presentation/MMCA.Common.UI/Components/Capabilities/OfflineWriteNotifier.razor:33-54), and Common's MainLayout already hosts that component (MMCA.Common/Source/Presentation/MMCA.Common.UI/Layout/MainLayout.razor:85); and the queue retries by itself (item 9).

  8. What a handler returns and what each outcome does. IOfflineWriteHandler.ReplayAsync sends the write with its idempotency key (and If-Match when set) and returns the server's answer as a Result (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/IOfflineWriteHandler.cs:14-23). A pass walks the user's writes oldest first, and before it expires or sends one it re-checks under the semaphore that the write is still stored, skipping one that left the store since the pass read it (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:293-354, :307-310, :476-487):

    • older than MaxAge: removed as Expired without being sent (:312-317);
    • no handler for its kind in this app: skipped and kept (:319-323);
    • success: removed as Completed (:265-268);
    • a transport failure, a timeout, or an Unexpected, TooManyRequests or Unauthorized error, or a handler that throws any exception other than a cancellation: kept with Attempts incremented, and the pass stops (:280-283, :335-347);
    • a handler that throws OperationCanceledException: rethrown, so the pass ends without counting an attempt (:330-333) and the next retry is still scheduled (:227-232, :365-369);
    • any other Conflict: removed as Conflict; any other failure: removed as Rejected (:275-277).

    The transient check runs before the conflict check (:270 before :275). A settled write leaves the store first, then WriteSettled fires (:424-428), and OfflineWriteNotifier turns it into a toast: a warning for Conflict and Expired, an error for Rejected, and a success toast for Completed only when ShowCompleted is set (MMCA.Common/Source/Presentation/MMCA.Common.UI/Components/Capabilities/OfflineWriteNotifier.razor:30, :88-104). The outcomes are the OfflineWriteOutcome enum (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteOutcome.cs:4-16).

  9. The self-retry while online. The queue holds at most one retry timer on the injected TimeProvider (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:383-394). It is set after a write with a registered handler is queued (:162-171) and after a pass that stopped on a transient failure or threw (:361-369). The first delay is 5 seconds (:50); it doubles after each pass that settled nothing, capped at 5 minutes (:53, :285-286), and returns to 5 seconds after a pass that settled a write (:367). A pass that leaves nothing to retry removes the timer, unless a replayable write was queued while it ran (:370-378). The timer is never created while the device reports offline (:385), and going offline removes it (:508-516), so an empty queue or an offline device holds none.

The server change feed

  1. Opt-in per controller. EntityControllerBase.GetChangesAsync serves GET {controller}/changes?since=&cursor=&pageSize= (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/EntityControllerBase.cs:456-465). Its [OptInAction(typeof(SupportsChangeFeedAttribute))] (:457) removes the action from the application model unless the controller carries [SupportsChangeFeed] (MMCA.Common/Source/Presentation/MMCA.Common.API/Pagination/OptInActionAttribute.cs:24-33), so a controller that did not opt in has no route and an unchanged API document (MMCA.Common/Source/Presentation/MMCA.Common.API/Pagination/OptInActionAttribute.cs:11-13). The attribute is inherited, so declaring it on an abstract base controller opts in every derived one (MMCA.Common/Source/Presentation/MMCA.Common.API/Pagination/SupportsChangeFeedAttribute.cs:10, :13).
  2. Paging. pageSize defaults to 100 and is clamped to the controller's MaxPageSize (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/EntityControllerBase.cs:464, :467). The query service reads one keyset page over LastModifiedOn ascending through GetPageByCursorAsync, with Id as the tie-break (MMCA.Common/Source/Core/MMCA.Common.Application/Services/EntityQueryService.cs:571-572, :584-591), and returns a KeysetCollectionResult<EntityChange<TEntityDTO, TIdentifierType>> with the next cursor (:610).
  3. The since bound. The bound is inclusive: ChangeFeedSpecification filters LastModifiedOn >= since and omits the bound when since is null (MMCA.Common/Source/Core/MMCA.Common.Application/Services/Query/ChangeFeedSpecification.cs:36-41). A local value is converted to UTC and an unspecified one taken as UTC (MMCA.Common/Source/Core/MMCA.Common.Application/Services/EntityQueryService.cs:614-620). A client pages with one since until the cursor is null, then keeps the largest changedOn as its next since; boundary rows come again and are applied idempotently by id and row version (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/EntityControllerBase.cs:448-450).
  4. Tombstones. The specification lifts the soft-delete filter (MMCA.Common/Source/Core/MMCA.Common.Application/Services/Query/ChangeFeedSpecification.cs:30). Each row becomes an EntityChange with Id, IsDeleted, ChangedOn (LastModifiedOn, else CreatedOn) and Item; only live rows are mapped, so a tombstone carries no field of the deleted row (MMCA.Common/Source/Core/MMCA.Common.Application/Services/EntityQueryService.cs:597-608).
  5. Scope stays in force. The rows are ANDed with the controller's GetReadSpecificationAsync scope (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/EntityControllerBase.cs:469-471, MMCA.Common/Source/Core/MMCA.Common.Application/Services/Query/ChangeFeedSpecification.cs:44-54), and only the soft-delete filter is lifted, so the tenant filter and every other global filter stay in force (MMCA.Common/Source/Core/MMCA.Common.Application/Services/Query/ChangeFeedSpecification.cs:9-11).
  6. A query service that predates it. IEntityQueryService.GetChangesSinceAsync has a default body that fails with Query.ChangeFeedNotSupported (Unexpected, 500) (MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/Mapping/IEntityQueryService.cs:34, :198, :212-213), so a custom query service learns of the feed by answering 500 rather than returning wrong data.

Rationale

  • The queue reuses the stores the client already has. Offline reads already put JSON documents in ILocalCacheStore on both heads, so the queue is one more document in the same store and works wherever offline reads do, with no second persistence stack on the device.
  • Idempotency keys make a replay safe without a sync protocol. A write that may already have reached the server is resent with the same key, and ADR-017 answers it from the replay cache instead of running it twice. The queue's MaxAge and the server's replay window are separate settings, both 24 hours by default, so a replay falls inside the window except in the narrow case under Trade-offs. A stale edit carries its row version and gets ADR-035's 412, which the queue reports as Conflict instead of overwriting.
  • The handler owns the meaning of a failure. Only the app knows that "already bookmarked" is a success for an add. The queue's classification covers the general case (transient keeps, conflict and refusal discard) and leaves domain equivalences to the handler.
  • The change feed is a read over data the framework already stamps. LastModifiedOn and IsDeleted exist on every auditable entity, so the feed needs no new column, no change log table and no migration, and it reuses keyset paging and the read scope that the list endpoints already enforce.
  • Opt-in on both sides. A consumer that registers nothing and declares no attribute sees no new service, no new route and no change to its API document.

Trade-offs

  • MaxPendingWrites counts every user's queued writes on the device, not the current user's: the cap check reads the whole list (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:152). A local sign-out wipes the whole store, every user's backlog with it (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthUIService.cs:542, :599), and that clear is best-effort (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthUIService.cs:590-605). Another user's writes therefore count against the cap only after a session that ended without that sign-out or whose clear failed; such a backlog can refuse the next user's enqueue, and since a pass reads only the current user's writes (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:296), it neither drains nor expires until its own user signs in again.
  • Only a transport failure falls back to the queue in the reference adopter. A timeout, a 429 or a 5xx on the online attempt is returned to the caller as a failure, not queued (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:215-217), even though the queue would keep such an error on replay. Which errors queue is the adopter's choice; the framework does not decide it.
  • Both device stores are best-effort. On MAUI MauiLocalCacheStore.SetAsync swallows an IOException or an UnauthorizedAccessException (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Capabilities/DeviceStorage/MauiLocalCacheStore.cs:27-34). In the browser storageSet catches a failed localStorage.setItem, a full quota included, and returns false (MMCA.Common/Source/Presentation/MMCA.Common.UI/wwwroot/capabilities-interop.js:141-148), BrowserLocalCacheStore.SetAsync ignores that result (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/BrowserLocalCacheStore.cs:27-30), and the interop wrapper turns an unavailable interop, a JSDisconnectedException or a JSException into a default answer (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/CapabilitiesJsModule.cs:36-48). Either way a failed write loses the queued write while EnqueueAsync still reports success (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:149-176). The browser store is bounded by localStorage's quota of roughly 5 MB (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/BrowserLocalCacheStore.cs:7-8).
  • The semaphore serializes the callers of one queue instance only (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:62, :452). Several browser tabs or circuits share one storage key with one queue instance each, so their read-modify-write cycles can overwrite each other and lose a write. And a read failure that a store swallows comes back as an empty list (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Capabilities/DeviceStorage/MauiLocalCacheStore.cs:53-64, MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DeviceStorage/BrowserLocalCacheStore.cs:50-53, MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:489-490), so the next change writes that list back (:455-459) and drops the rest of the queue.
  • Newest intent wins only over a write the pass has not started sending. A pass skips an entry that left the store after the pass read it (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:307-310), but CancelPendingAsync does not wait for a running pass (:193-208), so a write cancelled while its own request is in flight still lands; the next intent, issued in full, is what corrects the server.
  • A replay can reach the server just after it forgot the key. The server stores its replay entry after the action runs, for CacheExpirationHours (MMCA.Common/Source/Presentation/MMCA.Common.API/Idempotency/IdempotencyFilter.cs:442-450), the failed online attempt runs before the queued write's EnqueuedOn is stamped (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:145), and a pass measures age once, at its start (:297). So with the two windows equal, a write near the edge of MaxAge can go out after the server evicted its key and run again unless the action refuses the duplicate itself, and a host that sets the server window (MMCA.Common/Source/Presentation/MMCA.Common.API/Idempotency/IdempotencySettings.cs:15-16) below MaxAge widens that gap.
  • A pass stops at the first transient failure, so one write that keeps failing transiently holds back every later write of the same user until it settles or reaches MaxAge.
  • Rows with no last-modified time are invisible to a time-bounded feed. LastModifiedOn >= since never matches a null LastModifiedOn (MMCA.Common/Source/Core/MMCA.Common.Application/Services/Query/ChangeFeedSpecification.cs:41), so a row written before the framework stamped LastModifiedOn on insert appears only in a full read (since null), where its ChangedOn falls back to CreatedOn (MMCA.Common/Source/Core/MMCA.Common.Application/Services/EntityQueryService.cs:605).
  • The since bound trusts the application clock. LastModifiedOn is stamped from the application's clock when SaveChanges runs, not when the transaction commits (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Persistence/Interceptors/AuditSaveChangesInterceptor.cs:65, :83, :94). With the largest changedOn as the next since, a row committed after a client read past its stamp, or stamped by a host whose clock runs behind, falls below that client's since and is missed until its next full read.
  • A row that leaves the read scope without being deleted yields no tombstone (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/EntityControllerBase.cs:453). A client that cached it keeps it until its next full read.
  • A hard delete yields no tombstone. The audit interceptor stamps only added and modified rows and leaves an EntityState.Deleted row alone (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Persistence/Interceptors/AuditSaveChangesInterceptor.cs:101), and a row that is gone cannot match the feed, so only a soft delete is reported; a client that cached a hard-deleted row keeps it until its next full read.
  • The feed is time-based, not a log. It reports the latest state of each changed row, not each intermediate change, and depends on LastModifiedOn being stamped by the save path; a write that bypasses the audit stamping is not reported.
  • Nothing here was exercised on a physical device. The queue, the notifier and the reference adopter are covered by tests and builds only; a device run (airplane mode on a phone, an installed web app going offline) has not been performed.

The rule an adopter must follow, learned in the reference adopter: the newest intent for a key wins over every queued write not yet in flight, and it is always issued in full. On every new intent the adopter cancels the pending writes under the coalesce key FIRST, then sends or queues the new intent as a complete write of its own; it never cancels the queued write and stops. Cancelling removes a queued write that a replay pass has not started sending (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:307-310), but a write whose own request is already in flight still lands, and a write queued after a transport failure may already have reached the server, so cancelling it locally does not undo it: the opposite intent must still reach the server (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:86-91). Two companion rules follow from the same fact: a queued create reuses the idempotency key of the failed online request it replaces, chosen before the online attempt (:93-96, :202), and a device that already reports offline queues at once rather than spending the retry budget on a request that cannot leave it (:98-103). A queued delete carries no key of its own (:204-208): the queue mints one (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:140) that the delete handler does not send, and neither the online nor the replayed delete sends a key (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkApiClient.cs:84, MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkDeleteReplayHandler.cs:57); a repeated delete is safe because a bookmark the server no longer has counts as done (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkDeleteReplayHandler.cs:58, MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:181).

Alternatives rejected

  • An embedded SQLite store on the device (weighed 2026-11-12). It would give the queue transactions and queries, but it is a second persistence stack on the client beside ILocalCacheStore, with its own native dependency on MAUI and a WebAssembly build of its own in the browser, for a queue that holds at most a few hundred small documents. Revisit when a consumer needs offline writes that must query or join locally queued data, or when the queue outgrows the browser's localStorage quota.
  • Letting the service worker queue requests (Background Sync style, weighed 2026-11-12). ADR-136 keeps the worker to GET navigations and has it never cache a page or a response; a worker that stores request bodies carrying the user's data and replays them outside the app would break that rule, would exist only in the browser (the MAUI head has no worker), and could not attach a fresh bearer token or classify a Result. Revisit if ADR-136 is superseded by a worker that is allowed to hold user data.
  • Free-form replay without idempotency keys (weighed 2026-11-12). A write that died in transit may have reached the server, so resending it without a key can run it twice (a duplicate create, a double toggle). The key is what makes "resend until answered" safe. Revisit never for non-idempotent writes; a handler whose write is naturally idempotent (a PUT of a full state) may still pass any key.
  • A full sync protocol (client-side change tracking, server-side conflict resolution and merge, weighed 2026-11-12). It solves conflicts the framework does not have: the queue holds short-lived user intents, a conflict is reported through ADR-035's 412 rather than merged, and the change feed covers the read side. Revisit when a consumer needs multi-device offline editing of the same record with automatic merge.

Consequences

An adopter adds, using ADC's bookmark toggle as the worked example:

  1. Register the queue and one handler per write kind. ADC's Engagement UI calls AddOfflineWriteQueue() and AddOfflineWriteHandler<>() for BookmarkCreateReplayHandler and BookmarkDeleteReplayHandler (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/DependencyInjection.cs:42-44).
  2. Name versioned kinds and a coalesce key. Engagement.Bookmark.Create.v1 and Engagement.Bookmark.Delete.v1 are versioned because a queued write can outlive an app update, and the coalesce key bookmark:{userId}:{sessionId} pairs one user's toggles of one session (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkOfflineWrites.cs:13, :16, :22-23).
  3. Route every write through one place that applies the newest-intent rule. SessionBookmarkUIService.SetBookmarkedAsync cancels the pending writes for the key, mints the create's key before the online attempt, queues at once when offline, and otherwise falls back to the queue only on a transport failure (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:79-135). The Conference UI calls that toggle directly for both writes (MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.UI/Pages/Public/Sessions/PublicSessionListView.razor.cs:164, :186, MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.UI/Pages/Public/Sessions/SessionBookmarkButton.razor.cs:122), so every new intent first removes each queued write of the same user and session that a replay pass has not started sending; one already in flight still lands (see Trade-offs). The same interface also exposes DeleteBookmarkAsync (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.Shared/UserSessionBookmarks/ISessionBookmarkUIService.cs:32), which deletes online without cancelling queued writes (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:63-76); its only caller is the toggle's own remove path (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:180), so a caller that went around the toggle would skip the newest-intent rule. A write the queue refuses is returned as a failure, never as queued (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:210-212).
  4. Write each handler to map domain equivalences to success. The create handler resends with the queued key and treats UserSessionBookmark.Duplicate as done, since the star already exists (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkCreateReplayHandler.cs:45-52). The delete handler resolves a missing bookmark id through the session-ids read and counts a bookmark the server does not have, or a 404, as done (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkDeleteReplayHandler.cs:40-65). Both return every other failure unchanged so the queue classifies it.
  5. Expose a change feed scoped to the caller. BookmarksController derives from ApiControllerBase, not EntityControllerBase, so it serves its own GET bookmarks/changes (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.API/Controllers/BookmarksController.cs:37, :120, :125): behind the OwnerOrAdminFilter (:121), with a required userId (:126), a page clamped to 500 (:46, :135), and a scope of that user's rows passed to the same GetChangesSinceAsync (:132, :136). An EntityControllerBase controller gets the same feed by declaring [SupportsChangeFeed].

What to watch: the cross-user cap on shared devices, a write held back behind a transient failure until MaxAge, rows with no LastModifiedOn in a time-bounded feed, and the first physical-device run of the offline path.

Revision (2026-11-23)

Re-verified against current source. The decision is unchanged: the client write queue, its registration, storage, scoping, coalescing, cap, replay triggers, outcome classification and self-retry, and the server change feed with its paging, inclusive since bound, tombstones and read scope all hold as written. What moved is the reference adopter's UI, and the line numbers in most cited files.

  1. The adopter's BookmarkService wrapper is gone. The Conference UI calls ISessionBookmarkUIService.SetBookmarkedAsync directly for both the add and the remove (MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.UI/Pages/Public/Sessions/PublicSessionListView.razor.cs:164, :186, MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.UI/Pages/Public/Sessions/SessionBookmarkButton.razor.cs:122), so Consequences item 3 now cites those call sites. The interface still exposes DeleteBookmarkAsync (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.Shared/UserSessionBookmarks/ISessionBookmarkUIService.cs:32), which deletes online without calling CancelPendingAsync (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/SessionBookmarkUIService.cs:63-76); its only caller is the toggle's remove path (:180), and item 3 now says so.
  2. Anchors re-verified against current source: MMCA.Common/CHANGELOG.md:511 (the v1.289.0 entry); MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:411, :417-418, :438; MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Capabilities/DependencyInjection.cs:61, :113, :115; MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:107-109; MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:63; MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/OfflineWriteQueue.cs:50, :53, :57, :62, :98-101, :113, :130-134, :140, :144, :145, :149-176, :152-155, :162-171, :173-176, :193-208, :213-216, :227-232, :254-257, :265-268, :270, :275-277, :280-283, :285-286, :293-354, :296, :297, :307-310, :312-317, :319-323, :330-333, :335-347, :361-369, :367, :370-378, :383-394, :385, :424-428, :449-473, :452, :455-459, :476-487, :489-490, :493-499, :501-520, :508-516; MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Offline/IOfflineWriteQueue.cs:40-44; MMCA.Common/Source/Presentation/MMCA.Common.UI/Layout/MainLayout.razor:85; MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthUIService.cs:542, :590-605, :599; MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/EntityControllerBase.cs:448-450, :453, :456-465, :457, :464, :467, :469-471; MMCA.Common/Source/Core/MMCA.Common.Application/Services/EntityQueryService.cs:571-572, :584-591, :597-608, :605, :610, :614-620; MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/Mapping/IEntityQueryService.cs:198, :212-213; MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/DependencyInjection.cs:42-44; MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.UI/Services/Bookmarks/BookmarkCreateReplayHandler.cs:45-52; MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.API/Controllers/BookmarksController.cs:37, :46, :120, :121, :125, :126, :132, :135, :136.