Skip to content

fix(watch): hold parked video waits across a shared clock reset - #5272

Merged
kixelated merged 10 commits into
mainfrom
quest/m1/watch-break-av-sync
Oct 11, 2026
Merged

kixelated merged 10 commits into
mainfrom
quest/m1/watch-break-av-sync

Conversation

@kixelated

@kixelated kixelated commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In buffered mode, element.reset() flushes audio and clears the shared Sync reference. Video frames parked in Sync.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() stays Promise<void> and gains an optional signal?: AbortSignal, matching the audio ring's wait(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 replaces effect.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 @internal getter (stripped from the published types by stripInternal).
  • The video decoder captures the epoch when a frame comes out and drops the frame if the epoch changed while it waited. This replaces its own discontinuity generation, since #onDiscontinuity already 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).
  • The media harness keeps early-resume A/V grading active until audio is running and unstalled, reusing reachesLive from 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() stays Promise<void> ✅ (maintainer) / wait() resolves "present" | "stale" (fallback) / Promise<boolean> (previous draft)
  • Drop every frame whose wait spanned a reset ✅ / drop only frames overdue against the new reference. "Overdue" cannot be told apart from "due by timer" without a timing tolerance. It also misses frames within delay of the new anchor, and the reset-plus-same-reference case.
  • Add an optional AbortSignal to wait() ✅ (maintainer) / accept bounded retention until the next anchor
  • Remove the reset-fanout benchmark and its nightly step ✅: the extra per-wait listener it measured is gone, and the remaining reset wake is unchanged from main.

Validation

  • The regression "a shared audio clock reset cannot present a parked video frame" now also re-anchors the clock past the parked frame's deadline. It fails with either half of the fix reverted.
  • A new decoder test resets and restores the same reference in one turn, then fires the parked timer. It fails without the epoch check.
  • The Sync test "holds a sleeping wait across a reset until the next frame re-anchors" fails without the wait() change.
  • A Sync test closes a wait parked across a reset; it times out without the close fix. A second test aborts its signal instead.
  • A decoder test closes the track while a wait is parked across a reset. It fails unless the decoder passes its signal.
  • The js/watch suite passes. just check passes.

Impact

  • Public API (additive): Sync.wait(timestamp, signal?: AbortSignal). The return type stays Promise<void>. Its behavior changes for direct callers: after reset() a parked wait resolves only once a new frame re-anchors the clock, rather than at once. The new Sync.epoch is @internal.
  • Behavior: a video frame parked across any shared clock reset is dropped, so the held picture stays until a frame from the new timeline comes due. This includes audio discontinuities in live playback, which previously burst parked frames out early.
  • Wire: unchanged.

Follow-ups

  • Keep the quest until the 1.6 s reattach mismatch is reproduced with media-group/shared-clock evidence or shown resolved. Decoded frames still queued inside WebCodecs at reset time rely on the existing unanchored-reference check, not the epoch.
  • feat(watch)!: expose per-frame arrivals through decoder handles #5311 also touches js/watch heavily and may conflict.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 4 commits October 10, 2026 14:20
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>
@kixelated kixelated changed the title test(watch): grade sync during resumed catch-up fix(watch): discard video waits invalidated by a shared clock reset Oct 11, 2026
kixelated and others added 2 commits October 11, 2026 14:59
# 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>
@kixelated kixelated changed the title fix(watch): discard video waits invalidated by a shared clock reset fix(watch): hold parked video waits across a shared clock reset Oct 11, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T23:22:18.439388Z fdb210a Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread js/watch/src/sync.ts
Comment on lines +247 to +249
if (currentRef === undefined) {
await this.#sleep();
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread js/watch/src/sync.ts Outdated
const currentRef = this.#out.reference.peek();
if (currentRef === undefined) return;
if (currentRef === undefined) {
await this.#sleep();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

kixelated and others added 2 commits October 11, 2026 16:06
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>
@kixelated
kixelated marked this pull request as ready for review October 11, 2026 23:12
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d67014c-3863-4237-8ca5-3fde66b60764

📥 Commits

Reviewing files that changed from the base of the PR and between c629d0e and fdb210a.


📒 Files selected for processing (9)
  • js/watch/src/sync.test.ts
  • js/watch/src/sync.ts
  • js/watch/src/video/decoder.test.ts
  • js/watch/src/video/decoder.ts
  • quest/m1/watch-break-av-sync.md
  • test/interop/clients/js/media.ts
  • test/interop/clients/js/src/resume.test.ts
  • test/interop/clients/js/src/resume.ts
  • test/justfile

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread js/watch/src/video/decoder.ts Outdated
Comment on lines +471 to +472
await this.sync.wait(timestamp, effect.abort);
if (effect.abort.aborted) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: fdb210a265

ℹ️ 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".

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@kixelated
kixelated added this pull request to the merge queue Oct 11, 2026
Merged via the queue into main with commit 8b83bb5 Oct 11, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the quest/m1/watch-break-av-sync branch October 11, 2026 23:52
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