{"record":{"id":"1ff8a98ff866f1e7","repo":"chenglou/pretext","slug":"benchmark-run-reportindex-1-is-missing-key","errorCode":null,"errorMessage":"Benchmark run ${reportIndex + 1} is missing ${key}[${rowIndex}]","messagePattern":"Benchmark run (.+?) is missing (.+?)\\[(.+?)\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/benchmark-check.ts","lineNumber":130,"sourceCode":"  key: typeof BENCHMARK_RESULT_KEYS[number],\n): BenchmarkResult[] | undefined {\n  const firstRows = reports[0]?.[key]\n  if (firstRows === undefined) {\n    for (let reportIndex = 1; reportIndex < reports.length; reportIndex++) {\n      assertSame(reports[reportIndex]![key], undefined, `${key}`)\n    }\n    return undefined\n  }\n  for (let reportIndex = 1; reportIndex < reports.length; reportIndex++) {\n    assertSame(reports[reportIndex]![key]?.length, firstRows.length, `${key}.length`)\n  }\n\n  return firstRows.map((firstRow, rowIndex) => {\n    const values: number[] = []\n    for (let reportIndex = 0; reportIndex < reports.length; reportIndex++) {\n      const row = reports[reportIndex]![key]?.[rowIndex]\n      if (row === undefined) {\n        throw new Error(`Benchmark run ${reportIndex + 1} is missing ${key}[${rowIndex}]`)\n      }\n      assertSame(row.label, firstRow.label, `${key}[${rowIndex}].label`)\n      assertSame(row.desc, firstRow.desc, `${key}[${rowIndex}].desc`)\n      values.push(row.ms)\n    }\n    return {\n      ...firstRow,\n      ms: median(values),\n    }\n  })\n}\n\nfunction medianCorpusResults(reports: BenchmarkReport[]): CorpusBenchmarkResult[] | undefined {\n  const firstRows = reports[0]?.corpusResults\n  if (firstRows === undefined) {\n    for (let reportIndex = 1; reportIndex < reports.length; reportIndex++) {\n      assertSame(reports[reportIndex]!.corpusResults, undefined, 'corpusResults')\n    }","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/benchmark-check.ts#L112-L148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Dump the offending reports[reportIndex] JSON and inspect results[key] for holes/nulls.","Regenerate the benchmark report from a fresh page run rather than reusing a stale/edited JSON.","If this recurs, audit the page code that populates the results array for conditional `undefined` pushes.","Run with --runs=1 to isolate which run produces the malformed array."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Reject sparse arrays before mediating.\nfunction isDenseArray(arr: unknown[]): boolean {\n  return arr.every(item => item !== undefined)\n}","typeGuard":null,"tryCatchPattern":"// Treat malformed rows as a skip with a warning rather than aborting the median.\nconst row = reports[reportIndex]![key]?.[rowIndex]\nif (row === undefined) {\n  console.warn(`Skipping missing ${key}[${rowIndex}] in run ${reportIndex + 1}`)\n  continue\n}","preventionTips":["Never push undefined into results arrays on the page side; skip the push entirely.","Regenerate benchmark JSON from fresh page runs rather than editing by hand.","Add a page-side assertion that each result row is a fully-populated object."],"tags":["benchmark-check","defensive-guard","data-integrity","aggregation"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}