Stuck on Mute — JavaScript Bug Hunt
Inspired by the most 2020 bug imaginable: you unmute, the app says you're unmuted, everyone still hears silence.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Medium
- Concepts: State, Stale Closures
- Modelled on: Zoom-era calls
- Visible tests: a double toggle returns to the start; a single toggle flips; set overrides, toggles continue from there
- Reward: 50 XP for a complete fix
Briefing
Inspired by the most 2020 bug imaginable: you unmute, the app says you're unmuted, everyone still hears silence. Under the hood, rapid toggles were computed against a stale snapshot of the state instead of the latest value.
muteState.js folds mic events. Each toggle must flip the current state.
Bug report
BUG-UNMUTE · Priority: Critical (all-hands demo) · Reported by: everyone
processEvents(initialMuted, events):
- {type:"toggle"} flips the CURRENT state
- {type:"set", muted} assigns directly
- returns the final state
Observed: two quick toggles from unmuted leave you MUTED — both toggles computed against the initial value.
Logs
[mic] start=false toggle toggle -> true (expected false)The code as shipped
src/av/muteState.js (editable)
// Folds microphone events into the final mute state.
exports.processEvents = function (initialMuted, events) {
var muted = initialMuted;
for (var i = 0; i < events.length; i++) {
var e = events[i];
if (e.type === "toggle") {
muted = !initialMuted;
} else if (e.type === "set") {
muted = e.muted;
}
}
return muted;
};
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.