Skip to content

fix(watch-party): stop displaced connections from reconnecting - #1287

Merged
Quick104 merged 1 commit into
mainfrom
fix/watch-party-connection-replacement
Sep 22, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/watch-party-connection-replacement

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1284 (S2)

Companion correction: #1286 handles common suggestion broadcasts. Both PRs target main and can merge independently.

When another device connects as the same room member, the displaced socket closes without an explanation. The web reconnects and can repeatedly replace the other device.

Approach

Send a terminal v2 connection_replaced frame after the membership transaction commits. The existing socket writer prioritizes and flushes it before closing, with a one-second bound for a blocked peer. Both local takeover and cross-node reconciliation close the captured loser; stale callbacks cannot disconnect the winner.

The web retains the active room, pauses displaced playback, explains the takeover and offers explicit rejoin. Guards prevent late socket messages, HTTP selection updates, autoplay and media callbacks from resuming displaced playback. A capability flag and protocol documentation define the signal. V1 keeps its existing close behavior.

Validation

  • PostgreSQL race tests and real WebSocket tests passed for replacement delivery before close, transaction rollback, stale callbacks, both takeover paths and v1 compatibility. Blocked-writer tests verify the bounded close.
  • Shared development deployment checks of the combined fix(watch-party): make suggestion broadcasts consistent and stop displaced reconnects #1284 implementation passed for takeover in both process directions, mixed v1/v2 sockets and healthy winners. A temporary second process used the production room/authentication code with the same PostgreSQL and Redis services.
  • Desktop and mobile-sized Chrome verified lobby takeover, active room history, advancing playback, displaced-player pause and explicit rejoin. Controlled browser socket recovery opened one fresh socket and received a snapshot/pong in 1,203 ms. A live five-minute credential-expiry check closed the socket after 300,071 ms without a replacement signal and reconnected with a fresh ticket.
  • The isolated PR branch passed Go race tests for replacement service/socket/writer behavior, capability wiring and PostgreSQL takeover/rollback, plus the web socket suite. The four affected web suites also passed before the test-only split.
  • The full pre-PR gate ran on the combined fix(watch-party): make suggestion broadcasts consistent and stop displaced reconnects #1284 implementation. Builds, formatting, vet, changed-line Go lint, web lint, 4,584 web tests and all required repository verification targets passed. make test-go passed 156 packages; only TestAdminResourceCapabilitiesAndScope failed on macOS. The unchanged base fails identically because resource reporting is Linux-only.

Risks

Older v2 clients that ignore the signal can still reconnect and displace the winner. Apple adoption is tracked in Silo-Server/silo-apple#344 and Android follow-up in Silo-Server/silo-android#355; neither physical native client was tested here. These checks prove controlled socket recovery, not a real network outage. A broken transport can prevent delivery of the terminal frame. Deploy the correction to every API node before relying on it across the cluster. Jellyfin compatibility does not use these sockets.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Codex in T3 Code.
  • Tool(s): GitHub CLI (gh), Go toolchain, golangci-lint, pnpm/Vitest, Playwright with Chrome, SSH and Docker; repository unslop skill for PR prose.
  • Model(s): gpt-6-astra for implementation and independent review agents.
  • Involvement: AI-assisted implementation, tests, documentation, deployment verification and PR preparation at the maintainer's direction.
  • Adversarial review: A separate Codex agent traced transactional ownership, the bounded writer, stale callbacks, auth refresh, rejoin and player lifecycle. Review found that late HTTP selection updates could remount a displaced player and pending autoplay callbacks could resume it; both were fixed and covered by regression tests. The final review also checked the native media-event guard and found no remaining introduced defect or private evidence in the patch.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-09-22T01:12:39.771014Z 999c9ea PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 22 minutes.

Check out review usage here.

View limit details

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

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 21c129d6-75a5-4010-b5fd-7994557fae5b

📥 Commits

Reviewing files that changed from the base of the PR and between 40bb028 and 999c9ea.

📒 Files selected for processing (21)
  • contracts/api/v2/fixtures/get_system_info_ok.json
  • contracts/api/v2/fixtures/watch_together_capabilities.json
  • contracts/api/v2/openapi.json
  • docs/realtime-api.md
  • internal/api/handlers/watch_together.go
  • internal/api/handlers/watch_together_socket_v2_test.go
  • internal/api/handlers/watch_together_writer_test.go
  • internal/apiv2/watch_together_capabilities.go
  • internal/apiv2/watch_together_capabilities_test.go
  • internal/watchtogether/connection_replaced_test.go
  • internal/watchtogether/runtime.go
  • internal/watchtogether/service.go
  • web/src/api/v2/schema.ts
  • web/src/api/v2/watchTogetherSocket.test.tsx
  • web/src/pages/watchtogether/WatchTogetherRoomPage.test.tsx
  • web/src/pages/watchtogether/WatchTogetherRoomPage.tsx
  • web/src/player/components/VideoPlayer.test.tsx
  • web/src/player/components/VideoPlayer.tsx
  • web/src/player/components/WatchPage.test.ts
  • web/src/player/components/WatchPage.tsx
  • web/src/player/hooks/useWatchTogetherRoomConnection.ts

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.

@greptile-apps greptile-apps 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.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@Quick104
Quick104 merged commit 942ed9a into main Sep 22, 2026
10 checks passed
@Quick104
Quick104 deleted the fix/watch-party-connection-replacement branch September 22, 2026 01:24
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