Skip to content

perf(startup): overlap DV probe, prefetch MKV Cues from SeekHead, and defer subtitle prefetch - #31

Merged
Quick104 merged 12 commits into
mainfrom
perf/stream-start-speedup
Dec 6, 2026
Merged

Quick104 merged 12 commits into
mainfrom
perf/stream-start-speedup

Conversation

@Quick104

@Quick104 Quick104 commented Dec 4, 2026 •

Copy link
Copy Markdown

Summary

Cuts cold-start latency for HTTP playback by running Dolby Vision capability probes concurrently, prefetching Matroska Cues from SeekHead entries during open, kicking off the HLS background index pass before the composition-offset probe, tightening progressive-delivery segment waits, and deferring subtitleForwardPrefetcher until the session is ready.

What changed

  • VTCapabilityProbe: probes Dolby Vision hardware decode profiles concurrently instead of sequentially on cold launch.
  • AVIOReader: parses Matroska SeekHead entries out of the opening bytes and prefetches trailing Cues in parallel so cue prewarm hits RAM instead of cancelling the initial bytes=0- stream on large MKV remuxes.
  • HLSVideoEngine: starts beginIndexPass() before decideCompositionOffsetRepair() so packet indexing overlaps with the repair check.
  • SegmentCache: shortens the progressive-delivery wait step so ready segment fragments surface sooner.
  • AetherEngine+Subtitles: holds subtitleForwardPrefetcher until isSessionReady so background subtitle harvesting does not compete for demuxer lock and bandwidth before first frame.
  • aetherctl: adds --probesize and --max-analyze-duration flags to play (documented in docs/cli.md) to exercise existing LoadOptions.probesize and LoadOptions.maxAnalyzeDuration budgets.
  • Tests: adds Issue281ColdStartRoundTripTests coverage verifying Matroska SeekHead-guided trailing Cues prefetch avoids extra origin round trips.
  • CHANGELOG.md: records the Silo fork startup improvements under [Unreleased].

Test plan

  • Device / OS: macOS (SwiftPM test runner), iOS and tvOS physical devices (signed Silo client builds)
  • Source media (container / video codec + profile / audio / HDR-DV): 4K MKV remux (HEVC Dolby Vision Profile 8.1, TrueHD/AC-3, 36 embedded PGS tracks, trailing Cues ~2 MB before EOF) and 1080p SDR MKV remux (H.264, DTS/AC-3)
  • Result: swift test targeted suites passed (43/43 tests in 4 suites including PublicAPIDocumentationTests, DocumentedConstantsTests, Issue281ColdStartRoundTripTests, StartAfterCuePrewarmTests, Issue151SubtitleForwardPrefetchTests, SourcePrewarmPlanTests, plus earlier 66/66 run including FabricatedRangeOriginTests, Issue240SideReaderLinkPriorityTests, Issue295RangeBoundaryRefetchTests); Scripts/check-doc-links.py passed; signed iOS and tvOS builds compiled and played back cleanly.

Checklist

  • CHANGELOG.md updated
  • Commit messages follow Conventional Commits (feat(...), fix(...), chore(...))
  • The fix lives in the engine, not in a host-side workaround
  • Public API changes are intentional and documented

Council review

Rounds: 3, last reviewed at the round-2 fix head; round-3 fixes end at 2556b01e.

Member Round 1 Round 2 Round 3
Sol (gpt-6.2-sol, medium) 5/10 8/10 8/10
Opus (claude-opus-5-5, medium) 5/10 8/10 8/10
Gemini (gemini-4-neon, medium) 5/10 9.5/10 8/10

Visual review: not run; nothing changes on screen. Fixed in review: verdict cache keeps supported verdicts only, trailing Cues prefetch only for the playback demuxer, suffix completion timed from its own start, trailing span validated, CHANGELOG corrected. Round 3: the tail prefetch takes the superseded slot before cancelling it, the suffix span installs only for the current request at the open's size (published under the reader's lock), and the poll is back to 20 ms.

Evidence: https://evidence.siloserver.org/pr/aetherengine/31/


AI Disclosure: Harness: Antigravity (T3 Code); Tool(s): T3 Code, Antigravity agent; Model(s): gemini-4-neon; Involvement: AI-assisted; Adversarial review: see Council review above; review fixes by Claude Code (claude-opus-5-5) in T3 Code.

Note

