mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-12-01 00:27:17 +00:00
5 KiB
5 KiB
Preserve Error Sources Across Failure Paths
Summary
Fix the current error-handling policy violations by keeping structured errors intact until diagnostic/render boundaries. The implementation should preserve source chains through fabro-core, workflow lifecycle hooks, workflow operations, server-managed run failures, and error events that currently expose only error: String.
Key Changes
- Add a source-aware core error variant in
fabro-core, for exampleError::OtherWithSource { message, source: SharedError }, plusError::other_with_source(message, source). Usefabro_util::error::SharedErrorandcollect_chain; addanyhow.workspacetofabro-coreif needed for the constructor. - Update
fabro-core::Error::to_fail_outcome()so source-aware errors produceFailureDetail.causes, while preserving existing retry/category behavior forOther. - Update
fabro-workflow/src/pipeline/execute.rsto convert source-aware core errors intoWorkflowError::engine_with_source(...)instead of the catch-allError::engine(e.to_string()).
Implementation Changes
- Replace lifecycle string flattening with source-aware core errors:
lifecycle/git.rs: emitcheckpoint.failedwitherror = e.to_string()andcauses = collect_causes(&e), then returnCoreError::other_with_source("git checkpoint commit failed for node ...", e).lifecycle/fidelity.rs: wrap artifact context/outcome resolution errors withCoreError::other_with_source(...).lifecycle/artifact.rs: wrap artifact ledger and tempdir failures withCoreError::other_with_source(...).
- Sweep workflow operation/store conversions where internal errors currently use
Error::engine(err.to_string()). UseError::engine_with_source("<specific operation context>", err)for store, serde, IO, and task/join failures in operations such as start, retry, resume, rewind, archive, fork, timeline, create,pipeline/persist.rs,pipeline/initialize.rs, andhandler/manager_loop.rs. Keep intentional user-facing parse/validation string projections unchanged. - Add optional
causes: Vec<String>with#[serde(default, skip_serializing_if = "Vec::is_empty")]to these diagnostic event props and internal event variants:checkpoint.failedpull_request.failedagent.failoveragent.mcp.failed
- Update event conversion and emitters:
- Pull request flow should return
anyhow::Resultor a local typed error instead ofResult<_, String>, use.context(...), and emitcausesfrom the error chain. - Failover events should collect causes from the
fabro_llm::Errorbefore moving it. - MCP failures should preserve causes from structured MCP startup/handshake errors; update
fabro-mcperror wrapping to use context instead of interpolating the source error intoanyhow!.
- Pull request flow should return
- Update server managed-run failure rendering:
- Add helpers that accept
WorkflowErroror(message, causes)rather than onlyString. - Store compact cause-aware text in
managed_run.errorusing existing render helpers. - Reuse the same source-aware
WorkflowErrorfor persistedrun.failedand in-memory managed-run state.
- Add helpers that accept
Public Interfaces
fabro-typesrun event props gain optionalcausesfields for the four diagnostic events above. This is backward-compatible because old events deserialize with empty causes and empty causes are omitted from serialization.docs/internal/events.mdexamples/tables should documentcauses.- No TypeScript client regeneration is required for per-event properties because OpenAPI models
RunEvent.propertiesas arbitrary JSON, but Rust API round-trip tests should be updated.
Test Plan
fabro-core/src/error.rs: assertOtherWithSourcepreservessource()andto_fail_outcome().failure.causes.fabro-workflow/src/pipeline/execute.rstests: a lifecycle/core error with a nested source becomes a workflow error whoseFailureDetail.causescontains the leaf cause.fabro-workflow/src/event/convert.rs: checkpoint, PR failure, failover, and MCP failure events mapcausesintofabro-typesprops.fabro-workflow/src/pipeline/pull_request.rs: PR content/client/deserialization failures retain source-chain causes.fabro-agent/fabro-mcptests: MCP server failure events serialize causes when the underlying startup/handshake error has a chain.fabro-server/src/server/tests.rs: managed-run failure summaries render cause-aware text, and persistedrun.failedstill carries structured causes.- Run
cargo nextest run -p fabro-core,cargo nextest run -p fabro-workflow,cargo nextest run -p fabro-agent,cargo nextest run -p fabro-mcp, and targetedfabro-servertests. Runcargo +nightly-2026-04-14 fmt --check --allafter edits.
Assumptions
- API error responses such as
ApiError::new(..., err.to_string())are not part of this sweep unless they create run diagnostics; the policy explicitly allows curated HTTP JSON messages. - Projection-only summary strings may remain strings, but they must be rendered from preserved causes at the boundary.
- Empty
causesmeans "no structured source available," not "error had no cause."