{"record":{"id":"afb4cf985c0f49fb","repo":"Egonex-AI/Understand-Anything","slug":"benchmark-stage-failed-stage-name","errorCode":null,"errorMessage":"Benchmark stage failed: ${stage.name}","messagePattern":"Benchmark stage failed: (.+?)","errorType":"exception","errorClass":"BenchmarkStageError","httpStatus":null,"severity":"error","filePath":"scripts/lib/large-repo-benchmark.mjs","lineNumber":1755,"sourceCode":"    stageResults.push(scanStage);\n    report.stages.scan = summarizeStage(\n      scanStage,\n      fileSizeOrZero(scanPath),\n    );\n    let scan = null;\n    if (scanStage.status === 'ok') {\n      try {\n        scan = readJson(scanPath);\n        validateScanArtifact(scan);\n      } catch (error) {\n        markArtifactFailure(scanStage, 'scan', error, redactionRoots);\n        report.stages.scan = summarizeStage(\n          scanStage,\n          fileSizeOrZero(scanPath),\n        );\n      }\n    }\n    if (scanStage.status === 'failed') throw new BenchmarkStageError(scanStage);\n    report.scale = subjectScale(options.repoRoot, scan);\n    report.stages.scan = summarizeStage(scanStage, fileSizeOrZero(scanPath), {\n      files: scan.totalFiles,\n      lines: report.scale.lines,\n      bytes: report.scale.bytes,\n      filteredByUserIgnore: scan.filteredByIgnore ?? 0,\n    });\n\n    const importInputPath = join(artifactRoot, 'import-input.json');\n    const importOutputPath = join(artifactRoot, 'import-map.json');\n    writeJson(importInputPath, {\n      projectRoot: options.repoRoot,\n      files: scan.files,\n    });\n    onProgress('imports');\n    const importStage = await runStage(\n      'imports',\n      IMPORT_SCRIPT,","sourceCodeStart":1737,"sourceCodeEnd":1773,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/scripts/lib/large-repo-benchmark.mjs#L1737-L1773","documentation":"BenchmarkStageError thrown for the scan stage. After the scan worker runs, the harness reads scanPath (scan.json), calls validateScanArtifact, and on a thrown error marks the stage failed via markArtifactFailure (redacting the message) and summarizes it. If scanStage.status is still 'failed' after that, this BenchmarkStageError is thrown, halting the pipeline before the import stage which depends on scan output.","triggerScenarios":"The scan worker exited non-zero or scan.json is missing/invalid JSON, OR validateScanArtifact threw (e.g. totalFiles missing, schema mismatch), causing markArtifactFailure to set scanStage.status='failed'. The subsequent `if (scanStage.status === 'failed') throw new BenchmarkStageError(scanStage)` then aborts.","commonSituations":"repoRoot points at a path with no scannable files, or to a path the worker cannot read (permission denied). An outdated scan-project.mjs that omits a required field (totalFiles, filteredByIgnore). The worker process was killed (OOM on a huge repo). repoRoot is a file rather than a directory.","solutions":["Read report.stages.scan.stderr — it carries the sanitized original error from markArtifactFailure.","Run the scan worker standalone against repoRoot and inspect stderr: node understand-anything-plugin/skills/understand/scan-project.mjs <input.json> <out.json>.","Confirm repoRoot exists, is a directory, and is readable by the benchmark process.","If the worker is an older version, rebuild/re-sync the plugin so its scan-project.mjs emits the current required schema.","For very large repos, raise the worker memory budget so scan-project.mjs is not OOM-killed mid-stream."],"exampleFix":"// before — repoRoot unreadable or wrong type\nrunBenchmark({ repoRoot: './some-file', outputPath: './b.json' })\n\n// after — verify it is a readable directory first\nimport { statSync } from 'node:fs';\nif (!statSync(opts.repoRoot).isDirectory()) throw new Error('repoRoot must be a directory');\nrunBenchmark({ repoRoot: opts.repoRoot, outputPath: './b.json' })","handlingStrategy":"try-catch","validationCode":"import { statSync } from 'node:fs';\nfunction ensureScanInputs(repoRoot) {\n  if (!repoRoot) throw new Error('repoRoot required');\n  const st = statSync(repoRoot);\n  if (!st.isDirectory()) throw new Error('repoRoot must be a directory');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runBenchmark(options);\n} catch (e) {\n  if (e instanceof BenchmarkStageError && e.stage.name === 'scan') {\n    console.error('scan stage failed:', e.stage.stderr);\n    // re-run scan-project.mjs standalone for a fuller error\n  } else throw e;\n}","preventionTips":["Verify repoRoot is a readable directory before running the benchmark.","Keep scan-project.mjs in sync with the benchmark harness so its output schema matches validateScanArtifact.","On large repos, give the scan worker enough memory to avoid OOM kills."],"tags":["benchmark","pipeline","scan","stage-failure","schema"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}