Skip to content

feat(watch-together): give the feature a way in, and fix what had never run - #105

Closed
RXWatcher wants to merge 4 commits into
Silo-Server:mainfrom
RXWatcher:feat/watch-together-entry
Closed

RXWatcher wants to merge 4 commits into
Silo-Server:mainfrom
RXWatcher:feat/watch-together-entry

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

Watch Together was fully built and completely unreachable. The room machinery — create/join, suggestions and voting, the WebSocket transport, RoomSyncEngine — compiled, and both apps routed to the lobby and the synced player, but nothing could open either.

  • Phone was gated behind CLIENT_WATCH_TOGETHER_SURFACE_ENABLED = false, with the entry sheet already wired into AppNavigation.
  • TV had no entry point at all. TvItemDetailScreen declared an onWatchTogether callback and TvAppNavigation wired it to the lobby and synced-player routes, but no code path ever invoked it and TvWatchTogetherEntryDialog was never instantiated anywhere.

Because no user could reach any of it, none of this code had ever run. Reading it turned up four defects, two of which would have broken every room in its first seconds.

The entry points

TV gets the missing half: a Watch Together action in the detail overflow that opens the entry dialog, hands off to the join-code dialog, and routes on the resolved room exactly as the phone does — host with a selection goes straight to the synced player, everything else to the lobby.

Hosting targets whatever Play would launch, so a series or season hosts its next-up episode rather than the container, which cannot be a room selection. Audiobooks are excluded: a room's transport drives a video player and the lobby's "now playing" has nothing to show for one. Movies previously had no overflow button at all, so the action brings one with it.

CLIENT_WATCH_TOGETHER_SURFACE_ENABLED now gates both platforms together, so the surface can still be withdrawn in one edit.

The four defects

1. Frames sent before the socket was up vanished silently. WatchTogetherRealtimeClient.sendText was session?.send(...) — no error, no queue, no retry. The interface documented the opposite ("repository gates on connection"); nothing did. Sends now report whether they reached an open session.

2. attach_session could be lost for the life of the room. Both controllers set the sent-latch before awaiting the send, and the only path that re-arms it is a server-had-our-session → hasn't transition, which cannot happen for a session the server never had. The latch is now set only on a delivered frame.

This one matters more than it looks. The server's readiness barrier keys entirely on the attached session — activeParticipantCountLocked, allParticipantsReadyLocked and handleWaitingDeadline all skip members with sessionID == "". A member whose attach was dropped isn't someone the room waits for; it's someone the room doesn't know is watching. Playback starts without them and nothing logs an error.

3. The clock stayed unsynced for up to 15s. The ping loop fires immediately and races the handshake; on a dropped first ping no pong arrives until the next interval. RoomSyncEngine's documented fallback with no offset is to apply commands immediately, discarding the scheduled-execute barrier that keeps members in step — during exactly the window where someone presses play. Pings now retry at 1s until the socket is up and an offset exists, then settle to the normal interval.

4. Room-scoped calls addressed an empty room id. They resolved roomId ?: "", turning "there is no room" into a request against a malformed path whose 404/405 surfaced as though the server had rejected the user's action. They now fail fast with no_active_room — and fall back to the id connect() was called with, so voting still works in the windows where the snapshot is legitimately absent (before the first frame, and after a transient close).

Also

  • votedIds was an unsynchronised MutableSet written from an IO dispatcher and the WebSocket fold at once; it is a StateFlow<Set<String>> updated atomically now.
  • The state-report cadence gate had been hand-copied into the TV controller with a comment asking the two to be kept in lockstep. It moves to shared beside roomTransportAuthorized — a room is one protocol, and two platforms disagreeing about when to report is a desync that only appears with two devices in a room. Its test moves to commonTest.
  • MAX_RECONNECT_ATTEMPTS documented the opposite of the code. The behaviour is deliberate and load-bearing (there is a test for it); only the comment changed.

Testing

assembleDebug and the full unit suites green on shared, androidApp and androidTvApp, from a clean --rerun-tasks run on this branch based on main.

