chenglou/pretext · error · Error

Benchmark run ${reportIndex + 1} is missing ${key}[${rowInde

Error message

Benchmark run ${reportIndex + 1} is missing ${key}[${rowIndex}]

What it means

Thrown inside medianBenchmarkResults() when accessing reports[reportIndex][key][rowIndex] returns undefined despite the prior length check passing. It is a defensive guard: the code already asserted all runs share the same array length for the given key, so an undefined element implies a sparse/malformed array or a type lie. In normal operation this should be unreachable; seeing it means the report JSON is structurally corrupt.

Source

Thrown at scripts/benchmark-check.ts:130

  key: typeof BENCHMARK_RESULT_KEYS[number],
): BenchmarkResult[] | undefined {
  const firstRows = reports[0]?.[key]
  if (firstRows === undefined) {
    for (let reportIndex = 1; reportIndex < reports.length; reportIndex++) {
      assertSame(reports[reportIndex]![key], undefined, `${key}`)
    }
    return undefined
  }
  for (let reportIndex = 1; reportIndex < reports.length; reportIndex++) {
    assertSame(reports[reportIndex]![key]?.length, firstRows.length, `${key}.length`)
  }

  return firstRows.map((firstRow, rowIndex) => {
    const values: number[] = []
    for (let reportIndex = 0; reportIndex < reports.length; reportIndex++) {
      const row = reports[reportIndex]![key]?.[rowIndex]
      if (row === undefined) {
        throw new Error(`Benchmark run ${reportIndex + 1} is missing ${key}[${rowIndex}]`)
      }
      assertSame(row.label, firstRow.label, `${key}[${rowIndex}].label`)
      assertSame(row.desc, firstRow.desc, `${key}[${rowIndex}].desc`)
      values.push(row.ms)
    }
    return {
      ...firstRow,
      ms: median(values),
    }
  })
}

function medianCorpusResults(reports: BenchmarkReport[]): CorpusBenchmarkResult[] | undefined {
  const firstRows = reports[0]?.corpusResults
  if (firstRows === undefined) {
    for (let reportIndex = 1; reportIndex < reports.length; reportIndex++) {
      assertSame(reports[reportIndex]!.corpusResults, undefined, 'corpusResults')
    }

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Dump the offending reports[reportIndex] JSON and inspect results[key] for holes/nulls.
  2. Regenerate the benchmark report from a fresh page run rather than reusing a stale/edited JSON.
  3. If this recurs, audit the page code that populates the results array for conditional `undefined` pushes.
  4. Run with --runs=1 to isolate which run produces the malformed array.
Defensive patterns

Strategy: try-catch

Validate before calling

// Reject sparse arrays before mediating.
function isDenseArray(arr: unknown[]): boolean {
  return arr.every(item => item !== undefined)
}

Try / catch

// Treat malformed rows as a skip with a warning rather than aborting the median.
const row = reports[reportIndex]![key]?.[rowIndex]
if (row === undefined) {
  console.warn(`Skipping missing ${key}[${rowIndex}] in run ${reportIndex + 1}`)
  continue
}

Prevention

When it happens

Trigger: A benchmark report's results array has the right length but contains a hole (sparse array) or the JSON was hand-edited to contain null entries that deserialize as undefined. Because the length check at line 121-123 passed, rowIndex is in range, so the element itself must be absent.

Common situations: Extremely rare in practice; would indicate a corrupted posted/hash report, a serialization bug in the page, or a malformed JSON file passed as a precomputed report. Not something end users typically hit.

Related errors


AI-assisted analysis of chenglou/pretext@ac49b09b7d (2026-08-12). Data as JSON: /api/errors/1ff8a98ff866f1e7. Report an issue: GitHub.