Repository navigation
SiloPlayer: seek cache — disk spill on by default with NAND wear guard - #68
Conversation
Far forward/backward seeks now hit local temporary storage instead of refetching from origin. The source cache's dormant spill path becomes default behavior, hardened per the AetherEngine pattern: - Dynamic disk budget min(2 GiB, free/4, floor 512 MiB) shared with the loopback segment store via new PlaybackDiskBudget helper - Disk-span eviction farthest-from-playhead first (a seek-back target is the last thing dropped); previously spill silently stopped forever once the fixed 512 MiB budget filled - NAND wear guard: per-session write budget of 2x the retention budget (1x on constrained Apple TVs), halved when the budget holds under 10 minutes of content — a 70 GB remux now costs at most a few GiB of flash writes instead of the full stream, and the evict-to-make-room churn stops with it - Disk reads mmap with [.alwaysMapped, .uncached] in both spill tiers so a large cache pages through the kernel instead of the heap - User setting "Seek Cache" (player.seek_cache_enabled, default ON) in Playback Settings on iOS/tvOS/macOS; env vars remain as dev overrides - diskBudget/diskBytesWritten surfaced in stats + playback stats rows iOS/tvOS/macOS builds green; 526 tests incl. 5 new spill tests. Co-Authored-By: Claude Fable 5 <[email protected]>
A force-killed process never runs the caches' deinit cleanup, stranding its spill directories (up to the full retention budget each) — observed on-device when the app was swiped away mid-playback. One-shot per-process sweep in PlaybackDiskBudget clears leftovers from both spill tiers before the first cache of the new process creates its own directory. Also fixes the same pre-existing hole for the segment store's continuum-dv-hls generations. Co-Authored-By: Claude Fable 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds shared disk-budget policy and refactors playback cache spill, eviction, and stats handling. Introduces a persisted Seek Cache setting wired through iOS and tvOS settings, then covers the behavior with new disk-spill tests. ChangesDisk spill budgeting and Seek Cache setting
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f666587dc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
lastReadEnd is a monotonic high-water mark (forward-buffer accounting), so after a backward seek it stays pinned ahead of the bytes being served and disk eviction protected the wrong neighborhood — the seek-back target could be evicted while stale forward spans survived. Track the most recent read position separately and anchor eviction there. Regression test included. Review finding by Codex on PR #68. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (3)
iosApp/Tests/PlaybackSourceCacheDiskSpillTests.swift (2)
18-26: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUnused
fill()helper — every test inlines the same loop instead.
fill()is defined but never called;testEvictedSpanIsServedFromDisk,testDiskSpillDisabledWritesNothing,testDiskEvictionPrefersSpansFarthestFromPlayhead, andtestWriteBudgetStopsSpillAndChurneach hand-roll the identical span-storing loop instead of reusing it.(Would need `fill`'s signature extended with an optional `spacing` parameter, defaulting to `spanBytes`, to cover the non-adjacent-span cases.)♻️ Example: reuse fill() in testEvictedSpanIsServedFromDisk
func testEvictedSpanIsServedFromDisk() { let cache = makeCache() // Distinct non-adjacent spans so the append fast path can't merge // them; overflow the 4 KiB memory budget to force eviction + spill. - for i in 0..<8 { - cache.store( - start: Int64(i * spanBytes * 2), - data: Data(repeating: UInt8(i + 1), count: spanBytes), - totalLength: nil - ) - } + fill(cache, spans: 8, spacing: spanBytes * 2)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/Tests/PlaybackSourceCacheDiskSpillTests.swift` around lines 18 - 26, The PlaybackSourceCacheDiskSpillTests helper fill(_ cache:spans:startingAt:) is currently unused because several tests duplicate the same span-storing loop; update the tests to call fill() instead of inlining the loop. Extend fill() with an optional spacing parameter (defaulting to spanBytes) so it can cover both adjacent and non-adjacent span cases, and reuse it in testEvictedSpanIsServedFromDisk, testDiskSpillDisabledWritesNothing, testDiskEvictionPrefersSpansFarthestFromPlayhead, and testWriteBudgetStopsSpillAndChurn.
1-131: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNo cleanup of on-disk spill artifacts across test runs.
Several tests force real disk spill (
testEvictedSpanIsServedFromDisk,testDiskEvictionPrefersSpansFarthestFromPlayhead,testWriteBudgetStopsSpillAndChurn), which per the upstream contract writes files to adiskDirectory. There's notearDown()removing these directories, which could leave orphaned temp files if the cache's per-session cleanup doesn't already handle it deterministically in a test/CI environment.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/Tests/PlaybackSourceCacheDiskSpillTests.swift` around lines 1 - 131, The disk-spill tests create real on-disk cache artifacts, but `PlaybackSourceCacheDiskSpillTests` does not clean them up between runs. Add test teardown cleanup for the cache’s disk directory so `testEvictedSpanIsServedFromDisk`, `testDiskEvictionPrefersSpansFarthestFromPlayhead`, and `testWriteBudgetStopsSpillAndChurn` cannot leave orphaned files behind. Use the existing `PlaybackSourceCache`/`diskDirectory` setup in this test class to locate and remove spill artifacts deterministically after each test.iosApp/iosApp/Screens/Player/PlaybackDiskBudget.swift (1)
37-52: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winMove the orphan sweep off the startup path.
sweepOrphanedSpillDirectoriesdoes synchronous enumeration and deletion on first access ofPlaybackSourceCache/LoopbackSegmentStore, so a leftover spill tree can add a noticeable stall before playback starts. Dispatch this cleanup to a background queue so it reclaims space without blocking session startup.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/iosApp/Screens/Player/PlaybackDiskBudget.swift` around lines 37 - 52, The synchronous cleanup in sweepOrphanedSpillDirectories is running on the startup path and can block playback initialization. Move the directory enumeration and deletion work off the first-access path for PlaybackSourceCache/LoopbackSegmentStore by dispatching it to a background queue or async task, keeping the static initializer lightweight while still reclaiming spill space in the background.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@iosApp/iosApp/Screens/Player/PlaybackDiskBudget.swift`:
- Around line 37-52: The synchronous cleanup in sweepOrphanedSpillDirectories is
running on the startup path and can block playback initialization. Move the
directory enumeration and deletion work off the first-access path for
PlaybackSourceCache/LoopbackSegmentStore by dispatching it to a background queue
or async task, keeping the static initializer lightweight while still reclaiming
spill space in the background.
In `@iosApp/Tests/PlaybackSourceCacheDiskSpillTests.swift`:
- Around line 18-26: The PlaybackSourceCacheDiskSpillTests helper fill(_
cache:spans:startingAt:) is currently unused because several tests duplicate the
same span-storing loop; update the tests to call fill() instead of inlining the
loop. Extend fill() with an optional spacing parameter (defaulting to spanBytes)
so it can cover both adjacent and non-adjacent span cases, and reuse it in
testEvictedSpanIsServedFromDisk, testDiskSpillDisabledWritesNothing,
testDiskEvictionPrefersSpansFarthestFromPlayhead, and
testWriteBudgetStopsSpillAndChurn.
- Around line 1-131: The disk-spill tests create real on-disk cache artifacts,
but `PlaybackSourceCacheDiskSpillTests` does not clean them up between runs. Add
test teardown cleanup for the cache’s disk directory so
`testEvictedSpanIsServedFromDisk`,
`testDiskEvictionPrefersSpansFarthestFromPlayhead`, and
`testWriteBudgetStopsSpillAndChurn` cannot leave orphaned files behind. Use the
existing `PlaybackSourceCache`/`diskDirectory` setup in this test class to
locate and remove spill artifacts deterministically after each test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e99dd28e-37ff-43ea-b3e8-2393e49b38bb
📒 Files selected for processing (12)
iosApp/Tests/PlaybackSourceCacheDiskSpillTests.swiftiosApp/iosApp/Screens/Player/AVPlayerRoute/AVPlayerBackend.swiftiosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentStore.swiftiosApp/iosApp/Screens/Player/PlaybackDiskBudget.swiftiosApp/iosApp/Screens/Player/PlaybackSourceProxy.swiftiosApp/iosApp/Screens/Player/PlaybackStats.swiftiosApp/iosApp/Screens/Player/PlayerSettings.swiftiosApp/iosApp/Screens/Player/PlayerViewModel.swiftiosApp/iosApp/Screens/Settings/PlaybackSettingsView.swiftiosApp/iosApp/Screens/Settings/SettingsViewModel.swiftiosApp/iosApp/tvOS/Screens/Settings/TVPlaybackSettingsView.swiftiosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift
Review nitpicks from PR #68: the orphan sweep now enumerates synchronously (still before any live directory exists) but deletes on a utility queue so a multi-GiB leftover tree never stalls session startup; the spill tests reuse the fill() helper instead of six hand-rolled loops. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Addressed the CodeRabbit nitpicks in ad1b8a0:
🤖 Addressed by Claude Code |
Cluster-by-cluster comparison of AetherEngine's fixed defects against the silo-apple loopback + PlayerCore stack: 18 gaps (1 high, 15 medium, 2 low) where AE enforces an invariant we don't, each with the AE symptom, our concrete exposure scenario, and a fix naming our files/functions. Produced by a 5-phase agent workflow (mine 277 AE fixes → cluster → audit vs our code → adversarial verify); 15 gaps verified, 3 marked unverified. Markdown for review + a self-contained HTML report for sharing. Excludes today's moov-wedge fix (359d20c) and the PR #52/#66/#68 stack as landed. Co-Authored-By: Claude Fable 5 <[email protected]>
What
Makes the playback source cache spill to temporary disk storage by default (previously dormant behind
SILO_ENABLE_SOURCE_DISK_SPILL), so large forward/backward seeks are served from local storage instead of refetching from origin. Follows the AetherEngine pattern (small RAM window, disk-backed retention, mmap reads).min(2 GiB, free/4, floor 512 MiB)via newPlaybackDiskBudget, shared with the loopback segment store so both spill tiers size against one policy (existingAVPlayerBackend.vodRetentionBudgetdelegates to it)..alwaysMapped, .uncached) for disk hits in both spill tiers, so a large cache pages through the kernel instead of the heap.player.seek_cache_enabled. Governs the source cache only — the segment store's spill stays on (load-bearing for the DV loopback route). Env vars remain as dev overrides in both directions.continuum-dv-hlsgenerations.diskBudgetBytes/diskBytesWrittensurfaced in cache stats and the playback stats overlay ("Source disk written").Why
PR #66's streaming fetch fills the RAM window fast (6×+ realtime), but the window is only 256/128 MiB — far seeks past it always went back to origin. Disk retention buys instant seek-back within ~2 GiB of recently streamed content. The wear guard exists because unbounded spill would write each stream to flash once per watch, which matters on small-NAND Apple TVs.
Validation
PlaybackSourceCacheDiskSpillTests(disk round-trip integrity, playhead-aware eviction, write-budget enforcement, spill-off parity with old behavior, budget-clamp parity with the segment store).Reviewer notes
[CMP-SOURCE-CACHE] spill write-budget exhaustedline per session; not yet observed on hardware (session ended before budget spent).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Tests