Skip to content

fix(js): hang catalog/CMAF, watch rotation, and room metadata bugs - #9344

Merged
kixelated merged 10 commits into
mainfrom
quest/m1/precut-audit/js-media-fixes
Nov 22, 2026
Merged

kixelated merged 10 commits into
mainfrom
quest/m1/precut-audit/js-media-fixes

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes five JS media correctness bugs from the pre-cut full-codebase audit, and finishes quest/m1/precut-audit/js-media-fixes.md.

Changes

  • @moq/hang catalog encode (js/hang/src/catalog/root.ts): encode() used to write an unknown container or projection as the parser's { kind: "unknown", raw } wrapper. It now writes the original object, so a republisher passes a future kind through unchanged, as rs/hang's serializers do.
  • @moq/publish catalog producer (js/publish/src/catalog.ts): it used to store encode()'s output and re-encode it on the next edit. Now that encode() writes unknown kinds verbatim, it is no longer idempotent: a container whose real kind is the string "unknown" would be dropped on the next edit. The producer now keeps the parsed catalog it edits apart from the written one, and encodes only the parsed one. Found in local review.
  • @moq/hang stats and echo (js/hang/src/snapshot.ts, stats.ts, echo.ts): report rendition maps used the catalog's renditions() helper. That helper skipped any entry with version above the catalog draft and refused the report on a non-numeric version. They now use renditionsSchema, a plain __proto__-safe map. Like Rust's BTreeMap<String, Rendition>, it treats version as just another unknown field.
  • @moq/hang CMAF esds (js/hang/src/cmaf/decode.ts): the old flat scanner assumed the ES_Descriptor flags were zero. With streamDependenceFlag or URL_Flag set, it misread the descriptors and returned no AudioSpecificConfig, so AAC got no decoder description. The new parser walks ES_Descriptor → DecoderConfigDescriptor → DecoderSpecificInfo inside each descriptor's declared size, skips the optional fields (ISO/IEC 14496-1 §7.2.6.5), and throws on a truncated descriptor where the old scanner silently returned nothing.
  • @moq/watch rendition pick (js/watch/src/video/source.ts): byDimensions compared coded sizes against the element's displayed box. It now turns the coded size by the section's rotation first, using @moq/video's rotateDimensions. A 90°/270° stream in a portrait box now picks the largest rendition that fits as shown. Target.width/height docs now say they are sizes as shown.
  • @moq/room metadata (js/room/src/metadata.ts): catalog.hang is validated with zod, checking only the user/preview entries it reads so app extensions still pass through. A malformed section is refused as absent, with a warning. Each track name is its own computed, so a catalog update that leaves it alone (a new rendition, hang.chat) keeps the subscription. Before, every such update cleared the signals and resubscribed.

Choices made without asking:

  • The esds parser now throws on truncated or overlong descriptors instead of returning undefined, per fail-loud. A valid esds with no DecoderSpecificInfo (such as MP3) still returns undefined.
  • A malformed hang section warns and is treated as absent, matching how subscribeJson already treats malformed track values.

Validation

  • Each fix has a unit test that fails on the parent code and passes now. I checked this by swapping each file back to HEAD before the fix. One exception: the OCR-only and every-flag esds cases happened to pass under the old scanner by luck.
  • esds differential against ffmpeg: I took a real ffmpeg AAC fMP4, rewrote its ES_Descriptor to set each flag combination (0x00, 0x80, 0x40, 0x20, 0xE0) with matching optional fields, then compared decodeInitSegment's description to the extradata ffprobe reads. All five match (120856e500). The old parser returned nothing for 0x80 and 0x40.
  • just check passes.
  • Not done: no browser run of <moq-watch> with a rotated broadcast. The watch test drives the real Source with real signals.

Public API

None breaking. @moq/publish CatalogProducer keeps its edit state in the parsed shape (internal). @moq/watch Target.width/height docs now say they are sizes as shown; that is a behavior fix for rotated streams. @moq/hang encode() now writes unknown containers and projections verbatim. Wire: none.

Caused by

  • moq-dev/moq#2439 - added the { kind: "unknown", raw } container wrapper without unwrapping it in encode (found by reviewer; pre-cut audit)
  • moq-dev/moq#7498 - reused the catalog renditions() map, with its version skipping, for stats and echo reports (found by reviewer; pre-cut audit)
  • moq-dev/moq#1359 - added the esds scanner that assumes zero ES_Descriptor flags (found by reviewer; pre-cut audit)
  • moq-dev/moq#1411 - added byDimensions comparing coded sizes, ignoring rotation (found by reviewer; pre-cut audit)
  • moq-dev/moq#3634 - one effect over the whole catalog for metadata subscriptions, with an unvalidated hang section (found by reviewer; pre-cut audit)