New tests:

  • TvWatchTogetherSurfaceSourceTest — the TV failure mode was absence of wiring, which nothing behavioural could catch, because the dialog was not reachable to observe.
  • Repository tests asserting sends report undelivered before the socket is up, and delivered once connected.
  • RoomStateReportGateTest moves to commonTest with the gate.

Not yet exercised against a live server. The TV build is installed on an emulator, but a room needs two participants and I have not run one end to end. The server side was read closely — transport authority mirrors the client's shared roomTransportAuthorized, the waiting deadline is epoch-guarded, persist conflicts restore and re-arm rather than dropping the transition — and no server changes were needed.

Worth flagging for whoever picks this up: there is no Apple counterpart. silo-apple has no Watch Together at all, so this surface has no gold-standard client to mirror and anything ambiguous about its shape is a product decision rather than a parity bug.

AI-use disclosure

Written by Claude Opus 5 (Claude Code) working with @RXWatcher, who directed the work and reviewed it. The defects were found by reading the code, not by running it.

Summary by CodeRabbit

  • New Features
    • Enabled Watch Together from Android TV item detail menus, with host/join flows and lobby navigation.
  • Bug Fixes
    • Improved delivery handling so playback updates are not treated as sent when disconnected.
    • Added faster clock-sync retries until synchronization is established.
    • Prevented room requests from being sent without an active room.
    • Improved preservation of voting state across updates and reconnects.
  • Tests
    • Expanded coverage for Watch Together visibility, navigation, delivery failures, and room-state reporting.

RXWatcher and others added 4 commits July 26, 2026 14:45
Watch Together has been fully built and completely unreachable. The room
machinery — create/join, suggestions and voting, the WebSocket transport,
RoomSyncEngine — compiled, and both apps routed to the lobby and the
synced player, but nothing could open either.

Phone was one const: CLIENT_WATCH_TOGETHER_SURFACE_ENABLED gated an entry
sheet that was already wired into AppNavigation.

TV had no entry point at all. TvItemDetailScreen declared an
onWatchTogether callback and TvAppNavigation wired it to the lobby and
synced-player routes, but no code path ever invoked it and
TvWatchTogetherEntryDialog was never instantiated anywhere. This adds the
missing half: a "Watch Together" action in the detail overflow that opens
the entry dialog, hands off to the join-code dialog, and routes on the
resolved room the same way the phone does — host with a selection goes
straight to the synced player, everything else to the lobby.

Hosting targets whatever Play would launch, so a series or season hosts
its next-up episode rather than the container, which cannot be a room
selection. Audiobooks are excluded: a room's transport drives a video
player and the lobby's "now playing" has nothing to show for one.

Movies previously had no overflow button at all, so the action brings one
with it.

Worth noting there is no Apple counterpart to mirror — silo-apple has no
Watch Together whatsoever — so the shape here is Android's own.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
WatchTogetherRealtimeClient.sendText was `session?.send(...)` — every
client to server frame silently vanished if the socket had not finished
connecting, with no error and no retry. The interface even documented the
opposite ("repository gates on connection"); nothing did.

Two consequences, both on phone and TV, and both in the first seconds of
a room:

attach_session was lost for the life of the room. Both controllers set
the sent-latch BEFORE awaiting the send, and the only path that re-arms
it is a server-had-our-session to hasn't transition — which cannot happen
for a session the server never had. So a room could run with a member's
playback session permanently unknown to it.

The clock stayed unsynced for up to 15s. The ping loop fires immediately,
races the handshake, and on a dropped first ping no pong arrives until
the next interval. RoomSyncEngine's documented fallback with no offset is
to apply commands immediately, which discards the scheduled-execute
barrier that keeps members in step — during exactly the window where
someone presses play.

Sends now report whether they reached an open session. The latch is set
only on a delivered frame, and pings retry at 1s until the socket is up
and an offset exists, then settle to the normal interval.

Found by reading the code, not by running it: this feature has never been
reachable by a user, so none of it has ever been exercised.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
…ting

Four follow-ups from reading the sync path.

Room-scoped calls resolved their room id as `roomId ?: ""`, turning "there
is no room" into a request against a malformed path. It is reachable —
the snapshot is cleared on close and on losing the connection, and the UI
can still have an action in flight — and the 404/405 surfaced to the user
as though the server had rejected what they did. All nine call sites now
return a no_active_room error without touching the API.

