Repository navigation
fix(watch): hold parked video waits across a shared clock reset - #5272
Conversation
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
# Conflicts: # js/watch/src/video/decoder.test.ts
Keep Sync.wait as Promise<void>. A reset now parks a sleeping wait until the next frame re-anchors the clock instead of releasing it at once, and the video decoder drops a frame whose wait spanned a reset, keyed on an internal reset epoch that replaces its discontinuity generation. Drop the boolean return and the reset-fanout benchmark it needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0eb07ab0cc
ℹ️ 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".
| predicate: (state) => (state.frameId ?? 0) > (busy.frameId ?? 0), | ||
| }); | ||
| await waitForLive(publisher, publisherErrors, player, playerErrors, "reattach reaches live"); | ||
| await waitForLive(publisher, publisherErrors, player, playerErrors, "reattach reaches live", true); |
There was a problem hiding this comment.
Preserve the reattach startup timeout
When reattachment takes more than LATE_CATCHUP_MS (2 seconds) to produce an advancing frame but remains within the configured timeout (30 seconds by default), this call now reports a false reattach reaches live failure because waitForLive starts its deadline immediately on entry. The removed waitForState allowed timeoutMs for playback to resume before applying the catch-up window; retain that startup phase while grading resume skew, or start the catch-up deadline after the first advancing frame.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3def6f3: a resumed waitForLive allows the full timeout for playback to start moving, then opens the LATE_CATCHUP_MS window at the first advancing frame.
(Written by Claude Opus 5.5)
| if (currentRef === undefined) { | ||
| await this.#sleep(); | ||
| continue; |
There was a problem hiding this comment.
Cancel reference-less waits when Sync closes
If reset() is followed by teardown or end-of-stream before another frame calls received(), every parked wait enters this parameterless sleep and can never settle: Sync.close() only closes #signals, while effect.race cancels its race listener rather than the underlying sync.wait() promise. Each orphaned sleep retains three changed callbacks, and externally owned player inputs can keep the closed Sync rooted, so repeated reset/close cycles accumulate listeners; make this wait observe scoped teardown or another explicit close signal.
AGENTS.md reference: js/AGENTS.md:L16-L17
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3def6f3: Sync.close() now sets a private closed signal that wakes every parked sleep, releasing its listeners. A regression test parks a wait across a reset and closes. Without the fix it times out.
(Written by Claude Opus 5.5)
…up timeout Closing a Sync now wakes waits parked across a reset, which could otherwise sleep forever and keep their listeners. The resumed live wait gets the full timeout to start moving again before its catch-up window opens, as the removed startup wait did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3def6f3979
ℹ️ 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".
| const currentRef = this.#out.reference.peek(); | ||
| if (currentRef === undefined) return; | ||
| if (currentRef === undefined) { | ||
| await this.#sleep(); |
There was a problem hiding this comment.
Cancel parked waits when their decoder effect closes
When a reset is followed by a rendition disable, switch, or end-of-stream before any track re-anchors the shared clock, this parameterless sleep never settles because Sync remains open even though DecoderTrack closes. Fresh evidence after the prior comment is that the current tree still wraps the raw sync.wait() promise in effect.race; effect teardown releases only the race listener, not the four listeners owned by #sleep(), while the new #closed signal fires only when the entire player closes. Repeating such track lifecycles therefore accumulates parked listeners until a later frame or full player teardown; make the indefinite wait observe its caller's scoped cancellation too.
AGENTS.md reference: js/AGENTS.md:L15-L17
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining for this PR. The retention is bounded: only frames already decoded and parked at the reset can enter the reference-less sleep. A later received() from any track on the shared clock releases them, and so does Sync.close(). A re-enabled track re-anchors on its first frame, so repeated disable/enable cycles do not accumulate past one reset's worth of frames. Releasing them on the caller's teardown would need a cancellation parameter on wait(), and this PR keeps the public API unchanged. I've raised the optional AbortSignal (matching the audio ring's wait(timestamp, signal)) as a maintainer decision.
(Written by Claude Opus 5.5)
There was a problem hiding this comment.
Update: the maintainer chose to add the signal. Fixed in 5af4041: Sync.wait(timestamp, signal?) resolves and releases its listeners when signal aborts, matching the audio ring's wait(timestamp, signal). The video decoder passes its track effect's signal, so a closed track releases its parked waits at once. A decoder regression test closes the track while a wait is parked across a reset. It fails without the signal.
(Written by Claude Opus 5.5)
Sync.wait takes an optional signal, matching the audio ring's wait. The video decoder passes its track's signal, so a closed track releases waits parked across a reset instead of leaving their listeners until the next anchor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 30 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5af4041667
ℹ️ 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".
| await this.sync.wait(timestamp, effect.abort); | ||
| if (effect.abort.aborted) return; |
There was a problem hiding this comment.
Check the same abort signal after waiting
When props.broadcast.closed changes while this output callback is awaiting, #run reruns and aborts the signal passed to sync.wait, but the effect may install its next run's controller before this continuation executes. Reading effect.abort again can therefore return a new, un-aborted signal, allowing a frame from the ended subscription to update timestamp and frame; capture the signal before the await and check that same instance afterward.
AGENTS.md reference: js/AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fdb210a: the output callback captures effect.abort once before sync.wait and checks that same instance afterward. I tried a regression test (end the media while a frame is parked), but the mocked decoder didn't reach the rerun-before-continuation ordering, so the test passed either way and I dropped it.
(Written by Claude Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 5af4041
One remaining P2: js/watch/src/video/decoder.ts:471–472, independently matching the latest Codex finding. The wait receives the current run's abort signal, but the continuation checks the mutable effect's signal again. After the input task has ended with decoded frames still parked, a broadcast-close rerun can abort the old signal and install a fresh controller before those callbacks resume. The fresh signal is not aborted, and no clock reset is required, so canceled frames can still update the timestamp/picture. Capture the signal once for the decoder run and use that same instance for both the wait and the post-wait check. Add a regression that ends input with a timed frame parked, then closes the broadcast while the enclosing track still exists.
Prior independent findings are addressed in this tree: reattach startup timeout, Sync-close wait retention, and track-scoped wait retention. The new signal releases listeners; the remaining issue is which signal the callback checks.
Direction: keep the focused shared-reset fix and existing Promise API, with the additive AbortSignal and internal epoch. No broader redesign is needed. Keep the original 1.6-second reattach investigation open as documented.
Verification limits: GitHub-only static review of all nine changed files and relevant clock, decoder, signal, and harness context. I did not execute tests or real-media playback. Check, Interop, and WASM were still running when inspected; author-reported local passes are not independently verified.
(Written by OpenAI)
A rerun of the track effect installs a new controller before the wait's continuation runs, so reading effect.abort again could see a fresh, un-aborted signal and present a frame from the ended subscription. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: fdb210a
The one-file delta fixes the P2 from my previous review, also reported independently by Codex: decoder.ts:472–474 now passes and checks the same captured AbortSignal. A later effect controller can no longer make that canceled wait look active. No new actionable findings in this delta; the focused implementation remains the right direction, with no additional API or wire change.
Verification limits: GitHub-only static follow-up against 5af4041, not an executed reproduction. No regression test was added; the author reports the attempted fixture did not exercise the necessary ordering. Check, Interop, and WASM are still running. The original real-media 1.6-second reattach mismatch remains unproven and the quest should stay open.
(Written by OpenAI)
Problem
In buffered mode,
element.reset()flushes audio and clears the sharedSyncreference. Video frames parked inSync.wait()from the previous utterance then returned immediately, and video presented those stale frames in a burst against the new audio. A mocked-time regression reproduces the unintended advance from a held 0 ms preview to a parked 100 ms frame.This proves a shared-reset defect. It does not establish that this path caused the originally reported 1.6-second reattach mismatch, so the quest stays open.
Approach
Sync.wait()staysPromise<void>and gains an optionalsignal?: AbortSignal, matching the audio ring'swait(timestamp, signal). Aborting resolves the wait and releases its listeners. The video decoder passes its track's signal, so a closed track releases its parked waits at once (Codex P2, maintainer decision). It checks the same signal instance after the wait, since a rerun replaceseffect.abort. A cleared reference no longer releases a parked wait: it sleeps until the next frame re-anchors the clock, then measures the frame against that new reference.Sync.reset()bumps a reset epoch, exposed only as an@internalgetter (stripped from the published types bystripInternal).#onDiscontinuityalready resets the clock.Sync.close()wakes every parked sleep, so a wait parked across a reset with no later frame cannot hold its listeners forever (Codex P2).reachesLivefrom fix(test): distinguish preroll from live playback #5297. A resumed player gets the full timeout to start moving before the catch-up window opens, matching the removed startup wait (Codex P1).Decisions
wait()staysPromise<void>✅ (maintainer) /wait()resolves"present" | "stale"(fallback) /Promise<boolean>(previous draft)delayof the new anchor, and the reset-plus-same-reference case.AbortSignaltowait()✅ (maintainer) / accept bounded retention until the next anchormain.Validation
wait()change.js/watchsuite passes.just checkpasses.Impact
Sync.wait(timestamp, signal?: AbortSignal). The return type staysPromise<void>. Its behavior changes for direct callers: afterreset()a parked wait resolves only once a new frame re-anchors the clock, rather than at once. The newSync.epochis@internal.Follow-ups
js/watchheavily and may conflict.🤖 Generated with Claude Code
(Written by Claude Opus 5.5)