Skip to content

fix(subtitles): keep cue placement across every retained-store rebuild (#233) - #244

Merged
superuser404notfound merged 2 commits into
mainfrom
fix/issue233-placement-dropped-on-insert
Jul 29, 2026
Merged

superuser404notfound merged 2 commits into
mainfrom
fix/issue233-placement-dropped-on-insert

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Follow-up to #233, reported by tresby: no cue reached the host with a placement on an embedded track, while the same field survived fine on sidecars.

What was wrong

5.26.0 added SubtitleCue.placement and the decoders fill it correctly (EmbeddedSubtitleDecoder.swift:305, SubtitleDecoder.swift:301). Every operation that rebuilds a cue to change one field did it by calling the memberwise initializer with the fields it happened to know about. placement is defaulted there for source compatibility, so each of those call sites dropped it and still compiled.

insertCueSorted is the decisive one: it stamps the session-monotonic id (#121) on every cue entering the retained store, so nothing arriving through the drained embedded path could deliver a placement to a host at all. trimTextCues (#107) would have dropped it a second time on each teletext page transition.

Why it looked like it worked

Three publishing paths, only one goes through the retained store:

Path Publishing placement
Sidecar / external subtitle URL subtitleCues = result.cues survived
Native rendition route route.store.appendCues survived
Drained embedded track applyEventMutations -> insertCueSorted dropped

That is exactly the split the reporter saw: WebVTT placement worked through a sidecar, teletext placement did not because it is an embedded track. Colour and the other run attributes were never affected, since they live in the cue body, which every rebuild did carry.

The fix

One internal copy helper, SubtitleCue.with(id:endTime:body:), which carries every field it is not asked to change. All eight rebuild sites converted, including the image-only ones (PGS trim, Issue100PGSStaleArrival, OCR) where placement is nil by construction today. The next field added to the cue cannot repeat this.

Considered and rejected: making the initializer parameter required, which would have caught all eight at compile time but is source-breaking for hosts constructing a cue.

Tests

Issue233PlacementRetentionTests, 8 cases asserting the invariant on the store operations rather than on any one format, since the defect was never format-specific: the id stamp, the anchor point, rich-text bodies, the nil case, the #107 trim, both in the order the drain applies them, plus the shape of the image-only rebuilds.

Full suite green: 1252 Swift Testing in 193 suites, 392 XCTest, 0 failures. tvOS Simulator build succeeded.

Vincent Herbst and others added 2 commits July 29, 2026 08:40
#233 added SubtitleCue.placement and the decoders fill it correctly, but every
operation that rebuilds a cue to change one field did it by calling the
memberwise initializer with the fields it happened to know about. placement is
defaulted there for source compatibility, so each of those call sites dropped it
and still compiled.

insertCueSorted is the decisive one: it stamps the session-monotonic id on every
cue entering the retained store, so nothing arriving through the drained
embedded path could deliver a placement to a host. trimTextCues (#107) would
have dropped it a second time on each teletext page transition.

That is the split the reporter observed: a sidecar's cues are published as
decoded and a native rendition's go into a store verbatim, so WebVTT placement
worked; teletext is an embedded track and never got one.

Rebuilds now go through SubtitleCue.with(id:endTime:body:), which carries every
field it is not asked to change, so the next field added to the cue cannot
repeat this. All eight rebuild sites converted, including the image-only ones
where placement is nil by construction today.

Reported by tresby (#233).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N
@superuser404notfound
superuser404notfound merged commit 374916b into main Jul 29, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/issue233-placement-dropped-on-insert branch July 29, 2026 06:46
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