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

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 unavailable

The 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 edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.