The Log That Wore Out the Car — JavaScript Bug Hunt
Modelled on Tesla's 2021 media-control-unit recall. After an NHTSA investigation, Tesla recalled roughly 135,000 Model S and Model X vehicles whose media…
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Resource Limits, Logging
- Modelled on: Tesla · 2021
- Visible tests: logged lines reach flash in order after a flush; lines are written in batches
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High (hardware wear))
- Ticket: BUG-MCU-EMMC
- Reported by: vehicle reliability
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- lines are written in batches — two full batches of 50: expected 2 but got 120
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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- 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
Modelled on Tesla's 2021 media-control-unit recall. After an NHTSA investigation, Tesla recalled roughly 135,000 Model S and Model X vehicles whose media control unit used an 8 GB eMMC flash chip that could wear out: every flash chip survives only a limited number of program/erase cycles, and once this one was exhausted the touchscreen could fail, taking functions such as the rear-view camera display and defogging controls with it. Reporting on the failures widely pointed at the steady stream of log data being written to the chip.
logger.js is a reconstruction of such a logger: it writes every log line to flash as its own write.
Fix the logger to batch writes and cap what it keeps on flash.
Bug report
BUG-MCU-EMMC · Priority: High (hardware wear) · Reported by: vehicle reliability
createLogger(flash) returns { log(line), flush() }:
- log() appends to an in-memory buffer; nothing reaches flash until the buffer holds config.BATCH_LINES lines, which are then written with ONE flash.write(lines) call and the buffer emptied
- flush() writes whatever is buffered with one flash.write call; with an empty buffer it writes nothing
- after every write, if flash.lines holds more than config.RETAIN_LINES lines, the oldest are dropped with flash.dropOldest(count) so exactly RETAIN_LINES remain
- lines reach flash in the order they were logged
Observed: flash.writes equals the number of log lines; the part's write budget is spent in a few years of normal driving.
Logs
[mcu] emmc: life_time_est_typ_b=0x0B (exceeded)
[mcu] emmc: program/erase cycles consumed by /var/log: 97%
[mcu] display: boot failed, rear camera unavailableThe code as shipped
src/mcu/logger.js (editable)
var config = require("./config");
exports.createLogger = function (flash) {
return {
log: function (line) {
flash.write([line]);
},
flush: function () {}
};
};
Read-only context: src/mcu/config.js, src/mcu/flash.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.