Skip to content

fix(room): one watch pipeline per tile, room audio, and chat window - #43

Merged
kixelated merged 12 commits into
mainfrom
quest/m0/room-media
Nov 26, 2026
Merged

kixelated merged 12 commits into
mainfrom
quest/m0/room-media

Conversation

@kixelated

@kixelated kixelated commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/room-media.md.

Problem

  • Every remote broadcast was watched twice. @moq/room's roster opened a Watch.Player per member (catalog, user, and preview subscriptions), and Hang opened its own WatchBroadcast for the same path. Neither one claimed connection.viewers, so tiles ran ABR and probing without sharing the downlink estimate.
  • Mono microphones (the default) skipped the StereoPannerNode, so they never panned.
  • Unmuting from 0 never faded. An exponential ramp can't leave 0, so the gain stayed silent for the whole 200 ms and then jumped. The audit expected a RangeError, but Chrome doesn't throw; it renders 0 → 0 → 1 (see Validation).
  • Notifications and high-quality TTS played straight to destination, ignoring mute and speaker volume.
  • A meme audio clip that was replaced or cancelled while still loading started playing anyway, with nothing to stop it.
  • Remote hang/location.json and hang/chat.json went into the UI unvalidated. Chat was a lossy snapshot, so a repeated or quickly replaced message could disappear.
  • The lobby hid browser support warnings (show="never"), and decoder failures were invisible.

Approach

  • One pipeline per tile (room/watch.ts, room/index.ts): WatchBroadcast wraps a headless Watch.Player with no canvas. Video downloads while the room canvas is visible ("always"/"never"), and audio while sound is on. The player's own speaker output is held at volume 0 because Hang sends audio.root through its spatial graph. The player claims connection.viewers. Hang now discovers broadcasts from the announce stream itself, using @moq/room's parse and the same capture handling, instead of MoqRoom, whose Member hard-wires a canvas player that Hang can't feed or reuse.
  • Audio (room/audio.ts, room/sound.ts, room/tts): a shared fade() helper does a linear ramp anchored at the current value, so muting and unmuting fade both ways. Every remote voice goes through a StereoPannerNode, which up-mixes mono. Notifications and worker TTS go through Sound.gain. Browser speech can't, so say() skips it while muted. Meme audio races its load against the effect and stops the node on cleanup.
  • Metadata (room/metadata.ts): location and chat payloads are checked against zod/mini schemas and read with latest(). A malformed value ends that subscription and never reaches the UI, matching @moq/room's consume. Snapshot tracks finish() before close(). Messages now also go out as @moq/room's Chat window (chat track, advertised as hang.messages), one record per send. Typing stays on hang/chat.json. The reader decodes the window frame by frame. Only its first frame collapses to the newest record, so a late joiner's catch-up shows the latest message without replaying a superseded meme command. A later frame that restates several unseen records (after a lost group) delivers each in order, one event-loop turn apart, since signal writes coalesce and the meme effect would otherwise see only the last.
  • Support and errors (sup.tsx, index.tsx, room/debug.ts): the lobby shows <moq-watch-support> and <moq-publish-support> with show="warning". Decoder out.error is logged, and the track debug overlay marks the failed rendition in red with its message. I dropped the unused support-element imports from index.tsx.
  • Tests (app/test/setup.ts): the Bun preload stubs MoQ's Vite-only ?worklet imports, so app tests can import @moq/room at runtime.

Choices I made without asking:

  • Hang runs its own discovery rather than waiting on an upstream @moq/room change. That change is listed under Follow-ups.
  • TTS now goes through Sound.gain, which plays at half the speaker volume (the same level as notifications).
  • Decoder errors show only in the console and the debug overlay. A user-facing error badge would be new UI design, so I left it out.
  • I left the remote gain's initial value alone, since fix: preserve speaker gain across reload and mute #35 owns it.

Impact

  • Wire: additive and safe across mixed versions. New peers advertise hang.messages and publish the chat window. They still write message on hang/chat.json, and they read that legacy field from any broadcast whose catalog lacks hang.messages. Old and new tabs keep chatting both ways, and rolling back is clean. A later quest removes the legacy field.
  • Downlink: each remote broadcast drops its second catalog, user, and preview subscription. Tiles now split one shared receive estimate instead of each running ABR alone.
  • Public API: none. Hang is an app, and WatchBroadcastProps is internal.
  • Merged with main: keeps fix: preserve speaker gain across reload and mute #35's muted-start remote gain, fix(auth)!: harden OAuth, JWT auth, avatar uploads, and chat sanitization #44's chat sanitizer, chore!: remove the Tauri native app #47's Tauri removal, and chore(infra): remove self-hosted relay deployment in favor of moq.pro #48's infra removal.
  • Quests: this finishes m0's last quest, so the seven m1 audit quests drop their satisfied Required: m0 link (quest check rejects a link to a finished milestone).
  • Docs: AGENTS.md and CONTRIBUTING.md now let agents start just dev to validate a change on its real surface, stopping it when done.