Overlap DV probe with MKV Cues prefetch and defer subtitle prefetch at startup

  • Speeds up cold-start playback by parsing the Matroska SeekHead and prefetching the trailing Cues span in parallel with the DV capability probe, instead of waiting for a sequential index pass. AVIOReader gains a prefetchesTrailingIndex flag (default false), enabled via DemuxerOpenProfile.prefetchingTrailingIndex() for playback opens in HLSVideoEngine.swift and AetherEngine.swift
  • The trailing prefetch takes over the suffix-prefetch's origin-request slot via a new OriginRequestBudget.Ticket.take method in OriginRequestBudget.swift, and is capped at 4 MiB. Superseded completions are fenced with a generation counter
  • The startup index-pass bracket now covers the composition-offset repair, so a head packet read during repair cannot drop the retained head span before cue prewarm completes
  • Adds a 64-entry synchronized cache of accepted VideoToolbox hardware-decode verdicts in VTCapabilityProbe.swift; refused verdicts are not cached. Defers the native subtitle side-demuxer open up to 8 seconds until the session is ready, with polling at 150 ms
  • Adds --probesize and --max-analyze-duration flags to aetherctl play for measuring startup time, documented in cli.md
  • Risk: readers adopting a warm tail span or opened without the prefetch flag skip Matroska trailing inspection; a tail span whose end differs from a resolved file size is discarded — check AVIOReader teardown and size-probe paths in AVIOReader.swift

Macroscope summarized 094be23.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Dec 4, 2026
@silo-kody

silo-kody Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T07:03:16.070797Z 094be23 New commits
🔒 Security Review ✅ Completed 2026-12-06T07:06:31.237396Z 094be23 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The changes add optional Matroska trailing-index prefetching for playback, adjust playback index and subtitle-prefetch timing, cache successful hardware-decode verdicts, and expose probe-size and analysis-duration options in aetherctl play.

Changes: Cold-start playback

Layer / File(s) Summary
Matroska trailing-range prefetch
Sources/AetherEngine/Demuxer/Demuxer.swift, Sources/AetherEngine/Demuxer/AVIOReader.swift, Sources/AetherEngine/Demuxer/OriginRequestBudget.swift, Sources/AetherEngine/AetherEngine.swift, Sources/AetherEngine/Video/HLSVideoEngine.swift, Tests/AetherEngineTests/Issue281ColdStartRoundTripTests.swift, Tests/AetherEngineTests/Support/RangeFilesOrigin.swift
Playback profiles can enable trailing-index prefetching. AVIOReader inspects retained Matroska head data and fetches eligible trailing ranges. The reader validates tail spans and fences stale completions. Tests cover Cues reads, request limits, and disabled prefetching.
Playback preparation and prefetch timing
Sources/AetherEngine/Video/HLSVideoEngine.swift, Sources/AetherEngine/AetherEngine+Subtitles.swift
The HLS index pass starts before composition-offset repair. Subtitle forward prefetch waits for initial-session readiness, with the existing deadlines and arbitration condition retained.
Hardware decode verdict cache
Sources/AetherEngine/Video/VTCapabilityProbe.swift
Successful verdicts are cached by codec, dimensions, and configuration bytes. The cache is lock-protected and holds up to 64 entries. Refusals are not cached.
Playback probe options
Sources/aetherctl/main.swift, Sources/aetherctl/PlaybackCmd.swift, docs/cli.md, CHANGELOG.md
aetherctl play accepts --probesize and --max-analyze-duration and passes supplied values to LoadOptions. The CLI documentation and changelog describe these options.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant PlaybackDemuxer
  participant AVIOReader
  participant HTTPOrigin
  PlaybackDemuxer->>AVIOReader: Open with trailing-index prefetch enabled
  AVIOReader->>AVIOReader: Inspect retained head for a Matroska trailing object
  AVIOReader->>HTTPOrigin: Request eligible trailing byte range
  HTTPOrigin-->>AVIOReader: Return requested range
  AVIOReader-->>PlaybackDemuxer: Serve reads from the fetched tail span
Loading

Suggested reviewers: pkajaba

Security architecture risk: Moderate · up to 8fc15

The faster Matroska startup path intentionally spends a bounded request to avoid interrupting playback’s initial stream. AetherEngine can spend that request before it knows whether the selected playback route needs it, and a replacement fetch can bypass an origin’s active backoff. Separately, a previously successful hardware check can turn a later HEVC load into a playback failure instead of allowing software decoding.

This update could not fully reassess the architecture findings from the earlier review.

