docs(70): re-derive the stale-claim fix by grep instead of working the review's list
Round-3 review returned BLOCKED: must-fix (b) was not closed. It was right, and the root cause it named is the point of this commit — the previous correction "was scoped to the four sites the reviewer listed rather than re-derived by grep". Fixing the list is not fixing the class. That is the same failure as B1, where the gate covered the two writers already in hand and missed CreateChannelFromLineup. Re-grepped the behavior class instead. Three survivors, two of them missed and one freshly introduced by the correction itself: - CreateMultiCollectionHandler.cs — the create twin of a comment whose UPDATE twin I corrected and whose create twin I never opened. Present tense, and contradicted by two tests in this same PR. - decisions.md — corrected one line in that file and left its sibling. - MultiCollectionItemWeight.cs (and its decisions.md mirror) — the ceiling rationale still claimed unbounded weights overflow the sum. They cannot: EffectiveWeight clamps before every sum and CycleLength widens to long. The earlier pass pattern-matched on the word "filtered" and left the identical defect on the ceiling. The ceiling's real job is the floor's argument — a billion is not a share of airtime any more than 0 is — so it now says that, and credits the clamp with the arithmetic safety it actually provides. Also corrected the writer claim to the right predicate: not "two persisting writers" (Add*ToPlaylist and Trakt persist it too, hardcoded) but two writers that persist a CALLER-SUPPLIED order. The full set is now classified persists-caller-value / persists-hardcoded / in-memory, including Engine/PlaylistHelper, which the previous "two Preview handlers" phrasing missed. That bullet has been wrong three times in the same shape; it now says so, since a lesson that keeps being re-learned is worth recording as a pattern rather than a fact. The BOM check caught this commit re-adding a BOM to the one file patched with utf-8-sig — the same trap, an hour after writing it down. Stripped; the mechanical pre-push check is what makes that survivable. Core.Tests 566, ErsatzTV.Tests 1673, 0 failed. Format verify exit 0. decisions.md +90/-0 (append-only guard green). Refs #70 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -92,8 +92,11 @@ public class CreateMultiCollectionHandler :
|
||||
.ToList()
|
||||
});
|
||||
|
||||
// Bounds are shared with the update path so the two cannot drift: an out-of-range weight silently
|
||||
// removes the source from the rotation (0) or overflows the rotation arithmetic (huge). See #70.
|
||||
// Bounds are shared with the update path so the two cannot drift -- they silently disagreed before #402:
|
||||
// EF's HasDefaultValue substitutes 1 for a 0 on INSERT (0 reads as "not set") while an UPDATE writes the 0
|
||||
// through, so the same input landed differently depending on the verb. The enumerator clamps out-of-range
|
||||
// weights, so neither a 0 nor a huge value can reach the rotation; this gate refuses input that has no
|
||||
// meaning on a share-of-airtime scale, and keeps create and update honest with each other. See #70.
|
||||
private static Validation<BaseError, Unit> ValidateWeights(CreateMultiCollection request) =>
|
||||
request.Items.All(i => MultiCollectionItemWeight.IsValid(i.Weight))
|
||||
? Unit.Default
|
||||
|
||||
@@ -11,9 +11,12 @@ namespace ErsatzTV.Core.Domain;
|
||||
/// belt-and-braces, not duplicates — <b>neither is redundant</b>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The ceiling keeps the rotation arithmetic in range: the enumerator sums weights and scales the rotation
|
||||
/// by <c>items * totalWeight / weight</c>, and unbounded values overflow that sum (checked arithmetic, so it
|
||||
/// throws) inside a playout build.
|
||||
/// The ceiling is the same argument as the floor, not an arithmetic guard. A weight of a billion is not a
|
||||
/// share of airtime any more than 0 is, so it is refused at the boundary rather than silently reinterpreted.
|
||||
/// The rotation arithmetic is made safe by <c>EffectiveWeight</c>'s clamp (and by <c>CycleLength</c> summing
|
||||
/// to <c>long</c>) — <b>not</b> by this constant: with the clamp in place a sum cannot overflow whatever the
|
||||
/// stored value is, which is exactly why a row that predates this gate is still safe.
|
||||
/// <c>An_Enormous_Weight_Does_Not_Overflow_The_Rotation</c> pins that.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class MultiCollectionItemWeight
|
||||
|
||||
+26
-15
@@ -1451,22 +1451,33 @@ and "no single show dominates" — as **one** order, because fair-share is the e
|
||||
orders by *name*, so `Enum.Parse` accepts it regardless) log a warning when an order falls through
|
||||
unhandled. Making those pre-existing fallbacks loud is a real but separate defect class: **#403**, an
|
||||
explicit non-goal here.
|
||||
- **There are TWO persisting writers of `PlaylistItem.PlaybackOrder`, and the second is not obvious.**
|
||||
`ReplacePlaylistItems` is the expected one; **`CreateChannelFromLineup`** is the other — a lineup of 2+
|
||||
entries is stored as a `Playlist`, and its own guard only covered *MultiCollection* entries, so a
|
||||
multi-entry lineup of plain collections slipped `WeightedShuffle` straight through to
|
||||
`PlaylistEnumerator`'s null-drop. (`ReplaceBlockItems` is the separate writer of
|
||||
`BlockItem.PlaybackOrder`; `Add*ToPlaylist` and the Trakt path are safe only because they hardcode their
|
||||
order, and the two Preview handlers build in memory without persisting.) Caught by adversarial review of
|
||||
PR #402 **after** the first gates were written and this very bullet had recorded the perimeter as
|
||||
complete — twice, since the correction itself first miscounted the writers by conflating the two fields.
|
||||
Before trusting any "this order can't reach that engine" claim, grep every writer of **each field
|
||||
separately**; the non-obvious composite handler is the one that gets missed.
|
||||
- **Exactly two writers persist a CALLER-SUPPLIED `PlaylistItem.PlaybackOrder`, and the second is not
|
||||
obvious.** `ReplacePlaylistItems` is the expected one; **`CreateChannelFromLineup`** is the other — a
|
||||
lineup of 2+ entries is stored as a `Playlist`, and its own guard only covered *MultiCollection* entries,
|
||||
so a multi-entry lineup of plain collections slipped `WeightedShuffle` straight through to
|
||||
`PlaylistEnumerator`'s null-drop. Both are gated. The full writer set, since "persisting writer" alone is
|
||||
the wrong axis: `Add*ToPlaylist` and `TraktCommandBase` **do** persist the field but hardcode it
|
||||
(`Shuffle`/`Chronological`), so no caller value reaches them; `ReplaceBlockItems` writes the *different*
|
||||
field `BlockItem.PlaybackOrder` (also gated); and `PreviewPlaylistPlayout`, `PreviewBlockPlayout` and
|
||||
`Engine/PlaylistHelper` build in memory without persisting.
|
||||
**This bullet has now been wrong three times, each time in the same shape**: it recorded the perimeter as
|
||||
complete when the gate covered only the writers already in hand (missing `CreateChannelFromLineup`); the
|
||||
first correction miscounted by conflating `PlaylistItem` with `BlockItem`; the second said "two persisting
|
||||
writers" when the true predicate is *two writers that persist a caller-supplied order*. The failure is
|
||||
always **enumerating from a list instead of re-deriving from a grep** — which is also how the
|
||||
"0-weight is filtered out" claims survived their own correction. Before trusting any "this order can't
|
||||
reach that engine" claim, grep every writer of **each field separately** and classify each as
|
||||
persists-caller-value / persists-hardcoded / in-memory. The non-obvious composite handler is the one that
|
||||
gets missed.
|
||||
- **Weight is bounded at the write path** (`MultiCollectionItemWeight`, 1..1000) and clamped again in the
|
||||
enumerator. Both are needed: **EF's `HasDefaultValue(1)` substitutes 1 for a `0` on INSERT** (0 reads as
|
||||
"not set") **but an UPDATE writes the 0 through**, so create and update disagreed on the same input, and
|
||||
a 0-weight source was filtered out of the rotation — deleting it from the channel silently. The ceiling
|
||||
keeps `Sum(weights)` (checked arithmetic) from overflowing inside a playout build.
|
||||
enumerator (`EffectiveWeight`). They do **different** jobs, which is why both stay: **EF's
|
||||
`HasDefaultValue(1)` substitutes 1 for a `0` on INSERT** (0 reads as "not set") **but an UPDATE writes the
|
||||
0 through**, so create and update disagreed on the same input — the gate makes them agree and refuses
|
||||
values that mean nothing on a share-of-airtime scale (0, negative, or absurdly large). The **clamp** is
|
||||
what makes the rotation arithmetic safe for rows that predate the gate: it bounds every weight before the
|
||||
sum, so `Sum(weights)` cannot overflow regardless of what is stored. Historical note: an earlier revision
|
||||
of this PR *filtered* `Weight > 0` instead of clamping, which silently deleted a 0-weight source from the
|
||||
channel; the clamp replaced it, and any comment still describing that filter is stale.
|
||||
- **Weight is returned on the multi-collection GET, not just accepted on write.** The update replaces the
|
||||
item list, so a client that reads, edits a name, and writes back would silently reset every weight to the
|
||||
default if the read didn't carry it. Edits ride the existing `Version` token (If-Match/412, §7a).
|
||||
|
||||
Reference in New Issue
Block a user