Alternatives

  • Reusing @moq/room's Member: its Watch.Player is private and paints only to a canvas, so it can't feed Hang's WebGL renderer or audio graph without upstream API changes.
  • Building the player by hand and adding the viewer claim: that would copy Watch.Player's private holdViewer logic and its offline-tail logic. The headless player already has both.
  • An ordered UI queue for chat commands: the two review fixes (subscriptions keyed per track, and the parse raced against the effect) cover live bursts without changing ChatFields across the local, fake, and demo sources.
  • Using setTargetAtTime for fades: it never reaches exactly 0 within the 200 ms window, so muting would leave audible residue.

Caused by

  • moq-dev/hang.live#28 - kept a second WatchBroadcast beside @moq/room's per-member player, without connection.viewers (found by person; 2026-11-25 audit).
  • The audio-graph bugs date from the pre-PR history ("Move room into src."), so no single PR caused them.

Decisions

Settled by the maintainer on 2026-11-25 (comment):

  • Late-joiner meme replay: ✅ fix it, applying only the newest record of the initial window (rejected: accept it, drop the PR)
  • Live check: ✅ an agent runs just dev, with AGENTS.md reworded to "Start just dev only to validate a change on its real surface, and stop it when done." (rejected: maintainer runs it, merge on checks alone)
  • ✅ Keep the follow-up quest/m1/chat-window-only.md (rejected: drop it)
  • ✅ The @moq/room headless-member gap goes to moq-dev/moq's /quest-plan (rejected: track it here)

Settled by the maintainer on 2026-11-25 (comment):

  • Catch-up after a delivery gap: ✅ fix it, collapsing only the first frame and delivering later frames' unseen records in order (rejected: accept it, drop the PR)

Validation

  • quest gate just check: Quest, TypeScript, Biome, API and app tests, and native checks all pass. The new tests cover a repeated chat message arriving twice, the legacy message field being ignored once the window is advertised, and a malformed location being rejected.
  • quest gate just build: passes.
  • Real Chrome, using OfflineAudioContext with the same schedules the code uses:
    • Unmute from 0, old: t=0.1 → 0, t=0.19 → 0, t=0.3 → 1 (no fade, no throw).
    • Unmute from 0, new: 0.5, 0.95, 1.
    • Mono at pan -1, old: L=1, R=1 (not panned). New: L=1, R=0.
  • After review: chat subscriptions are keyed per track name, so an unrelated catalog edit no longer reopens the window. The new test fails on the previous code (4 deliveries instead of 2). TTS follows its owning Sound.enabled, and the chat parse is raced against its effect. quest gate just check passes on 0e7beb6.
  • Late-joiner fix: app/src/room/metadata.test.ts publishes hi, /huh, bye, then joins; the old reader delivered all three to the meme effect, the new one only bye, and a later live send still arrives.
  • quest gate just check passes on the merged head bf414a5.
  • Gap recovery: a new metadata.test.ts case shows hi, loses its group (TooFarBehind), then gets a header restating hi, /huh, bye. The watcher must see hi, /huh, bye. It fails on bf414a5 (no /huh) and also fails with in-order delivery but no yield between records (signal writes coalesce); it passes on the fix (3/3 runs). No new live check: a delivery gap can't be forced from two tabs, and the test drives the real track and window decoder.
  • quest gate just check passes after merging main (chore(infra): remove self-hosted relay deployment in favor of moq.pro #48) at 73a6738.
  • Live room (just dev, separate headless Chrome profiles with fake camera and mic, driven by agent-browser):
    • Lobby shows both support warnings (headless Chrome lacks H.265).
    • Two participants see each other's video and hear each other: each remote voice reaches its panner through a running context with signal (peaks 0.2 to 0.9). A closed participant's tile leaves.
    • Mono pans: the source is 1 channel; after dragging tiles apart, pan −0.366 gave L 0.893 / R 0.486 and pan +0.385 gave R ≈ 2× L, matching equal-power panning.
    • Speaker mute fades the remote gain linearly 1 → 0.79 → 0.57 → 0.31 → 0, and unmute 0 → 0.21 → 0.43 → 1. Notifications (gain 0.5) fade with it.
    • Chat shows on the peer; the same text sent twice notifies twice; /huh plays huh.webm live.
    • Late joiner within the 10 s window after alpha, /huh, omega: shows only omega, one notification, no meme (three runs).

Follow-ups

  • quest/m1/chat-window-only.md [XS] - once this deploy has been live for a day, stop writing and reading the legacy message field on hang/chat.json. No open decisions.
  • moq-dev/moq (for /quest-plan there, which the coordinator runs): @moq/room's Room opens a canvas-bound Watch.Player for every member, so an app with its own renderer has to re-implement discovery, as Hang now does. Options: a discovery-only roster, or a headless Member that exposes its player, takes a visible input, and can turn off speaker output. Hang would then go back to MoqRoom.

Models

  • Size: M
  • Implementer: Claude Code, claude-opus-5-5, high
  • Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, M)
  • Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: 73a6738

  • Base: origin/main at 76d1206

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

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

  • Session: 01a215e7-2e54-7441-86f4-29c2ce1b939b, round 5

  • Score: 10/10, The head preserves live commands recovered after a gap and still shows late joiners only the newest retained message.

  • Rounds: 5; first round 3 (medium 3); findings 5 (medium 5): fixed 5, refuted 0, open 0

  • Findings: none

  • Notes, the author's to take or leave:

    • app/src/room/metadata.ts:398: Avoid timer throttling while draining recovered chat
  • The last round's findings, at bf414a5:

    • Fixed: medium, app/src/room/metadata.ts:389: Preserve live meme commands recovered after a delivery gap; The reader collapses only the first frame and yields between later recovered records, and the regression test asserts that the viewer receives both `/huh` and `bye` after `TooFarBehind` (`app/src/room/metadata.ts:392`, `app/src/room/metadata.test.ts:187`).

