fabro/lib/crates/fabro-core/src/handler.rs
Bryan Helmkamp 49fbc78028 Unify Outcome types between fabro-core and fabro-workflows
Make fabro-core's Outcome generic over a usage/metadata type parameter
(OutcomeMeta trait), allowing fabro-workflows to use core's types
directly via a type alias instead of maintaining duplicate Outcome,
StageStatus, and FailureDetail types with bidirectional conversions.

Key changes:
- Add FailureCategory enum to fabro-core (moved from fabro-workflows'
  FailureClass), with Display/FromStr/is_signature_tracked
- Add OutcomeMeta supertrait + blanket impl for the generic parameter
- Make Outcome<M>, NodeResult<M>, RunState<M>, NodeDecision<M> generic
  with default type parameter M=()
- Add Graph::Meta associated type
- Update FailureDetail with serde renames (category→"failure_class",
  signature→"failure_signature") for checkpoint backward compat
- Replace fabro-workflows' Outcome with type alias to
  fabro_core::Outcome<Option<StageUsage>>
- Add OutcomeExt extension trait for wf-specific factory methods
  (fail_classify, fail_deterministic, retry_classify, simulated, etc.)
- Delete core_adapter/outcome.rs (~170 lines of conversion functions)
- Replace FailureClass with FailureCategory throughout fabro-workflows
- Fix timeout handler to use TransientInfra category, panic handler to
  use Deterministic category

Net: -144 lines, zero-cost type unification with no runtime conversions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:47:05 -04:00

29 lines
677 B
Rust

use async_trait::async_trait;
use crate::context::Context;
use crate::error::Result;
use crate::graph::Graph;
use crate::outcome::Outcome;
use crate::retry::RetryPolicy;
#[async_trait]
pub trait NodeHandler<G: Graph>: Send + Sync {
async fn execute(
&self,
node: &G::Node,
context: &Context,
graph: &G,
) -> Result<Outcome<G::Meta>>;
fn retry_policy(&self, _node: &G::Node, _graph: &G) -> RetryPolicy {
RetryPolicy::none()
}
fn on_retries_exhausted(
&self,
_node: &G::Node,
_last_outcome: Outcome<G::Meta>,
) -> Outcome<G::Meta> {
Outcome::fail("max retries exceeded")
}
}