Follow-ups

  • quest/m1/json-snapshot-refusal.md - @moq/room's subscribeJson matches err instanceof z.core.$ZodError, which breaks the rule against matching on errors. The proposed fix is for @moq/json's Snapshot.Consumer to skip and report schema refusals itself. No open decisions; the recommended shape is in its Plan.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: 975ac8b

  • Base: origin/main at 675206c

  • Risk: high, Changes to hang catalog JSON serialization and public video target semantics can affect published consumers and deployed peers; reverting restores the code but cannot recall catalogs already transmitted.

  • Classified: high by Codex, gpt-6.1-sol, low effort, session 01a201a0-cedc-7dd1-b8bb-9737564ad701

  • Reviewer: Codex, gpt-6.1-sol, high effort

  • Session: 01a20195-b459-7a13-81cf-2d7cdfec3c55, round 2

  • Score: 10/10, The parsed-state separation fixes the earlier finding, and inspection of the incremental changes found no new issues.

  • Rounds: 2; first round 1 (medium 1); findings 1 (medium 1): fixed 1, refuted 0, open 0

  • Findings: none

  • The last round's findings, at 9bc8b00:

    • Fixed: medium, js/hang/src/catalog/root.ts:147: Keep serialized unknown kinds out of editable catalog state; js/publish/src/catalog.ts now retains parsed edits in #value and publishes #wire, preserving unknown container and projection wrappers across later edits; the added regression test covers this scenario.

kixelated and others added 9 commits November 21, 2026 20:37
…batim

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cross unrelated updates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Fix JS hang catalog/CMAF, watch video rotation, and room metadata bugs fix(js): hang catalog/CMAF, watch rotation, and room metadata bugs Nov 22, 2026
… its own output

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 22, 2026 05:01
@coderabbitai

coderabbitai Bot commented Nov 22, 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 6 seconds.

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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d5b26dfa-2552-459a-ae65-262de756762c
Commits

Reviewing files that changed from the base of the PR and between e140dae and 975ac8b.

Files selected for processing: 16

  • js/hang/src/catalog/root.test.ts
  • js/hang/src/catalog/root.ts
  • js/hang/src/cmaf/decode.test.ts
  • js/hang/src/cmaf/decode.ts
  • js/hang/src/echo.ts
  • js/hang/src/snapshot.ts
  • js/hang/src/stats.test.ts
  • js/hang/src/stats.ts
  • js/publish/src/catalog.test.ts
  • js/publish/src/catalog.ts
  • js/room/src/metadata.test.ts
  • js/room/src/metadata.ts
  • js/watch/src/video/source.test.ts
  • js/watch/src/video/source.ts
  • quest/m1/json-snapshot-refusal.md
  • quest/m1/precut-audit/js-media-fixes.md
  • 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

@kixelated
kixelated enabled auto-merge November 22, 2026 05:05

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound. Each fix sits at the root cause: encode-time unwrapping (with the producer splitting parsed and written state so it never re-encodes its own output), a structural esds walk instead of a flag-blind scanner, rotation applied where dimensions are compared, and per-track computeds that dedupe on the track name.

Reviewed changes

I read the full diff at 975ac8b and traced each change against its callers and the helpers it uses.

  • @moq/hang catalog encode(): writes unknown container/projection back as raw. Catalog.encode has one in-repo caller, js/publish/src/catalog.ts, which now keeps the parsed draft in #value and the encoded copy in #wire, so the non-idempotence the doc comment warns about can't come up there.
  • @moq/publish CatalogProducer: comparisons for estimate monotonicity and change detection, and every update, now read #wire. Each mutate clones the parsed draft, so the producer never encodes its own output.
  • @moq/hang stats/echo rendition maps: renditionsSchema mirrors the catalog renditions() helper without the version skip. It is still __proto__-safe and still refuses the map on a malformed entry, as before.
  • @moq/hang CMAF esds: walks ES_Descriptor → DecoderConfigDescriptor → DecoderSpecificInfo within the declared sizes. The optional fields are read in the §7.2.6.5 order (dependsOn, URL, OCR). decodeInitSegment reads a single trak, so a throw only refuses that one rendition.
  • @moq/watch byDimensions: turns the coded size with rotateDimensions (@moq/video is already a dependency). orientedRenditions already accounted for rotation through Catalog.Video.orientation, so the two filters now agree.
  • @moq/room metadata: HangSchema validates only the user/preview entries. The user and preview subscriptions are now separate effects keyed on Computed track names. Signal.set skips notifying when the value is unchanged, so an unrelated catalog update leaves both subscriptions alone.

I couldn't run the tests here: bun install fails because the @moq/libav build needs Nix.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 5971145 Nov 22, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/precut-audit/js-media-fixes branch November 22, 2026 05:14
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