Skip to content

fix(frame-times): draw the producer epoch and flush generation process-wide (#314) - #327

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/314-process-wide-frame-time-sequence
Aug 7, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/314-process-wide-frame-time-sequence

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Refs #314.

The defect

NativeVideoFrameTime.epoch and SoftwareVideoFrameTime.generation both document the same rule: a higher value retires every entry a consumer recorded under a lower one. Both were counted per session, and a load() builds a new HLSVideoEngine (AetherEngine+Loading.swift) and a new SampleBufferRenderer (SoftwarePlaybackHost), so the counter restarted at exactly the seam the rule exists for.

The observer is engine-scoped and documented to outlive a load, so the outgoing producer keeps reporting until load stops it. A host that retired its table at the start of the load could be handed a frame from the outgoing producer at epoch N, adopt N as newest, and then reject every frame of the new session (epochs 1, 2, ...) as stale for the rest of the item. epoch is the only discriminator that could separate them: source, item and segmentIndex all restart near zero on a new item.

The fix

One FrameTimeSequence, a process-wide monotonic allocator with its own lock, behind both counters:

  • HLSVideoEngine.producerEpochs (static) feeds nextProducerEpoch().
  • SampleBufferRenderer.flushGenerations (static) feeds both the initial generation and every flush. The initial draw matters as much as the flush draw: a renderer that came up at zero would tie with, or rank below, the one it replaces.

That restores the documented rule end to end without a public struct change, and hosts that only compare epochs relatively need no changes. Values stay strictly increasing but are no longer consecutive; the doc comments now say so.

The software path was not in the issue's scope but carries the identical defect against the identical contract, so it is fixed in the same pass rather than left to be reported separately.

stopInternal additionally detaches the outgoing session and the outgoing software host from the observer before stopping them. That does not replace the ordering guarantee (a pump can have snapshotted the observer already), it just means the ordinary case is silence rather than a correctly-sorted straggler.

Verification

New suite Issue314FrameTimeSequenceTests:

  • the allocator is strictly increasing, never zero, and collision-free under 8 concurrent drawers (two sessions overlap while the outgoing one unwinds);
  • a new SampleBufferRenderer reports above the one it replaces, and a straggler from the outgoing renderer ranks below the new one's first report (fixture-free, runs on CI);
  • two HLSVideoEngine instances over the witness clip, standing in for the two sides of a load: the incoming session's first epoch outranks the outgoing session's last, and a restart inside the new session still opens above its own first epoch, so Report per-frame presentation times on both the source and item axes (native path) #260's within-session behaviour is untouched (fixture-gated).

Negative control: with the per-instance counters restored, the native witness fails with (incomingEpoch -> 1) > (outgoingEpoch -> 1), plus both software assertions. Full suite green afterwards, 1552 tests in 232 suites.

Issue311SoftwareFrameTimesTests moves from == before + 1 to > before, since a process-wide sequence is legitimately advanced by a renderer in a parallel test. Ordering was always the contract.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE

…s-wide (#314)

Both discriminators carry the same documented rule, that a higher value retires
every entry recorded under a lower one, and both were counted per session. A
load() builds a new HLSVideoEngine and a new SampleBufferRenderer, so the counter
restarted at the one seam the rule exists for: a report still arriving from the
outgoing session outranked everything the incoming one would ever emit, and a
host that ordered by it dropped the new item's frames for as long as it played.

Both now draw from one process-wide FrameTimeSequence, which restores the
ordering end to end without a public struct change: the superseded producer's
last report always ranks below the next session's first. The values stay
strictly increasing but are no longer consecutive, which ordering never relied
on. stopInternal also detaches the outgoing session and host from the observer
before stopping them, so the straggler window is closed in the ordinary case
rather than only sorted correctly.

The witness fails on the old code with equal epochs (1 vs 1) across two
sessions, which is the value ordering cannot separate.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
@superuser404notfound
superuser404notfound merged commit d63c438 into main Aug 7, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/314-process-wide-frame-time-sequence branch August 10, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant