Files
OrbitTv/docs/smartsetup-rotation-fix.md
pauljdandClaude Opus 5.5 2df65c098c Smart setup: the evening rotation from the plan's own time, balanced by running time (0.110.15-smartsetup, versionCode 298)
The weekly evening and late rotation read the real clock (rotationWeek() in
programmingOf), so plans depended on the day they were made, and
SmartSetupRegressionTest failed from Monday 9 November. And the weekly sets
were split by count, so one of Orbit Sakura's weeks was ten short films:
30 repeats from day 2.5 (from 16 November), against 15 from day 6.

Shaped channels now hand the planner the whole rotating list; topUpPlan
resolves it (resolveRotations) from its own time, balancing the sets by
the pool's running times (rotationSet), deterministically. Every Sakura
week is now 15-17 repeats, none before day 6. Committed plans untouched.

New tests plan every rotation week for both fixture channels; the
regression limit is 18 a week (original run: 34). Docs:
docs/smartsetup-rotation-fix.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 00:52:45 +00:00

2.9 KiB

Smart setup: evening rotation fix (9 November 2026)

Branch smartsetup-rotation-fix from story-p1000 (585ac72), version 0.110.15-smartsetup, versionCode 298. Not installed.

What was wrong

Shaped channels (smart setup, such as Orbit Sakura) rotate their evening and late-night shows weekly: at most 12 evening and 24 late shows a week, a different set each week (commit de68578, 7 November). Two problems:

  1. The week came from the clock. programmingOf called rotationWeek() with the real time, so the same plan made on a different day came out differently. SmartSetupRegressionTest (planned from a fixed Saturday, 7 November) started failing after midnight on Monday 9 November, when the rotation turned over.
  2. Sets were split by count, alphabetically. Sakura's 29 evening shows made three sets of 10, 10 and 9, but one set was ten short films (14 hours), another 116 hours of series. The thin week (from Monday 16 November) planned 30 repeats in a week, the first after 2.5 days, against 15 and 6 days in the others.

The fix

  • shapedParts no longer picks the week: it gives the planner the whole rotating list ([DayPart.rotating], with the week's cap and the slot's weekly hours). A part that borrows the evening's titles (an empty daytime) rotates with the evening.
  • topUpPlan resolves the rotation first ([resolveRotations]): the week from the plan's own time (rotationWeek(nowMs, zone), which no longer has a clock default), and the sets balanced by running time from the real pool ([rotationSet]): longest first into the lightest week, each show counting at most the hours its slot runs in a week. Deterministic: the same titles, pool and week always give the same set.
  • CustomChannels.programmings no longer rebuilds each week: nothing in a channel's programming depends on the date.
  • Plans already committed are untouched; new days are planned with the balanced sets.

Result (Orbit Sakura, the real Crunchyroll collection)

Week from Before After
7 Nov 15 repeats, first after 6.1 days 17, first after 6.1
9 Nov 16, 6.1 16, 6.1
16 Nov 30, 2.5 15, 6.1
23 Nov 15, 6.1 17, 6.1
30 Nov 16, 6.1 16, 6.1

Every week now has 15 to 17 repeats, all on its last day. The regression test's limit is 18 a week (it was 15 when only one week was ever measured; the original run had 34), with no repeat before day 5. Orbit Mistletoe (no evening part) is unchanged: no repeats.

Tests

  • SmartSetupRegressionTest.everyRotationWeekStaysWithinTheRepeatsAndStartsNoEarlierThanDayFive: Sakura and Mistletoe planned from eight dates across a whole turn of the rotation (Saturdays and Mondays).
  • SmartSetupRegressionTest.plansDependOnTheirOwnTimeNeverTheClock: the same plan twice, and a shaped channel's programming carries its rotation for the planner.
  • SmartSetupTest.rotationSetsAreBalancedByRunningTimeAndCoverEveryShowOnce.