Expand description
runtime/validate.rs — Kernel graph validation engine
Purpose:
- Validates an
ExpandedGraphagainst the registered primitive catalog before execution, ensuring all structural and semantic constraints are satisfied.
Behavior:
- Returns
Result<ValidatedGraph, GraphValidationError>. - Short-circuits on the first encountered error — callers receive
a single
GraphValidationError, not a collected list.
Owns (invariant → enforcing function → rule ID):
- V.1 No cycles in graph →
topological_sort(CycleDetected) - V.2 Wiring matrix / port legality→
enforce_wiring_matrix(InvalidEdgeKind / MissingInputMetadata / MissingOutputMetadata) - V.3 Required inputs connected →
enforce_required_inputs(MissingRequiredInput) - V.4 Type constraints at edges →
enforce_types(TypeMismatch) - V.5 Action trigger gating →
enforce_action_gating(ActionNotGated) - V.7 Single edge per input port →
enforce_single_edge_per_input(MultipleInboundEdges) - V.8 Primitive catalog existence →
validatemain loop (MissingPrimitive) - (boundary outputs — no doc V-number) →
enforce_boundary_outputs(MissingOutputMetadata) - E.3 ExternalInput rejection →
validatemain loop (ExternalInputNotAllowed)
Note: V.6 (“All nodes pass validation before any action executes”) is a
meta-invariant satisfied by the fact that validate runs to completion
before execute is called — it is not a single check function.
Does not own:
- Graph execution (see
execute.rs) - Primitive registration (see
catalog.rs) - Graph construction or expansion (see
cluster.rs) - E.3 expansion-time enforcement (see
cluster.rs::expand)
Connects to:
execute.rs— producesValidatedGraphconsumed by executiontypes.rs— usesGraphValidationErrorfor reporting violationscatalog.rs— queries primitive metadata for validation
Safety notes:
- Validation is pure and deterministic — no side effects
- E.3 is enforced twice: first during expansion (
cluster.rs), then again here as a defense-in-depth check