--- key: concurrency.diff-scalar-fanout title: '2026-07-11 — #253 PR3: Diff + Scalar concurrency fan-out (Collection / Playout×2 / MultiCollection / RerunCollection)' status: active since: '2026-07-11' supersedes: none superseded-by: none rule: The frozen Block optimistic-concurrency recipe (api-conventions §7a) fans out to Collection/Playout×2/MultiCollection/RerunCollection, keeping a guard-returned `PreconditionFailedError` out of any handler's generic `catch(Exception)`→422 mapping, and preserving each aggregate's existing `SaveChangesAsync() > 0` gate semantics under the new unconditional `Version++`. signals: 'concurrency fan-out, PreconditionFailedError, SaveChangesWithConcurrencyGuard · paths: `api-conventions.md` §7a · issues: #253, #269, #232, #197' mechanics: '`RootWriterForceVersionTests`-adjacent handler tests; `api-conventions.md` §7a' --- **Context.** PR3 of the #253 optimistic-concurrency arc fans the frozen Block recipe (api-conventions §7a) across the five Diff/Scalar aggregates. Three judgment calls beyond the mechanical copy: **H1 — Playout `catch(Exception)`→422.** The two Playout replace handlers wrap `SaveChangesAsync` in a `catch(Exception)` that maps any exception to a bare `BaseError` (→ 422). Rather than let the guard's concurrency failure be reshaped into a 422, the guarded save (`SaveChangesWithConcurrencyGuard`) returns a `PreconditionFailedError` **Left as a value** and the handler returns it before the post-commit block — so it never reaches the catch. Proven by the pre-check-subtype tests (a `.Apply` flatten would fail `ShouldBeOfType`) plus a non-vacuous Playout racing-save test. **M2 — the `SaveChangesAsync() > 0` gates.** RerunCollection and Collection-custom-order run their playout-refresh **unconditionally** on a successful save (the unconditional `Version++` makes the old gate always-true; the "nothing changed" branch is dead). MultiCollection is the exception: it saved the name first specifically so a name-only change wouldn't rebuild playouts, so we bump `Version` on that **first** save and leave the **second** (items) save's `> 0` gate intact — a name-only edit still bumps + rotates the ETag but does not rebuild. Enumerating every behavior the gate provided before reworking it (the #232 lesson). **Sibling-writer scope (deferred).** §7a's config-only boundary says every writer of an aggregate's editor-visible config bumps `Version`. PR3 ships the five primary endpoints' full contract + the one design-named bulk writer (`UpdateDefaultDecoHandler`, safe via `.SetProperty`). It **defers** the other same-root non-bulk config writers (`UpdateCollectionHandler`, `RemoveItemsFromCollectionHandler`, `UpdatePlayoutHandler`, the `ScheduleFile` handlers) and the repository-mediated `Add*ToCollection` family. Rationale: the primary endpoints' own bump+guard fully cover the two-tab lost-update the issue targets; the deferred writers only affect cross-editor ETag *rotation*, and adding an unconditional bump to a handler that uses plain `SaveChangesAsync` (not the guard) converts a latent lost-update into a **new 500** (`DbUpdateConcurrencyException`) — doing it safely needs a uniform guard+bump+412 pass of its own, better done with the #197 contract work. Tracked as a follow-up issue. **VMs.** `Playout.Version` surfaces via `PlayoutNameViewModel` (required arg); the three collection VMs (`MediaCollectionViewModel`, `MultiCollectionViewModel`, `RerunCollectionViewModel`) carry `int Version = 0` (defaulted — 0 for the selection-placeholder constructions, real value from the Mapper projection). Header-only via ETag, never echoed in a response body (the Block precedent). **Post-merge addendum (PR3 review, #269).** Activating the `Version` token means EF guards *every* root UPDATE, so non-participating root-scalar writers that use plain `SaveChangesAsync` (playout settings / schedule-file / on-demand-checkpoint, collection name) would 500 on a concurrent bump. The realistic UPDATE writers were fixed in-PR with `ConcurrencyExtensions.SaveChangesForcingVersion` (Phase-1 force-write on conflict: adopt the stored token, retry, never revert the concurrent bump). The deferral above is re-scoped to the DELETE handlers + repository `Add*` writers only (→ #269).