fix(api): interleave album candidate-window anchors so recent media gets windows #1273

Merged
chris merged 2 commits from fix/album-window-recent-first into main 2026-10-16 22:56:28 +02:00
Owner

Summary\n- Learned-path candidate windows were generated oldest-media-first and hard-capped at MAX_WINDOWS_PER_RUN = 500. On a real 21k-media library the last run produced exactly 500 windows covering 1972–2017 only — zero windows for 2018–2026. Because a trained model is active, the deterministic candidates are discarded entirely and suggestions are materialized only from learned windows, so recent photos could never become an album suggestion (verified in production: user's photos from 2026-10-16 produced no suggestion).\n- Anchor selection now interleaves newest/oldest ([t(n-1), t0, t(n-2), t1, …]) instead of walking strictly oldest→newest, so both ends of the timeline get windows under the cap. Window membership, kinds, gap rules, caps, dedup, and round-robin logic are unchanged; adaptive_gap segments are still derived from time-ordered points (36h rule intact) and only their emission is interleaved.\n- Feature batch sent to the ML worker: ordering flipped to starts_at DESC, id DESC (worker scores rows independently, so order carries no semantics) — documents/ensures that if the window cap and batch limit ever diverge, OLD windows drop out of scoring, never the newest ones (which would reintroduce this bug).\n\n## Validation\n- rtk ./gradlew :apps:api:test --tests '*AlbumSuggestion*' --tests '*AlbumShape*' → BUILD SUCCESSFUL, 82 tests, 0 failures.\n- New regression test candidateWindowCapInterleavesAnchorsSoNewestAndOldestMediaGetWindows: weekly media 1995–2026 (1,635 items, ≫500 candidates) asserts a same_day window at the newest AND oldest capture instant, with the cap still exactly 500. No existing test asserted the old ordering.\n\n## Known limitation (tracked)\n[KNOWN_ISSUES ISSUE-166] A single day with >500 photos produces no window at all (oversized windows are dropped, not trimmed) — out of scope here.

## Summary\n- Learned-path candidate windows were generated **oldest-media-first** and hard-capped at `MAX_WINDOWS_PER_RUN = 500`. On a real 21k-media library the last run produced exactly 500 windows covering **1972–2017 only — zero windows for 2018–2026**. Because a trained model is active, the deterministic candidates are discarded entirely and suggestions are materialized only from learned windows, so **recent photos could never become an album suggestion** (verified in production: user's photos from 2026-10-16 produced no suggestion).\n- Anchor selection now **interleaves newest/oldest** (`[t(n-1), t0, t(n-2), t1, …]`) instead of walking strictly oldest→newest, so both ends of the timeline get windows under the cap. Window membership, kinds, gap rules, caps, dedup, and round-robin logic are unchanged; `adaptive_gap` segments are still derived from time-ordered points (36h rule intact) and only their emission is interleaved.\n- Feature batch sent to the ML worker: ordering flipped to `starts_at DESC, id DESC` (worker scores rows independently, so order carries no semantics) — documents/ensures that if the window cap and batch limit ever diverge, OLD windows drop out of scoring, never the newest ones (which would reintroduce this bug).\n\n## Validation\n- `rtk ./gradlew :apps:api:test --tests '*AlbumSuggestion*' --tests '*AlbumShape*'` → BUILD SUCCESSFUL, 82 tests, 0 failures.\n- New regression test `candidateWindowCapInterleavesAnchorsSoNewestAndOldestMediaGetWindows`: weekly media 1995–2026 (1,635 items, ≫500 candidates) asserts a `same_day` window at the newest AND oldest capture instant, with the cap still exactly 500. No existing test asserted the old ordering.\n\n## Known limitation (tracked)\n[KNOWN_ISSUES ISSUE-166] A single day with >500 photos produces no window at all (oversized windows are dropped, not trimmed) — out of scope here.
fix(api): interleave album candidate-window anchors so recent media gets windows
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 5s
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 10m32s
921b8d66d6
Production run with a trained model active and 21k+ eligible media produced
exactly 500 candidate windows covering only 1972-2017; because suggestions
are materialized only from learned (scored) windows, media from 2018-2026
could never become an album suggestion.

Anchor selection for candidate-window generation now consumes eligible
points alternately newest-first / oldest-first (meeting in the middle) for
the per-point anchored kinds (same_day, weekend, rolling 3/7/14). Adaptive
gap segments are still derived from time-ordered points (the 36h gap rule
requires it) but their per-segment windows are emitted with the same
newest/oldest interleave. Window kinds, membership, gap rules, caps, dedup
and the persisted schema are unchanged.

The ML feature-batch query keeps LIMIT = MAX_WINDOWS_PER_RUN == the cap so
all persisted windows are scored; ordering flipped to starts_at DESC so a
future cap/limit divergence would drop OLD windows from scoring, never
newest ones (comment documents the invariant).

Known limitation (documented, not fixed): a single day with more than
MAX_MEDIA_PER_WINDOW (500) photos produces no window at all — oversized
windows are dropped, not trimmed (KNOWN_ISSUES.md ISSUE-166).

Tests: pinned cap-balance test unchanged and green; new regression test
inserts weekly media 1995-2026 (>500 candidate windows) and asserts a
same_day window exists at the newest capture instant, one at the oldest,
and the run still persists exactly 500 windows.
docs: point ISSUE-166 ref at PR#1273
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 11m15s
8cfeaa529b
chris merged commit fa50b51dcb into main 2026-10-16 22:56:28 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1273
No description provided.