{"record":{"id":"c85ce0e2f8d9f13d","repo":"Egonex-AI/Understand-Anything","slug":"batch-artifact-does-not-match-the-required-shape","errorCode":null,"errorMessage":"Batch artifact does not match the required shape","messagePattern":"Batch artifact does not match the required shape","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/large-repo-benchmark.mjs","lineNumber":771,"sourceCode":"function validateBatchArtifact(batches) {\n  if (\n    !isRecord(batches) ||\n    batches.schemaVersion !== 1 ||\n    typeof batches.algorithm !== 'string' ||\n    batches.algorithm.length === 0 ||\n    !Array.isArray(batches.batches) ||\n    !isNonNegativeInteger(batches.totalBatches) ||\n    batches.totalBatches !== batches.batches.length ||\n    batches.batches.some(\n      (batch) =>\n        !isRecord(batch) ||\n        !isNonNegativeInteger(batch.batchIndex) ||\n        !Array.isArray(batch.files) ||\n        !isRecord(batch.batchImportData) ||\n        !isRecord(batch.neighborMap),\n    )\n  ) {\n    throw new Error('Batch artifact does not match the required shape');\n  }\n}\n\nfunction markArtifactFailure(stage, stageName, error, redactionRoots) {\n  const rawMessage = error instanceof Error ? error.message : String(error);\n  const safeMessage = sanitizeBounded(\n    `${stageName} stage produced an invalid artifact: ${rawMessage}`,\n    redactionRoots,\n  );\n  stage.status = 'failed';\n  stage.stderr = safeMessage.text;\n  stage.stderrTruncated ||= safeMessage.truncated;\n}\n\nfunction fileSizeOrZero(path) {\n  try {\n    return statSync(path).size;\n  } catch {","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/scripts/lib/large-repo-benchmark.mjs#L753-L789","documentation":"Thrown by validateBatchArtifact when batches.json (the output of the batching worker) does not satisfy the contract the benchmark needs to size agent input. It enforces schemaVersion===1, a non-empty algorithm string, a batches array whose length equals totalBatches, and a per-batch shape of {batchIndex, files[], batchImportData, neighborMap}. This is a hard gate because the agent-input byte estimate (JSON.stringify of files+batchImportData+neighborMap) is computed unconditionally right after this check.","triggerScenarios":"The benchmark reads artifactRoot/batches.json after batchStage.status === 'ok' and calls validateBatchArtifact(batches). Throws when schemaVersion !== 1, algorithm is missing/empty/non-string, batches is not an array, totalBatches !== batches.length, or any batch is missing batchIndex (non-negative int), files (array), batchImportData (record), or neighborMap (record).","commonSituations":"A custom or out-of-date batching implementation that omits schemaVersion or the algorithm tag. A partial write where totalBatches was updated but batches truncated (interrupted write / OOM kill mid-stream). A neighborMap that came back null from a worker that skipped import enrichment. Editing batches.json by hand and forgetting the totalBatches counter.","solutions":["Open artifactRoot/batches.json and confirm schemaVersion===1, a non-empty algorithm string, and totalBatches === batches.length.","Re-run the batching stage on its prior inputs (scan-result-with-imports.json) and inspect stderr; a crash there usually leaves totalBatches unset.","If you swapped in a different batching algorithm, ensure it still emits schemaVersion:1 and the four required per-batch fields.","Delete batches.json and the artifactRoot intermediate so the benchmark regenerates it from the validated scan+import artifacts.","Verify the import stage (error 20) passed — batching depends on batchImportData/neighborMap produced upstream, and a skipped import stage yields empty maps that some custom batchers may omit."],"exampleFix":"// before: batcher emits arrays without the envelope\n{ \"batches\": [ { \"files\": [\"a.ts\"] } ] }\n\n// after: full validated shape\n{\n  \"schemaVersion\": 1,\n  \"algorithm\": \"greedy-import-locality\",\n  \"totalBatches\": 1,\n  \"batches\": [\n    { \"batchIndex\": 0, \"files\": [\"a.ts\"], \"batchImportData\": {}, \"neighborMap\": {} }\n  ]\n}","handlingStrategy":"validation","validationCode":"function isValidBatchArtifact(v) {\n  if (typeof v !== 'object' || v === null) return false;\n  if (v.schemaVersion !== 1) return false;\n  if (typeof v.algorithm !== 'string' || v.algorithm.length === 0) return false;\n  if (!Array.isArray(v.batches)) return false;\n  if (!Number.isInteger(v.totalBatches) || v.totalBatches !== v.batches.length) return false;\n  for (const b of v.batches) {\n    if (typeof b !== 'object' || b === null) return false;\n    if (!Number.isInteger(b.batchIndex) || b.batchIndex < 0) return false;\n    if (!Array.isArray(b.files)) return false;\n    if (typeof b.batchImportData !== 'object' || b.batchImportData === null) return false;\n    if (typeof b.neighborMap !== 'object' || b.neighborMap === null) return false;\n  }\n  return true;\n}","typeGuard":"function isBatchArtifact(v) {\n  if (typeof v !== 'object' || v === null) return false;\n  const o = v;\n  return o.schemaVersion === 1\n    && typeof o.algorithm === 'string' && o.algorithm.length > 0\n    && Array.isArray(o.batches)\n    && Number.isInteger(o.totalBatches) && o.totalBatches === o.batches.length\n    && o.batches.every((b) =>\n        b !== null && typeof b === 'object'\n        && Number.isInteger(b.batchIndex) && b.batchIndex >= 0\n        && Array.isArray(b.files)\n        && typeof b.batchImportData === 'object' && b.batchImportData !== null\n        && typeof b.neighborMap === 'object' && b.neighborMap !== null);\n}","tryCatchPattern":"try {\n  validateBatchArtifact(batches);\n} catch (e) {\n  console.error('batches.json shape invalid:', e.message, batchesPath);\n  throw e;\n}","preventionTips":["Custom batchers must emit schemaVersion:1, a non-empty algorithm, totalBatches === batches.length, and all four per-batch fields.","Never edit batches.json by hand without updating totalBatches to match.","Re-run the batcher rather than patching its output."],"tags":["benchmark","validation","batching","schema","json-artifact"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}