Problem
The Factory server's ProjectScanner encounters invalid run-index.json files during directory scans. When parsing fails, the server logs console.error with full stack traces that look like server crashes. In reality, these are data quality issues: old files, interrupted runs, or incompatible formats.
Example log output:
Error parsing run data for codeassembly/CODY-115/20260302-122846Z-orchestrated: Error: Invalid run-index.json at /Users/william/.ai/projects/codeassembly/tickets/CODY-115/20260302-122846Z-orchestrated/run-index.json
at parseRunIndexFromRaw (file:///...run-data-parser.js:104:11)
...
Root cause
The parseRunData function in run-core throws plain Error objects with minimal context. The scanner's catch block in scanTicket treats all non-ENOENT errors the same way: console.error + skip the run. There are three distinct failure categories that should be handled differently:
- Corrupt JSON —
run-index.json exists but contains invalid JSON syntax
- Invalid schema — valid JSON but doesn't match v2 or v3 schema (Zod validation details are discarded)
- Missing companion — v3 header exists but
run-log.jsonl is missing
Proposed solution
- Introduce a structured
RunDataParseError class in run-core with category, filePath, and optional zodIssues fields
- Refactor the parser to throw
RunDataParseError instead of plain Error (preserving existing error messages for backward compatibility)
- Update the scanner to catch
RunDataParseError specifically and log console.warn with an informative message and fix suggestion instead of console.error with a stack trace
Acceptance criteria
Must have
- Parse errors produce a
console.warn (not console.error) with a clear, single-line message
- The warning includes the run path and what went wrong
- Invalid runs are still skipped (no crash, no partial data)
- Truly unexpected errors (permissions, I/O failures) remain as
console.error
Should have
- The warning includes a suggestion for how to fix the problem
- Schema validation errors include Zod issue details (available on the error object)
Nice to have
- Auto-fixable errors are fixed automatically
Out of scope
- User sees errors in the UI
Problem
The Factory server's
ProjectScannerencounters invalidrun-index.jsonfiles during directory scans. When parsing fails, the server logsconsole.errorwith full stack traces that look like server crashes. In reality, these are data quality issues: old files, interrupted runs, or incompatible formats.Example log output:
Root cause
The
parseRunDatafunction inrun-corethrows plainErrorobjects with minimal context. The scanner's catch block inscanTickettreats all non-ENOENT errors the same way:console.error+ skip the run. There are three distinct failure categories that should be handled differently:run-index.jsonexists but contains invalid JSON syntaxrun-log.jsonlis missingProposed solution
RunDataParseErrorclass inrun-corewithcategory,filePath, and optionalzodIssuesfieldsRunDataParseErrorinstead of plainError(preserving existing error messages for backward compatibility)RunDataParseErrorspecifically and logconsole.warnwith an informative message and fix suggestion instead ofconsole.errorwith a stack traceAcceptance criteria
Must have
console.warn(notconsole.error) with a clear, single-line messageconsole.errorShould have
Nice to have
Out of scope