Skip to content

fix(engine): cancelling the task that awaits load() ends the load at once (Sodalite#173) - #683

Merged
superuser404notfound merged 3 commits into
mainfrom
fix/cancellable-load
Oct 1, 2026
Merged

superuser404notfound merged 3 commits into
mainfrom
fix/cancellable-load

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Problem (device log, Sodalite live zap): a .custom(HLSLiveIngestReader) load against an unreachable provider kept running for 19 s (open_input 18987ms while the ingest retried its playlist). load() ignored Swift task cancellation, so a host that cancelled the load (a zap to the next channel) still had to wait it out, and every press in between queued.

Change

  • Cancelling the Task that awaits load(...) now ends the load promptly with CancellationError (measured ~30 ms instead of the full connect budget), for URL and .custom sources.
  • A cancelled load leaves the engine the way a newer load would: .idle, generation bumped, native host and AVPlayer kept for the next load (fix(native): apply externalMetadata on iOS too #15 reuse, AE#158 handover), display criteria and audio-session membership untouched. A host that leaves on cancel calls stop().
  • Generation-guarded throughout: a cancel never touches a session a newer load() or a stop() started; a cancel that lands after the load reached its final state but before load() returned ends that session and throws.
  • An AE#629 software-path follower that is cancelled ends the engine's rebuild too, including nested reroutes.
  • A superseded custom-source reloadAtCurrentPosition() now throws CancellationError like the URL branch already did, so the escalation no longer logs a false "rebuilt on the software path".
  • AVIOReader: a closed reader no longer waits out a 0.75 s probe-fallback delay (~0.03 s now), which also speeds up stop() during a URL open.
  • docs/api.md: "How a load ends" row and a paragraph under Loading.

Tests: 16 CancellableLoadTests (RED before for the cancel paths, AVPlayer reuse, nested-reroute rebuild, startup continuation, superseded custom reload); full swift test: XCTest 655 tests, 0 failures; swift-testing 3984 passed. tvOS and iOS builds succeed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS

Vincent Herbst and others added 3 commits October 1, 2026 10:27
…once (Sodalite#173)

A host that cancelled the Task awaiting load() (a zap past an unreachable
live origin) waited out the whole connect and retry budget, 19 s on the
reporter's box, and every zap queued behind it.

load() now installs a task cancellation handler that tears the in-flight
load down the way stop(resetDisplayCriteria: false, finalTeardown: false)
does, guarded on the load's own generation, so a cancellation that lands
after a newer load or after the load returned touches nothing. A load
started on an already cancelled task throws before it tears down the
running session, and a load following an AE#629 takeover cancels the
rebuild it follows. The AVIOReader size-probe ladder now polls isClosed
instead of waiting out a fallback's 0.75 s stagger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… would (Sodalite#173)

The first round ended a cancelled load with a host stop(), which dropped
the native host and AVPlayer (#15) and an AE#158 handover item that the
next load's own teardown would have kept, so every zap that cancelled a
load lost AVPlayer reuse. The cancelled generation is now ended with the
supersede teardown (native host and handover item kept, panel mode kept,
no audio-session release) plus the published reset to .idle.

A load following an AE#629 rebuild no longer cancels the rebuild's Task,
which the retained-reader branch never observed; it ends the rebuild's
generation instead, and the rebuild unwinds at its own checkpoints. A
load cancelled before it began withdraws a reroute's #361 continuation,
and AVIOReader no longer logs streaming mode for a closed size ladder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eroutes (Sodalite#173)

A load following an AE#629 rebuild ended only the generation the rebuild's
teardown opened, which misses a rebuild whose load() rerouted into a
nested load() (AE#678, AE#363, AE#246/268, #168/#199): the follower threw
over a session that kept starting. Cancelling the follower now also
cancels the rebuild's Task, so load() and its reroutes end through their
own generation-guarded handlers, while the retained-reader branch is
still ended by its generation.

A custom-source reloadAtCurrentPosition() that a stop() or a cancelled
load superseded returned as if it had rebuilt, so the escalation logged
"rebuilt on the software path"; it now throws CancellationError, and a
retained-reader reopen aborted by that supersede is no longer published
as a failed reload. The docs say what a cancel leaves held until the next
load() or stop().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@superuser404notfound
superuser404notfound merged commit 80ce5a5 into main Oct 1, 2026
4 checks passed
@superuser404notfound
superuser404notfound deleted the fix/cancellable-load branch October 1, 2026 08:59
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