Quest-Claim: 17522c5c5b85c592
kixelated and others added 2 commits November 25, 2026 19:24
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 Deduplicate remote watch pipelines and fix room audio fix(room): one watch pipeline per tile, room audio, and chat window Nov 26, 2026
…S follows its own sound

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (2026-11-25, /quest-run):

  • Fix the open review finding: apply only the newest message from the initial chat batch in subscribeMessages, with a test.
  • Reword AGENTS.md's just dev rule to "Start just dev only to validate a change on its real surface, and stop it when done." Then run just dev and a two-tab browser check of this PR.
  • Keep follow-up quest/m1/chat-window-only.md.
  • The upstream @moq/room headless-member gap goes to moq-dev/moq's /quest-plan.
  • Pick: /quest-merge once the new head is reviewed and checks pass.

(Written by Claude Opus 5.5 with high)

kixelated and others added 4 commits November 25, 2026 20:41
# Conflicts:
#	quest/m0/room-media.md
A late joiner's first frame restates the retained window, and each record
ran the meme effect in turn, so a superseded /huh could play once.
Read frames with the window decoder and show only each frame's newest push.

Also let agents run `just dev` to validate a change on its real surface.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…UTING on just dev

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Applied the maintainer decisions on bf414a5:

  1. subscribeMessages reads the chat window frame by frame and applies only each frame's newest record. A new test fails on the old code (it delivered hi, /huh, bye; now only bye).
  2. AGENTS.md (and CONTRIBUTING.md) now say to start just dev only to validate a change on its real surface and stop it when done. I ran the live multi-tab check; the results are under ## Validation.
  3. Kept quest/m1/chat-window-only.md.
  4. The @moq/room headless-member gap stays under ## Follow-ups for moq-dev/moq's /quest-plan.

Merged main, including #35, #44, and #47. just check passes. Review round 4 raised one new finding: always collapsing to the newest record drops a live meme command after a delivery gap. That hit next decide, so it is under ## Waiting.

(Written by Claude Opus 5.5)

@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (2026-11-25, /quest-run): fix the round-4 catch-up finding. Only the first frame after joining applies just its newest message; later catch-up frames deliver every message in order. Pick stays /quest-merge.

(Written by Claude Opus 5.5 with high)

kixelated and others added 2 commits November 25, 2026 21:12
Only the first window frame after joining collapses to its newest record.
A later frame restating several unseen records, as after a lost group,
now delivers each in order, one event-loop turn apart so the meme effect
sees a `/huh` before the text that followed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Applied in 73a6738 (da1a6b2): subscribeMessages collapses only the first window frame after joining; later frames deliver every unseen record in order, one event-loop turn apart so the meme effect sees each. New test a watcher recovers every chat message a delivery gap skipped fails on bf414a5 and passes now. Also merged main (#48).

(Written by Claude Opus 5.5)

@kixelated
kixelated marked this pull request as ready for review November 26, 2026 05:14
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review 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: db84a83e-63bf-4bb6-bebc-91752f226747
Commits

Reviewing files that changed from the base of the PR and between c5b3e14 and 734098d.

Files selected for processing: 23

  • AGENTS.md
  • CONTRIBUTING.md
  • app/src/index.tsx
  • app/src/room/audio.ts
  • app/src/room/broadcast.ts
  • app/src/room/debug.ts
  • app/src/room/index.ts
  • app/src/room/metadata.test.ts
  • app/src/room/metadata.ts
  • app/src/room/sound.ts
  • app/src/room/tts/index.ts
  • app/src/room/watch.ts
  • app/src/sup.tsx
  • app/test/setup.ts
  • quest/m0/room-media.md
  • quest/m1/audit-code.md
  • quest/m1/audit-cost.md
  • quest/m1/audit-deps.md
  • quest/m1/audit-docs.md
  • quest/m1/audit-instructions.md
  • quest/m1/audit-tests.md
  • quest/m1/audit-tree.md
  • quest/m1/chat-window-only.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 (squash) November 26, 2026 05:26
@kixelated
kixelated merged commit bd75bd7 into main Nov 26, 2026
2 checks passed
@kixelated
kixelated deleted the quest/m0/room-media branch November 26, 2026 05:29
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