Context
After #130, the complete_run MCP tool emits run_failed events with an optional reason field when a run fails. The RunFailedEvent type and Zod schema in run-core already support this field. However, foldEvents in packages/run-core/src/event-folder.ts handles run_failed events but discards the reason field — CanonicalRunStatus has no corresponding property.
Problem
Downstream consumers (Factory visualization, status adapter) cannot access the failure reason because it is lost during event folding. If a run fails with a reason like "quality gates failed", that context is preserved in the JSONL event log but not surfaced through the canonical run status API.
Considerations
CanonicalRunStatus is the single source of truth for run state, defined in packages/run-core/src/types/canonical.ts. Factory re-exports it from packages/factory/src/shared/types/canonical.ts.
- The status adapter (
packages/factory/src/server/adapters/status-adapter.ts) is a re-export from @codeassembly/run-core/parsers and needs no changes.
- The project uses
exactOptionalPropertyTypes, so the field should be reason: string | undefined (always present, nullable) rather than reason?: string (possibly absent), matching the pattern of completedAt.
- The Factory event-folder test file mirrors the run-core test file; both must be updated.
Proposed solution
- Add
reason: string | undefined to CanonicalRunStatus in packages/run-core/src/types/canonical.ts
- Update
foldEvents in packages/run-core/src/event-folder.ts to initialize reason: undefined and extract reason from run_failed events
- Display the failure reason in the Factory StatusBar (
packages/factory/src/client/components/StatusBar.tsx) when present
- Add/update tests in both
run-core and factory packages
Acceptance criteria
Must have
Should have
Nice to have
Context
After #130, the
complete_runMCP tool emitsrun_failedevents with an optionalreasonfield when a run fails. TheRunFailedEventtype and Zod schema inrun-corealready support this field. However,foldEventsinpackages/run-core/src/event-folder.tshandlesrun_failedevents but discards thereasonfield —CanonicalRunStatushas no corresponding property.Problem
Downstream consumers (Factory visualization, status adapter) cannot access the failure reason because it is lost during event folding. If a run fails with a reason like "quality gates failed", that context is preserved in the JSONL event log but not surfaced through the canonical run status API.
Considerations
CanonicalRunStatusis the single source of truth for run state, defined inpackages/run-core/src/types/canonical.ts. Factory re-exports it frompackages/factory/src/shared/types/canonical.ts.packages/factory/src/server/adapters/status-adapter.ts) is a re-export from@codeassembly/run-core/parsersand needs no changes.exactOptionalPropertyTypes, so the field should bereason: string | undefined(always present, nullable) rather thanreason?: string(possibly absent), matching the pattern ofcompletedAt.Proposed solution
reason: string | undefinedtoCanonicalRunStatusinpackages/run-core/src/types/canonical.tsfoldEventsinpackages/run-core/src/event-folder.tsto initializereason: undefinedand extractreasonfromrun_failedeventspackages/factory/src/client/components/StatusBar.tsx) when presentrun-coreandfactorypackagesAcceptance criteria
Must have
CanonicalRunStatusincludes areason: string | undefinedfieldfoldEventsextractsreasonfromrun_failedevents and includes it in the returned statusfoldEventsinitializesreasontoundefinedfor new runs and non-failure completionsShould have
Nice to have