Skip to content

fix: reveal tossup answer when all remaining players have buzzed#516

Open
xpoes123 wants to merge 1 commit into
qbreader:mainfrom
xpoes123:fix-buzz-count-after-leave
Open

fix: reveal tossup answer when all remaining players have buzzed#516
xpoes123 wants to merge 1 commit into
qbreader:mainfrom
xpoes123:fix-buzz-count-after-leave

Conversation

@xpoes123
Copy link
Copy Markdown

Summary

quizbowl/TossupRoom.js decides whether to reveal the answer after a neg by checking this.buzzes.length === Object.keys(this.sockets).length. But this.buzzes is only reset between tossups (endCurrentTossup) — Room.leave() removes the userId from this.sockets and never touches this.buzzes. So once a player negs and leaves, the buzz array carries a stale entry forever, and the equality check drifts out of sync with the actual room population.

Failure scenario

  1. Players A and B are in a room with rebuzz off.
  2. A buzzes and negs → buzzes = [A], sockets = {A, B} (1 ≠ 2, reading resumes — correct).
  3. A leaves → buzzes = [A] (stale), sockets = {B}.
  4. B buzzes and negs → buzzes = [A, B], sockets = {B} (2 ≠ 1, answer is not revealed even though every player still in the room has already buzzed).

A symmetric variant (A negs, B leaves without buzzing) makes the answer reveal after a single neg, which is also wrong when rebuzz is off.

Fix

Replace the length comparison with "every current socket has already buzzed":

Object.keys(this.sockets).every(id => this.buzzes.includes(id))

This ignores ghost entries left behind by departed players and correctly accounts for newly joined players who haven't buzzed yet (they'll be in sockets but not in buzzes, so the answer won't prematurely reveal).

Test plan

  • Two-player room, rebuzz off: player A buzzes/negs, leaves, player B buzzes/negs → answer is revealed.
  • Two-player room, rebuzz off: player A buzzes/negs, player B joins mid-tossup → reading continues until B also buzzes or the question ends (no premature reveal).
  • Single-player room, rebuzz off: solo player negs → answer revealed (unchanged behavior).
  • rebuzz on: behavior unchanged (the whole branch is gated on !this.settings.rebuzz).

🤖 Generated with Claude Code

The previous check compared `buzzes.length` to the socket count, but
`this.buzzes` is never pruned when a player leaves the room. So if a
player negged and then left, every subsequent neg would push the buzz
count above the remaining socket count, preventing the answer from ever
being revealed until the question ran out of words.

Switch the condition to "every current socket is in buzzes" — this
ignores stale userIds from departed players and correctly handles newly
joined players who haven't buzzed yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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