Skip to content

fix(p2p): deduplicate host initialization#6618

Merged
matthewevans merged 2 commits into
mainfrom
ship/fixp2p-deduplicate-host-initialization
Jul 25, 2026
Merged

fix(p2p): deduplicate host initialization#6618
matthewevans merged 2 commits into
mainfrom
ship/fixp2p-deduplicate-host-initialization

Conversation

@matthewevans

@matthewevans matthewevans commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Prevented multiplayer hosts from initializing more than once during the lobby-to-game transition.
    • Concurrent initialization requests now share the same setup process, reducing duplicate setup issues.
    • Failed initialization attempts can be retried automatically.

@matthewevans
matthewevans enabled auto-merge July 25, 2026 03:26
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@matthewevans, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b3fcc146-6b57-49ae-ba80-c56b936168e5

📥 Commits

Reviewing files that changed from the base of the PR and between f5f5338 and fb298a7.

📒 Files selected for processing (2)
  • client/src/adapter/__tests__/p2p-adapter-multiplayer.test.ts
  • client/src/adapter/p2p-adapter.ts
📝 Walkthrough

Walkthrough

P2PHostAdapter initialization now runs once across concurrent and repeated calls, retries after failure, and has a regression test covering lobby-to-game handoff behavior.

Changes

P2P host initialization

Layer / File(s) Summary
Run-once initialization guard
client/src/adapter/p2p-adapter.ts, client/src/adapter/__tests__/p2p-adapter-multiplayer.test.ts
P2PHostAdapter shares in-flight initialization, skips completed setup, clears failed promises for retries, marks successful initialization, and verifies that setup and multiplayer mode changes occur once.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • phase-rs/phase#6614: Updates game-store adapter assignment ordering for the related P2P startup handoff race.

Suggested reviewers: minion1227

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preventing duplicate host initialization in P2P.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ship/fixp2p-deduplicate-host-initialization

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/src/adapter/__tests__/p2p-adapter-multiplayer.test.ts`:
- Around line 410-418: Add a test alongside the existing host initialization
test that makes the first initialize attempt reject, verifies a subsequent
initialize succeeds, and then simulates a guest connection to assert it is
accepted exactly once. Exercise the retry through the adapter’s initialization
flow and verify failed initialization does not leave duplicate listeners or
otherwise prevent the successful retry.

In `@client/src/adapter/p2p-adapter.ts`:
- Around line 1105-1111: Make initialize and initializeInner retry-safe:
preserve single-flight behavior for concurrent callers, but reset or recreate
the constructor-owned pregameReady gate after a failed attempt so a later
successful retry can resolve it. Ensure each failed attempt removes its
onGuestConnected subscription before clearing initPromise and permitting another
retry, preventing duplicate guest processing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1bb96475-8d61-4d3d-926f-32f8614c6295

📥 Commits

Reviewing files that changed from the base of the PR and between 616d5fd and f5f5338.

📒 Files selected for processing (2)
  • client/src/adapter/__tests__/p2p-adapter-multiplayer.test.ts
  • client/src/adapter/p2p-adapter.ts

Comment thread client/src/adapter/__tests__/p2p-adapter-multiplayer.test.ts
Comment thread client/src/adapter/p2p-adapter.ts
@matthewevans
matthewevans added this pull request to the merge queue Jul 25, 2026
Merged via the queue into main with commit 4782c0c Jul 25, 2026
14 checks passed
@matthewevans
matthewevans deleted the ship/fixp2p-deduplicate-host-initialization branch July 25, 2026 04:10
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