The Vanishing Search Results — JavaScript Bug Hunt
The search box on Atlas Docs shows results for a query the user typed three keystrokes ago.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Easy
- Modelled on: Typeahead search UIs
- Visible tests: in-order responses render normally; stale response must not overwrite a newer one; the newest request always applies
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-1188
- Reported by: design QA
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- stale response must not overwrite a newer one — stale response overwrote the newer results: expected "match-1:react" but got "match-1:re"
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
The search box on Atlas Docs shows results for a query the user typed three keystrokes ago. Fast responses for old queries are overwriting slow responses for new ones.
The UI pipeline and the mock search service are locked. The race-guard logic in requestTracker.js is where the bug lives.
Bug report
BUG-1188 · Priority: High · Reported by: design QA
Type "re", then quickly "react". The list flashes the correct results, then snaps BACK to the results for "re".
The tracker is supposed to give every request an increasing id, and only let the response through if it belongs to the LATEST request.
Logs
[search] issued id=1 q="re"
[search] issued id=2 q="react"
[search] applied id=2 q="react" <- correct
[search] applied id=1 q="re" <- stale overwrite!The code as shipped
src/search/requestTracker.js (editable)
// Guards against out-of-order async responses.
var latestId = 0;
exports.nextRequestId = function () {
latestId = latestId + 1;
return latestId;
};
// Should return true only for the response belonging to the newest request.
exports.shouldApply = function (responseId) {
return responseId <= latestId;
};
exports.reset = function () {
latestId = 0;
};
Read-only context: src/search/searchService.js, src/search/ui.js.
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.