Retained concerns

  • Minor · reliability · observed: AVIOReader treats the suffix request’s lease as permission to send a new trailing-index request. If the origin enters a Retry-After quiet period or exhausts its pacing tokens while the suffix is outstanding, a successful lease transfer skips the checks that would reject a fresh speculative request. The single-slot guard only stops an origin currently limited to one request; the pacing check runs only when no suffix lease can be taken. The merge base had no replacement request that could cross that backoff boundary.
  • Trivial · architecture · observed: AetherEngine opts the initial probe into the larger SeekHead fetch before selecting the playback route. An eligible HTTP Matroska open can consume a request slot and fetch up to 4 MiB even if the selected route does not use HLS cue prewarm. That cost is useful when the route consumes the prefetched bytes; it is new relative to the base’s smaller suffix fetch when the route does not. The declared-sequential path and the known single-slot guard skip the request, and fresh admission can refuse it, but none of those checks confirms that a consumer will use the bytes.
  • Minor · reliability · inferred: SoftwarePlaybackHost uses a cached HEVC success to select hardware even if VideoToolbox availability has changed since that success. The real decoder open still checks current availability, but the host only falls back at open for VP9. A matching HEVC load can therefore fail where a fresh probe refusal in the base would have selected libavcodec. The open failure does not invalidate the cached success, so repeating the load can repeat the same decision.

View findings in the submitted review

Security review details

Security Blast Radius

  • inferred — The new network exposure is source availability: an eligible media open can issue one bounded trailing request, and admission and backoff are shared with other readers using the same origin budget. The media metadata does not grant authority to choose a new host.

Public contracts

  • observed — aetherctl play adds optional byte and microsecond probe-budget overrides through existing LoadOptions fields. The trailing-fetch option is internal to Demuxer and AVIOReader.

Resilience and Maintainability Implications

  • observed — The lease and generation checks prevent double release and stale buffer installation. If fresh admission is refused after cancellation, AVIOReader clears the wait state, does not restore the suffix fetch, and leaves reads to the ordinary path. In a successful handoff, the lease moves before the suffix completion callback; it proves local slot ownership, not that the provider has acknowledged cancellation or retired its work.
  • observed — VideoToolbox refusals are not cached, so a retry after a fresh negative probe can reach VideoToolbox again. A cached positive takes a different path: SoftwarePlaybackHost discovers any current refusal at decoder open, where the HEVC path propagates failure without the VP9 software fallback.

Hardening Proposals

  • proposed — Separate concurrency-slot transfer from permission to start a new HTTP request. Apply current pacing before cancelling the suffix, and verify the handoff against an origin fixture that enforces both request backoff and its concurrency cap.

Rollout and rollback

  • observed — AetherEngine’s open profile enables the optimization before route selection. For a provider that genuinely requires unranged sequential reads, the integration must declare that source policy before opening; AVIOReader then takes the forward-only path. Otherwise, AVIOReader checks for a known single-slot origin at trailing-request initiation. That guard prevents speculation at one slot, but it does not enforce a multi-slot provider’s backoff after a lease transfer.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names three of the main changes in the changeset: Dolby Vision probe concurrency, Matroska Cues prefetch from SeekHead, and subtitle prefetch deferral. It omits the verdict cache, the HLS in…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is related to the changeset. It names the concurrent Dolby Vision capability probes, Matroska SeekHead Cues prefetch in AVIOReader, the HLSVideoEngine index-pass reordering, the subtit…
Full details: Title check

Explanation

The title names three of the main changes in the changeset: Dolby Vision probe concurrency, Matroska Cues prefetch from SeekHead, and subtitle prefetch deferral. It omits the verdict cache, the HLS index-pass reordering, and the aetherctl flags, but it describes real, central parts of the PR and is not misleading.

Full details: Description check

Explanation

The description is related to the changeset. It names the concurrent Dolby Vision capability probes, Matroska SeekHead Cues prefetch in AVIOReader, the HLSVideoEngine index-pass reordering, the subtitle prefetch deferral, and the aetherctl --probesize and --max-analyze-duration flags. Each of these matches the file-level summaries. The description also gives a test plan and a council review record. The description is specific and on-topic, so it passes this lenient check.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68e3bafd66

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

tailPrefetchRangeStart = start
tailPrefetchInFlight = true
tailPrefetchStartedAt = DispatchTime.now()
tailPrefetchStartedAt = startedAt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Capture an immutable start time for the suffix completion

When a Matroska range prefetch upgrades an outstanding suffix fetch, this assignment can race with the suffix fetch's completion, which reads tailPrefetchStartedAt outside winCond when calculating elapsedMs. The persistent and chunk sessions use separate delegate queues, so the completion can evaluate DispatchTime.now() before the upgrade captures its new start time, then read that newer timestamp afterward; the unsigned subtraction can consequently underflow and trap during playback startup. Capture the suffix request's own immutable start time in its completion, as the new explicit-range completion already does, rather than reading the mutable shared timestamp.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 3340868: the suffix completion uses its own startedAt constant, not the shared field.