votedIds was an unsynchronised MutableSet written from two directions at
once: REST completions on an IO dispatcher and the websocket fold. It is
a StateFlow of an immutable Set now, so updates are atomic and readers
always see a whole set.

The state-report cadence gate was hand-copied into the TV controller with
a comment asking the two copies to be kept in lockstep. It now lives in
shared next to roomTransportAuthorized, for the same reason that is
shared: a room is one protocol, and two platforms disagreeing about when
to report is a desync that only appears with two devices in a room. Its
test moves to commonTest with it.

MAX_RECONNECT_ATTEMPTS documented the opposite of what the code does —
failures reset on a clean connection end, not on any healthy event, which
is deliberate and load-bearing (a server emitting one good frame per
attempt would otherwise reconnect forever). The code was right; the
comment is now too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
Room-scoped calls resolve their id from the room snapshot, which is null
until the first frame arrives over the socket and is cleared again on a
transient close. The lobby lets you vote, promote and change policy in
both of those windows, so those actions failed for a room the caller is
demonstrably connected to.

connect() knows the id; remember it and fall back to it. The snapshot
stays the preferred source.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 67b59de4-8caa-4299-aeed-fe33d4ac598c

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9fdc1 and cfef896.

📒 Files selected for processing (12)
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/RoomSyncController.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/RoomSyncStateReportGate.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailScreen.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvRoomSyncController.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/watchtogether/TvWatchTogetherSurfaceSourceTest.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/feature/ClientSurfacePolicy.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/WatchTogetherRealtimeClient.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/repository/WatchTogetherRepository.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/watchtogether/RoomStateReportGate.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/model/feature/ClientSurfacePolicyTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/repository/WatchTogetherRepositoryTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/watchtogether/RoomStateReportGateTest.kt

📝 Walkthrough

Walkthrough

The PR exposes Watch Together on Android TV, adds room-resolution dialog wiring and navigation, reports websocket send delivery status, centralizes state-report suppression, and retries synchronization pings until server time is established.

Changes

Watch Together and room synchronization

Layer / File(s) Summary
Shared room state and realtime delivery
shared/src/commonMain/kotlin/org/siloserver/silo/watchtogether/*, shared/src/commonMain/kotlin/org/siloserver/silo/network/*, shared/src/commonMain/kotlin/org/siloserver/silo/repository/*, shared/src/commonTest/kotlin/org/siloserver/silo/watchtogether/*, shared/src/commonTest/kotlin/org/siloserver/silo/repository/*
Adds shared state-report gating, Boolean websocket delivery results, active-room validation, atomic vote tracking, reset behavior, and corresponding tests.
Controller attach and synchronization retries
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/RoomSyncController.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvRoomSyncController.kt
Uses the shared report gate, latches session attachment only after delivery, and retries pings at a shorter cadence until engine time synchronization exists.
TV Watch Together entry flow
shared/src/commonMain/kotlin/org/siloserver/silo/model/feature/ClientSurfacePolicy.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailScreen.kt, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/watchtogether/*, shared/src/commonTest/kotlin/org/siloserver/silo/model/feature/ClientSurfacePolicyTest.kt
Enables the TV surface, adds the detail overflow action and dialogs, forwards resolved rooms to navigation, excludes audiobooks, and verifies source wiring.
Estimated code review effort: 4 (Complex) ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Viewer
  participant TvItemDetailScreen
  participant WatchTogetherViewModel
  participant TvAppNavigation
  Viewer->>TvItemDetailScreen: select Watch Together
  TvItemDetailScreen->>WatchTogetherViewModel: host or join room
  WatchTogetherViewModel-->>TvItemDetailScreen: resolved RoomSnapshot
  TvItemDetailScreen->>TvAppNavigation: open WatchTogetherLobby
Loading

Possibly related PRs

Suggested reviewers: quick104

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@RXWatcher

Copy link
Copy Markdown
Contributor Author

Closing — opened against the wrong remote. This work lives on the RXWatcher fork.

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