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
Incident
- Severity: SEV-1 (priority: Critical (all-hands demo))
- Ticket: BUG-UNMUTE
- Reported by: everyone
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- a double toggle returns to the start — expected false but got true
- set overrides, toggles continue from there — expected false but got true
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
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 start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.