🤖 Claude Code (claude-opus-5-5)

Comment on lines +3539 to +3541
tailPrefetchRangeStart = nil
tailPrefetchInFlight = true
tailPrefetchStartedAt = DispatchTime.now()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug critical

Superseded tail completion can underflow its elapsed-time calculation

A replacement request can overwrite tailPrefetchStartedAt after the current time is sampled, causing unsigned subtraction to trap and terminate playback. Capture each suffix request's start time locally and use it in the completion.

Prompt for LLM
File Sources/AetherEngine/Demuxer/AVIOReader.swift, lines 3539-3541:

Superseded tail completion can underflow its elapsed-time calculation

The suffix completion reads `tailPrefetchStartedAt` without the lock while the replacement request can overwrite it after the current time is sampled, causing unsigned subtraction to trap and terminate playback. Capture the suffix request's start time locally and use that immutable value in its completion.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same defect as the Codex thread; fixed in 3340868.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. The suggestion addresses the same defect as the Codex thread, which you report was fixed in commit 33408687.

Comment on lines +3608 to +3610
guard let ticket = OriginRequestBudget.shared.tryAcquire(
for: url, label: "\(label) mkv trailing prefetch") else {
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Performance medium

The suffix prefetch blocks its own replacement under a two-request limit

When maxConcurrentSourceRequests is two, playback and suffix prefetch fill both slots, so tryAcquire rejects the larger Cues request. Release or replace the speculative request before acquiring its replacement, and allow retries when no slot is available.

Prompt for LLM
File Sources/AetherEngine/Demuxer/AVIOReader.swift, lines 3608-3610:

The suffix prefetch blocks its own replacement under a two-request limit

With `maxConcurrentSourceRequests` set to two, the playback connection and suffix prefetch occupy both slots, so `tryAcquire` rejects the larger Cues request before the suffix task is canceled and the new startup optimization is lost. Release or replace the existing speculative request before acquiring its replacement, and allow a retry if the slot is temporarily unavailable.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, not fixed. With a two-request budget the upgrade is skipped and the reader falls back to the suffix prefetch, which is what main does, so nothing breaks. Fixing it properly means handing the suffix's slot to the trailing request, and that slot is released asynchronously; that's new budget accounting, better done on its own.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Under a two-request budget, the larger Cues prefetch can be skipped while playback and the suffix prefetch hold both slots. Playback falls back to the existing suffix behavior, so this is a missed startup optimization rather than a playback regression.

Handling the asynchronous slot handoff and retry is reasonable as a separate follow-up. Would you like me to create an issue to track it?

Comment on lines +199 to +200
let verdict: HardwareDecodeVerdict = ok ? .supported : .unsupported
verdictCache.set(verdict, for: cacheKey)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

Transient decoder creation failures become permanent unsupported verdicts

A temporary VTDecompressionSessionCreate failure caches .unsupported for the process lifetime, forcing software decoding even after hardware resources recover. Cache only successful verdicts, or distinguish permanent unsupported-format statuses from transient failures.

Prompt for LLM
File Sources/AetherEngine/Video/VTCapabilityProbe.swift, lines 199-200:

Transient decoder creation failures become permanent unsupported verdicts

A temporary `VTDecompressionSessionCreate` failure is cached as `.unsupported` for the same format for the rest of the process, so subsequent playback continues to take the software route even after hardware resources recover. Cache successful verdicts only, or distinguish permanent unsupported-format statuses from transient failures.

Suggested code:

let verdict: HardwareDecodeVerdict = ok ? .supported : .unsupported
if ok { verdictCache.set(verdict, for: cacheKey) }

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 598ef4a: only .supported verdicts are cached, so the retry after the panel settles reaches VideoToolbox again.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming. Caching only .supported verdicts addresses the concern: a later attempt can retry VideoToolbox after a transient failure.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. Do not cache refusals across the panel-settle retry.
Minor 3
  1. Read the suffix request's start time from a local constant.
  2. The startup optimization makes AetherEngine's existing post-panel-settle retry reuse the refusal it was meant to recheck. In the merge base the retry opened a fresh VideoToolbox session; at head a same-key cache hit skips that check. A refusal recorded during the transition can therefore keep the current load and later matching loads on the software path after the condition has cleared.
  3. The new SeekHead prefetch sends an absolute range calculated from the reader's known file size, but its delegate accepts any end-of-file span of the expected length and installs it at the response-reported offset. A stale or inconsistent source response can replace the resident tail and supply bytes from a different source view to the demuxer. The suffix-only base had the same validator, but this PR applies it to an absolute-range contract and a larger resident span.
Nitpick 1
  1. Keep Cues outside the opening persistent window.
    Tests/AetherEngineTests/Issue281ColdStartRoundTripTests.swift, lines 468 · 📐 Maintainability & Code Quality · ⚡ Quick win
    The entire 8 MiB fixture fits below the default 16 MiB high-water threshold. The opening connection can therefore deliver Cues into window. Since readPersistent serves window first, the marker and request-count assertions can pass even if the explicit prefetch never installs its span.
    Use a larger fixture, such as 64 MiB, with Cues beyond the opening 32 MiB request. Keep the cluster marker inside the retained head. This makes the assertions detect a broken prefetch installation.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00ba677e-61fb-4253-afeb-2bd2a1efc857
Commits

Reviewing files that changed from the base of the PR and between 1afe480 and 68e3baf.

Files selected for processing: 10

  • CHANGELOG.md
  • Sources/AetherEngine/AetherEngine+Subtitles.swift
  • Sources/AetherEngine/Demuxer/AVIOReader.swift
  • Sources/AetherEngine/Video/HLSVideoEngine.swift
  • Sources/AetherEngine/Video/SegmentCache.swift
  • Sources/AetherEngine/Video/VTCapabilityProbe.swift
  • Sources/aetherctl/PlaybackCmd.swift
  • Sources/aetherctl/main.swift
  • Tests/AetherEngineTests/Issue281ColdStartRoundTripTests.swift
  • docs/cli.md

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently tested 68e3bafd against 1afe480fcb with a 4K Dolby Vision 8.1 MKV over an isolated HTTP range origin.

Metadata probes now fetch the trailing Cues. Every aetherctl probe invocation on the base made two GETs. The PR made three and downloaded an additional 2,865,183 bytes even though the caller only requested metadata. With a warm origin and a new CLI process for each trial, the median went from 76.6 to 234.5 ms and p95 from 110.4 to 433.5 ms (8 trials per revision). Gate the extra range on an open that intends to use the index for playback or seeking. Prefetch condition

Across two full loads per trial, median origin requests fell from 19 to 17 and interrupted responses from 2 to 0. First frame ready was 350 → 355 ms on process start and 212 → 251 ms on reload (8 each). The PR head also lacks LiveTelemetry.relayMediaReceivedBytes, which the current Apple app requires. Please retain that API when preparing the client pin. silo-apple#1360

AI-assisted validation · Codex (gpt-6.2-sol, xhigh) in T3 Code.

@silo-triage silo-triage Bot added enhancement New feature or request needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. labels Dec 5, 2026
Quick104 and others added 5 commits December 6, 2026 00:18
…pted

The new verdict cache also kept refusals for the life of the process.
VideoToolbox refuses for passing reasons, such as no hardware decoder while
the app is in the background, and the AE#348 retry after the panel settles
read the cached refusal back instead of asking again. A format refused once
then stayed on the software path for every later load.

Cache a supported verdict only; a refusal is probed again on every consult.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… demuxer

The SeekHead-guided trailing Cues prefetch ran on every AVIOReader open
with read-ahead on: metadata probes, the Dolby Vision record audit, and
the subtitle and Atmos side demuxers each fetched up to 4 MiB beside their
open that nothing read. Only the session's playback demuxer, whose cue
prewarm reads that index, gains from it.

Gate it on a new open-profile flag that the session's probe demuxer and
HLSVideoEngine's own open set, and test that a reader without it leaves the
trailing range alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The suffix prefetch's completion read the shared tailPrefetchStartedAt
outside winCond, and the Matroska trailing-range prefetch now rewrites that
field when it supersedes the suffix. A completion that read the later start
subtracted a larger DispatchTime from a smaller one, which traps on UInt64.

Capture the suffix request's start in a local, as the trailing-range path
already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sked for

The trailing-range completion installed any span the delegate accepted, and
the delegate only checks that the span is the right length and ends at the
response's own total. A fetch superseded by a close or a forward-only
switch, or an origin answering against a different length, could install
bytes at offsets this open does not own.

Install only for the current prefetch generation, starting at the requested
offset and ending at the size the open knows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The entry said VTCapabilityProbe checks the Dolby Vision decode profiles
concurrently; the change caches verdicts instead. It now names what each
part does, including that refusals are not cached and that only the
playback demuxer fetches the trailing Cues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 68e3bafd. New findings are inline; the verdict-cache, suffix start-time, and request-budget threads are answered in place.

For the maintainers: the Silo app pins this engine at f470d8dc, the head of #30, and this branch is based on main, which lacks LiveTelemetry.relayMediaReceivedBytes from #30. The app can't adopt this PR until #30 lands and this branch is rebased, or this branch is rebased onto #30.

🤖 Claude Code (claude-opus-5-5) in T3 Code

Comment thread CHANGELOG.md Resolved
/// sealed segment is read to its end; `.abandoned` when the producer gave it up, or wrote nothing
/// for `idleTimeout` (a wedged producer must not hold a connection forever).
func next(maxBytes: Int = 256 * 1024, pollInterval: TimeInterval = 0.02,
func next(maxBytes: Int = 256 * 1024, pollInterval: TimeInterval = 0.004,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer decision. 20 ms → 4 ms means five times the wakeups for every connection waiting on a progressive segment, on battery-powered iPhones and iPads included, and no measurement separates its gain from the rest of the PR. Options: keep 4 ms, go back to 20 ms, or signal readers through the existing condition instead of polling. I'm leaving it as it is.

@silo-kody

silo-kody Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. A cached hardware verdict can select a decoder that VideoToolbox refuses.
Trivial 2
  1. AetherEngine enables the larger SeekHead fetch on its initial playback probe before choosing the final route. An eligible HTTP Matroska open can therefore spend an origin request slot and fetch up to 4 MiB even if playback later takes a path that does not perform HLS cue prewarm. The base had the smaller suffix fetch but did not pay this cost before route selection. AVIOReader skips the new request for declared sequential sources and checks known serial-origin restrictions and available request slots, but those checks do not establish that a consumer will use the bytes.
  2. SoftwarePlaybackHost treats a cached HEVC success as evidence that hardware is available for the current load. If availability changes after the earlier success, a matching load can select hardware and propagate a decoder-open failure instead of selecting libavcodec as a fresh refusal would have in the base. The actual VideoToolbox open still checks current availability, but the host's open-time software fallback applies only to VP9, and an HEVC open failure does not invalidate the cached positive verdict.
Nitpick 1
  1. Keep Cues outside the main window in this test.
    Tests/AetherEngineTests/Issue281ColdStartRoundTripTests.swift, lines 464 · 📐 Maintainability & Code Quality · ⚡ Quick win
    The 8 MiB fixture fits in both the default 16 MiB window and the first 32 MiB pump request. If that request finishes before the Cues read, readPersistent serves the window without using tailSpan. The test can therefore pass when the explicit prefetch is requested but never installed.
    Change the fixture layout or reader-window setup so the main window cannot serve Cues. Keep cluster 0 in the retained head. This makes a broken tail installation fail the round-trip assertion.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3c39130-97a7-478e-81aa-fba16fbbaca5
Commits

Reviewing files that changed from the base of the PR and between 68e3baf and d4ffca8.

Files selected for processing: 7

  • CHANGELOG.md
  • Sources/AetherEngine/AetherEngine.swift
  • Sources/AetherEngine/Demuxer/AVIOReader.swift
  • Sources/AetherEngine/Demuxer/Demuxer.swift
  • Sources/AetherEngine/Video/HLSVideoEngine.swift
  • Sources/AetherEngine/Video/VTCapabilityProbe.swift
  • Tests/AetherEngineTests/Issue281ColdStartRoundTripTests.swift
Files skipped from review as they are similar to previous changes: 1

  • CHANGELOG.md

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

if let session { VTDecompressionSessionInvalidate(session) }
let ok = status == noErr && session != nil
let verdict: HardwareDecodeVerdict = ok ? .supported : .unsupported
if ok { verdictCache.set(verdict, for: cacheKey) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Stability & Availability · Heavy lift

A cached hardware verdict can select a decoder that VideoToolbox refuses.

A successful probe is cached and reused. A later load that runs while VideoToolbox refuses new sessions, such as in the background, gets the cached .supported. SoftwarePlaybackHost then selects HardwareVideoDecoder without a new probe. That decoder has no software fallback, so the stream can stay without decodable video. Before this change, the same load re-probed, received the refusal, and used libavcodec.

A cached success must not route a load to hardware in a state where VideoToolbox can refuse the session. Choose one of these behaviors: check hardware availability again before using the cached verdict, or fall back to libavcodec when the hardware session fails to open.

@Quick104

Quick104 commented Dec 6, 2026

Copy link
Copy Markdown
Author

Review summary

Reviewed head: d4ffca84.

Fit: 7/10 · Readiness: 7/10 — conditional (assuming CI is green)

What changed in review

  • Verdict cache: keeps only supported verdicts, so the retry after the panel settles reaches VideoToolbox again.
  • Trailing Cues prefetch: runs only for the session's playback demuxer and HLSVideoEngine's open. Metadata probes and side readers no longer fetch the extra ~2.9 MB.
  • Suffix completion: times itself from its own start, so the unsigned subtraction can't trap.
  • Trailing span: installed only when the fetch is current, at the requested offset, and ending at the known file size.
  • CHANGELOG: describes what the code does.
  • Checks: swift build passes, 76 focused tests pass, and check-doc-links passes.

Evidence: https://evidence.siloserver.org/pr/aetherengine/31/

Left for the maintainers

Council

Member Round 1 Round 2
Sol (gpt-6.2-sol, medium) 5/10 8/10
Opus (claude-opus-5-5, medium) 5/10 8/10
Gemini (gemini-4-neon, medium) 5/10 9.5/10

Fit is 7: the startup work belongs in the engine, but the poll change trades wakeups for an unmeasured gain. Readiness is 7: the defects found are fixed, and the base-branch question decides when the app can use it.

🤖 Claude Code (claude-opus-5-5) in T3 Code

Quick104 and others added 3 commits December 6, 2026 03:40
…d the open's size

The suffix prefetch completion checked the generation but installed its
span anyway, so a suffix the Matroska trailing-index request had
superseded could still land, and a suffix answered against a different
length than the opening GET would be served at the wrong offsets.

Install only for the current generation and only when the span ends at
the size the open knows. When the suffix lands before the data
connection has named a size, the span goes in and is dropped as soon as
a size arrives that it does not end at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g request

The trailing-index request asked the origin budget for a slot before it
cancelled the suffix request it supersedes. On an origin capped at two
requests the data connection and the suffix request already hold both,
so the trailing request was always skipped and the Cues were read over a
reconnect.

Supersede the suffix request first and move its slot to the trailing
request (OriginRequestBudget.Lease.take), so the slot never goes back to
the budget where another caller could take it in between. When the
suffix request has already finished, the trailing request asks the
budget as before. A read waiting on the tail keeps waiting across the
handoff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR lowered the progressive segment reader's poll interval from
20 ms to 4 ms without a measurement showing a gain. Restore main's value
and drop the CHANGELOG sentence that described the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-triage silo-triage Bot added size/XL 500–999 added + deleted lines (all files); change volume, not priority. and removed size/L 200–499 added + deleted lines (all files); change volume, not priority. labels Dec 6, 2026
@silo-kody

silo-kody Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Minor 4
  1. The Matroska trailing prefetch can lose its origin slot to another caller.
  2. Check request-rate admission when transferring the slot.
  3. Do not finish inspection from an incomplete SeekPosition.
  4. AVIOReader treats the suffix request’s lease as permission to send a new trailing-index request. If the origin enters a Retry-After quiet period or exhausts its pacing tokens while the suffix is outstanding, a successful lease transfer skips the checks that would reject a fresh speculative request. The single-slot guard only stops an origin currently limited to one request; the pacing check runs only when no suffix lease can be taken. The merge base had no replacement request that could cross that backoff boundary.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e8437c54-e6ed-4874-ad03-ccf382e6fbad
Commits

Reviewing files that changed from the base of the PR and between d4ffca8 and 8fc15d4.

Files selected for processing: 5

  • CHANGELOG.md
  • Sources/AetherEngine/Demuxer/AVIOReader.swift
  • Sources/AetherEngine/Demuxer/OriginRequestBudget.swift
  • Tests/AetherEngineTests/Issue281ColdStartRoundTripTests.swift
  • Tests/AetherEngineTests/Support/RangeFilesOrigin.swift
Files skipped from review as they are similar to previous changes: 1

  • CHANGELOG.md

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Comment on lines +3656 to +3657
supersededTask?.cancel()
guard let ticket = supersededLease?.take() ?? OriginRequestBudget.shared.tryAcquire(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Performance & Scalability · Quick win

The Matroska trailing prefetch can lose its origin slot to another caller.

The suffix request releases its budget ticket on every outcome, including cancellation. Here, the code cancels that request before it takes the lease. If the suffix completes in that gap, its release can hand the slot to a queued caller. The lease's take() then returns nil, and the fallback admission fails. The trailing Cues prefetch is skipped, and the reader falls back to a reconnect that adds origin round trips at cold start.

Take the ticket before cancelling the suffix task:

Suggested fix

         tailPrefetchTask = nil
         tailPrefetchLease = nil
+        // Take the slot before cancelling: the cancelled suffix can release its ticket on the
+        // delegate queue at any point after cancel() returns.
+        let inheritedTicket = supersededLease?.take()
         // `tailPrefetchInFlight` stays as it was across the handoff, so a read already waiting on
         // the tail keeps waiting for this request instead of reconnecting in the gap.
         winCond.unlock()
         supersededTask?.cancel()
-        guard let ticket = supersededLease?.take() ?? OriginRequestBudget.shared.tryAcquire(
+        guard let ticket = inheritedTicket ?? OriginRequestBudget.shared.tryAcquire(
             for: url, label: "\(label) mkv trailing prefetch") else {

// the tail keeps waiting for this request instead of reconnecting in the gap.
winCond.unlock()
supersededTask?.cancel()
guard let ticket = supersededLease?.take() ?? OriginRequestBudget.shared.tryAcquire(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Performance & Scalability · Quick win

Check request-rate admission when transferring the slot.

If the armed pacer has two tokens, the suffix request and pump can consume both. When the SeekHead arrives, supersededLease?.take() returns a ticket and bypasses tryAcquire, including its rate-token check. The explicit prefetch then starts without rate admission.

Preserve the concurrency slot, but check and consume a rate token for the replacement request. If no token is available, skip the speculative request. Keep the existing handoff for unpaced origins.

|| Int64(headSpan.count) >= fileSize || connEnded || connEndedAtRangeEnd {
if let trailingStart = SourcePrewarmPlan.firstTrailingObject(
head: headSpan, headEnd: Int64(Self.headSpanMaxBytes)) {
mkvTrailingPrefetchChecked = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Performance & Scalability · Quick win

Do not finish inspection from an incomplete SeekPosition.

If a delivery ends inside a SeekPosition, SourcePrewarmPlan.seekPositions clamps the field to the available bytes and accepts that shorter integer. For a 2 GiB MKV with Cues 512 KiB before EOF, seven bytes of an eight-byte position can produce an offset near 8 MiB. This line then finishes inspection, while the incorrect trailing length fails the 4 MiB cap. Later bytes cannot trigger the valid Cues prefetch.

Require the complete SeekPosition payload before accepting its value. Keep inspection pending within the existing inspection bound when the field is incomplete.

Quick104 and others added 2 commits December 6, 2026 04:26
The trailing-index request cancelled the suffix request before taking
its lease. A cancel can fire the suffix delegate's completion, which
releases the lease, so the slot could go back to the origin budget and
be taken by another caller before the handoff ran.

Take the lease first, then cancel. The suffix completion's release then
finds nothing to return, and the trailing request asks the budget only
when there was no slot to take over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the data connection named no size, the open fell back to the size
probe and wrote the result to fileSize without holding winCond, then
took the lock only to check the tail span. The suffix prefetch's
completion reads fileSize under winCond to decide whether its span fits,
so the two raced.

Probe into a local and publish it in the same critical section as the
tail check. The refused-at-offset-0 branch, which resets the size to
unknown while the suffix request can still be in flight, now writes
under the lock too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-kody

silo-kody Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Quick104 commented Dec 6, 2026

Copy link
Copy Markdown
Author

Review update

Reviewed head: 2556b01e.

Fit: 7/10 · Readiness: 8/10 — conditional (assuming CI is green)

What changed since the last summary

  • Tail prefetch handoff. The trailing-index request takes the superseded suffix request's origin slot before cancelling it, so the slot can't go back to the budget in between. A test covers an origin capped at two requests.
  • Suffix span. It installs only for the current request, and only where it ends at the size the open learned. A span installed before the size was known is dropped if it doesn't fit. The size probe now publishes under the reader's lock.
  • Poll interval. The progressive segment poll is back to main's 20 ms.
  • Checks. swift build passes. 5,863 swift-testing and 17 XCTest tests run, with one failure: an APAC encode test that also fails on the base.

Left for the maintainers

Council

Member Round 1 Round 2 Round 3
Sol (gpt-6.2-sol, medium) 5/10 8/10 8/10
Opus (claude-opus-5-5, medium) 5/10 8/10 8/10
Gemini (gemini-4-neon, medium) 5/10 9.5/10 8/10

🤖 Claude Code (claude-opus-5-5) in T3 Code

@Quick104
Quick104 merged commit db3125a into main Dec 6, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant