A restart is told by the stream's own timestamps, not its clock falling behind (#190) #192

Merged
cmoriarty merged 1 commit from slow-source-restarts into main 2026-11-18 10:22:43 -05:00
Owner

Fixes #190.

The fault

On 2026-11-17, shd247.world's sources listed media at 0.0 to 0.7 times real time, stalling and bursting. The app took them for a new stream about every 90 s: 28 drops on four links in 25 minutes, most before their pairs had matched.

  • Why #179 didn't help. A standby's clock is read once a sample, 45 s apart, and #179's drift needs three readings a minute apart. At 0.6× the third reading had already fallen more than 30 s, before any drift was known. Each drop cleared the readings, so the drift was never measured.
  • What it cost. The links were rarely measured. A slow link of the right game could end up showing "No match".

The fix

  • A restart is told by timestamps. offsets._listed compares the link's own timestamps with its last segment (_last_end). It takes them for a new stream only when they go back more than RESTART_SECONDS (30 s), or leap ahead of the time that passed by more than LEAP_SECONDS (600 s). Tonight's real restarts moved by thousands of seconds.
  • Slow is not a restart. A source that falls behind, steadily or in stalls and bursts, still moves its timestamps on. It keeps its readings and pairs however far it falls, and a catch-up after a stall is no restart either.
  • Unchanged: the drift carried forward (#179) still sets the seconds shown, and a wrap of the timestamps still clears the readings.
  • One small change. A link that now names another stream starts its clock anew, but no longer drops the old stream's pairs, which other links may still carry.
  • Spec. stream-supervision gains "A restart is told by the stream's own timestamps", with two scenarios.

Checks

  • New tests. Both fail on main's code.
    • test_a_source_at_half_speed_listing_in_bursts_is_never_taken_for_a_new_stream covers a 0.5× source listing in bursts a minute apart.
      • With the fix there is no restart in ten minutes, and the relation it matched is kept.
      • Its shown lead falls 0.52 s each second against a true 0.5, within 35 s of the truth at 300 s and at 600 s.
      • On main it was dropped at the third sample ("its clock moved −30.0 s") and read "No match" by 540 s.
    • test_timestamps_that_go_back_or_leap_far_ahead_are_a_new_stream_and_a_catch_up_is_not:
      • timestamps that go back 31 s, and others that leap 20 minutes ahead of the 10 s that passed, drop their pairs, with the log saying which;
      • a catch-up of 150 s in 125 s after a stall does not.
  • Existing tests. All 20 other measuring tests pass unchanged. That includes the real-restart and forward-jump tests and #179's 0.9× test.
  • The whole lane. make test gave 1,500 passed and 1 skipped, in 35 s at a load average of 2.6.
  • OpenSpec. openspec validate stream-supervision --type spec --strict gives the same 24 long-requirement warnings as on main, and no new ones.

🤖 Generated with Claude Code

Fixes #190. ## The fault On 2026-11-17, shd247.world's sources listed media at 0.0 to 0.7 times real time, stalling and bursting. The app took them for a new stream about every 90 s: 28 drops on four links in 25 minutes, most before their pairs had matched. - **Why #179 didn't help.** A standby's clock is read once a sample, 45 s apart, and #179's drift needs three readings a minute apart. At 0.6× the third reading had already fallen more than 30 s, before any drift was known. Each drop cleared the readings, so the drift was never measured. - **What it cost.** The links were rarely measured. A slow link of the right game could end up showing "No match". ## The fix - **A restart is told by timestamps.** `offsets._listed` compares the link's own timestamps with its last segment (`_last_end`). It takes them for a new stream only when they go back more than `RESTART_SECONDS` (30 s), or leap ahead of the time that passed by more than `LEAP_SECONDS` (600 s). Tonight's real restarts moved by thousands of seconds. - **Slow is not a restart.** A source that falls behind, steadily or in stalls and bursts, still moves its timestamps on. It keeps its readings and pairs however far it falls, and a catch-up after a stall is no restart either. - **Unchanged:** the drift carried forward (#179) still sets the seconds shown, and a wrap of the timestamps still clears the readings. - **One small change.** A link that now names another stream starts its clock anew, but no longer drops the old stream's pairs, which other links may still carry. - **Spec.** stream-supervision gains "A restart is told by the stream's own timestamps", with two scenarios. ## Checks - **New tests.** Both fail on main's code. - `test_a_source_at_half_speed_listing_in_bursts_is_never_taken_for_a_new_stream` covers a 0.5× source listing in bursts a minute apart. - With the fix there is no restart in ten minutes, and the relation it matched is kept. - Its shown lead falls 0.52 s each second against a true 0.5, within 35 s of the truth at 300 s and at 600 s. - On main it was dropped at the third sample ("its clock moved −30.0 s") and read "No match" by 540 s. - `test_timestamps_that_go_back_or_leap_far_ahead_are_a_new_stream_and_a_catch_up_is_not`: - timestamps that go back 31 s, and others that leap 20 minutes ahead of the 10 s that passed, drop their pairs, with the log saying which; - a catch-up of 150 s in 125 s after a stall does not. - **Existing tests.** All 20 other measuring tests pass unchanged. That includes the real-restart and forward-jump tests and #179's 0.9× test. - **The whole lane.** `make test` gave 1,500 passed and 1 skipped, in 35 s at a load average of 2.6. - **OpenSpec.** `openspec validate stream-supervision --type spec --strict` gives the same 24 long-requirement warnings as on main, and no new ones. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On 2026-11-17 shd247.world's sources listed media at 0.0 to 0.7 times
real time, stalling and bursting, and were taken for a new stream about
every 90 s: 28 drops on four links in 25 minutes, most before their
pairs had matched. A standby's clock is read once a sample, 45 s apart,
and #179's drift needs three readings a minute apart, so at 0.6x the
third reading had fallen more than 30 s before any drift was known; each
drop cleared the readings, and so on.

offsets._listed now tells a restart by the link's own timestamps against
its last segment (_last_end): they went back more than RESTART_SECONDS,
or leapt ahead of the time that passed by more than LEAP_SECONDS (600).
A source that falls behind, steadily or in stalls and bursts, still moves
its timestamps on, and keeps its readings and pairs however far it
falls; a catch-up after a stall is no restart either. The drift carried
forward (#179) still sets the seconds shown. A link that now names
another stream starts its clock anew and no longer drops the old
stream's pairs, which other links may still carry. A wrap of the
timestamps clears the readings, as before.

The stream-supervision spec says so, with two scenarios and their tests:
a 0.5x source listing in minute-long bursts keeps its relation for ten
minutes with no restart (main dropped it at the third sample and showed
"No match" by 540 s), and timestamps that go back 31 s or leap 20
minutes ahead still drop the pairs while a catch-up does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
cmoriarty/sports-breaker!192
No description provided.