Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(flows): remove unused engine compatibility validation

Steven Enamakel43a125c66d28
diff --git a/src/openhuman/flows/ops.rs b/src/openhuman/flows/ops.rs
index 5d8e044e23..012ea774a0 100644
--- a/src/openhuman/flows/ops.rs
+++ b/src/openhuman/flows/ops.rs
@@ -62,11 +62,6 @@ const FLOW_RUN_TIMEOUT_SECS: u64 = 600;
/// this is a dedicated flows-side TTL, not a reuse of the approval store's.
const FLOW_PARKED_TTL_SECS: i64 = 600;
-/// Stable host-validation code for a topology that the currently vendored
-/// TinyFlows/TinyAgents barrier-relief implementation cannot execute safely.
-const UNSUPPORTED_NESTED_CONDITIONAL_FAN_IN: &str = "unsupported_nested_conditional_fan_in";
-const UNSUPPORTED_MAIN_PORT_CONDITIONAL_FAN_IN: &str = "unsupported_main_port_conditional_fan_in";
-
/// T-M1 fail-closed refusal: the graph hash pinned when this run parked no
/// longer matches the flow's current graph (`save_workflow` rewrote it while
/// the approval sat pending). Distinct wording from every other
@@ -133,341 +128,6 @@ pub(crate) fn validate_and_migrate_graph(graph_json: Value) -> Result<WorkflowGr
Ok(graph)
}
-/// Detects fan-in predecessors controlled by more than one branching decision.
-///
-/// TinyFlows lowers every fan-in edge as a waiting edge and registers a
-/// barrier relief for conditional predecessors. The current lowering chooses
-/// only the first upstream brancher, while TinyAgents cannot prove reachability
-/// through a second brancher. Depending on node declaration order, that can
-/// either relieve the barrier before the real predecessor runs (silently
-/// dropping its data) or leave the fan-in unfired. Fail closed until the
-/// vendored engine models nested decisions directly.
-///
-/// This intentionally mirrors TinyFlows' topology classification rather than
-/// limiting the check to `merge` nodes: any node with multiple incoming edges
-/// is lowered as a fan-in barrier. A predecessor reachable from the trigger by
-/// `main`-only edges is unconditional and needs no relief, so it is safe.
-pub(crate) fn engine_compatibility_errors(
- graph: &WorkflowGraph,
-) -> Vec<crate::openhuman::flows::FlowValidationError> {
- engine_compatibility_errors_with_max_depth(graph, max_sub_workflow_depth(graph))
-}
-
-/// Same walk as [`engine_compatibility_errors`], but with the inline-nesting
-/// budget passed in rather than recomputed from `graph`'s own trigger.
-///
-/// [`referenced_workflow_compatibility_errors`] needs this: a saved child
-/// reached partway through the root's referenced-workflow chain must still be
-/// checked to the *remaining* depth the root's own `max_sub_workflow_depth`
-/// allows, not to the child's own (possibly lower/default) declared cap —
-/// the engine's runtime depth counter is one budget shared across the whole
-/// inline-plus-referenced call chain, so a fan-in the child's own cap would
-/// not reach can still be reached from the root.
-pub(crate) fn engine_compatibility_errors_with_max_depth(
- graph: &WorkflowGraph,
- max_depth: u64,
-) -> Vec<crate::openhuman::flows::FlowValidationError> {
- let mut errors = Vec::new();
- collect_engine_compatibility_errors(graph, 0, max_depth, &mut errors);
- errors
-}
-
-/// The nesting cap this graph declares on its trigger, or the engine default.
-///
-/// The static walk below has to descend as deep as the run actually will, or a
-/// graph that legitimately nests past the default would stop being checked
-/// exactly where it starts being interesting.
-pub(crate) fn max_sub_workflow_depth(graph: &WorkflowGraph) -> u64 {
- graph
- .trigger()
- .and_then(|t| t.config.get("max_sub_workflow_depth"))
- .and_then(serde_json::Value::as_u64)
- .filter(|n| *n > 0)
- .unwrap_or(tinyflows::engine::MAX_SUB_WORKFLOW_DEPTH)
-}
-
-fn collect_engine_compatibility_errors(
- graph: &WorkflowGraph,
- depth: u64,
- max_depth: u64,
- errors: &mut Vec<crate::openhuman::flows::FlowValidationError>,
-) {
- errors.extend(graph_engine_compatibility_errors(graph));
- if depth >= max_depth {
- return;
- }
-
- for node in &graph.nodes {
- if node.kind != NodeKind::SubWorkflow {
- continue;
- }
- let Some(inline) = node.config.get("workflow") else {
- continue;
- };
- let Ok(child) = serde_json::from_value::<WorkflowGraph>(inline.clone()) else {
- // TinyFlows reports malformed inline children as capability errors;
- // this gate is specifically for otherwise-deserializable unsafe
- // topologies.
- continue;
- };
- let first_child_error = errors.len();
- collect_engine_compatibility_errors(&child, depth + 1, max_depth, errors);
- for error in &mut errors[first_child_error..] {
- error.message = format!("Inline sub_workflow node '{}': {}", node.id, error.message);
- }
- }
-}
-
-fn graph_engine_compatibility_errors(
- graph: &WorkflowGraph,
-) -> Vec<crate::openhuman::flows::FlowValidationError> {
- let Some(trigger) = graph.trigger() else {
- return Vec::new();
- };
- let mut errors = Vec::new();
-
- // The edges that close a cycle, from the engine's own classifier rather
- // than a second implementation here — this gate mirrors TinyFlows' fan-in
- // lowering, so the two must agree on which edges count. A back-edge is a
- // loop head's re-entry, not a predecessor it barriers on, and counting it
- // would report every legal loop as an unrelieved fan-in.
- let loop_edges = tinyflows::engine::back_edges(graph);
-
- for fan_in in &graph.nodes {
- let incoming: Vec<&str> = graph
- .edges
- .iter()
- .filter(|edge| edge.to_node == fan_in.id)
- .filter(|edge| !loop_edges.contains(&(edge.from_node.clone(), edge.to_node.clone())))
- .map(|edge| edge.from_node.as_str())
- .collect();
- if incoming.len() <= 1 {
- continue;
- }
-
- for predecessor in incoming {
- // Reaching a router itself unconditionally does not make the edge
- // it selects into the fan-in unconditional. Let router
- // predecessors reach the port-aware analysis below.
- if !is_branching_node(graph, predecessor)
- && reaches_on_main_edges(graph, &trigger.id, predecessor, &fan_in.id)
- {
- continue;
- }
-
- let mut controlling_branchers = 0usize;
- let mut controlled_via_main_port = false;
- for candidate in &graph.nodes {
- let is_router = matches!(candidate.kind, NodeKind::Condition | NodeKind::Switch);
- let ports: HashSet<&str> = graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == candidate.id)
- .map(|edge| edge.from_port.as_str())
- .collect();
- if ports.len() < 2 && !is_router {
- continue;
- }
- // When the router is itself the incoming predecessor, its
- // branch edge must be tested against the fan-in (asking whether
- // that edge reaches the router again can never succeed).
- let controlled_target = if candidate.id == predecessor {
- fan_in.id.as_str()
- } else {
- predecessor
- };
- let reaches_from_port = |port: &str| {
- reaches_via_port(graph, &candidate.id, port, controlled_target, &fan_in.id)
- };
- let any_port_reaches = ports.iter().any(|port| reaches_from_port(port));
- // A router with one wired output still has unwired runtime
- // choices that emit no successor, so that sole edge cannot
- // prove unconditional reachability. Router reconvergence is
- // only deterministic when every runtime choice is wired:
- // both condition outcomes, or a switch fallback. Generic
- // multi-port nodes retain their existing all-port behavior.
- let routing_choices_are_exhaustive = match candidate.kind {
- NodeKind::Condition => ports.contains("true") && ports.contains("false"),
- NodeKind::Switch => ports.contains("default"),
- _ => true,
- };
- let can_prove_all_routing_choices = if is_router {
- routing_choices_are_exhaustive
- } else {
- ports.len() >= 2
- };
- let every_port_deterministically_reaches = can_prove_all_routing_choices
- && ports.iter().all(|port| {
- reaches_deterministically_via_port(
- graph,
- &candidate.id,
- port,
- controlled_target,
- &fan_in.id,
- )
- });
- // A multi-port node only controls this predecessor when the
- // predecessor is reachable from it but not guaranteed by a
- // deterministic path on every routing choice. This matches
- // TinyAgents' relief proof, which stops at another router.
- if any_port_reaches && !every_port_deterministically_reaches {
- controlling_branchers += 1;
- controlled_via_main_port |= ports.contains("main") && reaches_from_port("main");
- }
- }
-
- let (code, routing_kind) = if controlled_via_main_port {
- (
- UNSUPPORTED_MAIN_PORT_CONDITIONAL_FAN_IN,
- "a conditional branch labelled 'main'",
- )
- } else if controlling_branchers >= 2 {
- (
- UNSUPPORTED_NESTED_CONDITIONAL_FAN_IN,
- "nested conditional routing",
- )
- } else {
- continue;
- };
- errors.push(crate::openhuman::flows::FlowValidationError {
- code: code.to_string(),
- message: format!(
- "Fan-in node '{}' has predecessor '{}' behind {routing_kind}; \
- this topology is temporarily unsupported because it can silently lose \
- merged data. Flatten the conditional branch or join it before this fan-in.",
- fan_in.id, predecessor
- ),
- node_id: Some(fan_in.id.clone()),
- field: None,
- });
- }
- }
-
- errors
-}
-
-fn ensure_engine_compatible(graph: &WorkflowGraph) -> Result<(), String> {
- match engine_compatibility_errors(graph).into_iter().next() {
- Some(error) => Err(format!("{}: {}", error.code, error.message)),
- None => Ok(()),
- }
-}
-
-/// Host-aware compatibility check, including saved descendants that graph-only
-/// validation cannot inspect. Authoring boundaries use it before persistence;
-/// execution boundaries use it before compiling a root run/resume or returning
-/// a resolver graph, so an unsafe descendant cannot run after earlier effects.
-fn ensure_config_aware_engine_compatible(
- config: &Config,
- graph: &WorkflowGraph,
-) -> Result<(), String> {
- match config_aware_engine_compatibility_errors(config, graph)
- .into_iter()
- .next()
- {
- Some(error) => Err(error),
- None => Ok(()),
- }
-}
-
-fn reaches_on_main_edges(graph: &WorkflowGraph, from: &str, to: &str, stop: &str) -> bool {
- if from == to {
- return true;
- }
- let mut stack: Vec<&str> = if is_branching_node(graph, from) {
- Vec::new()
- } else {
- graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == from && edge.from_port == "main")
- .map(|edge| edge.to_node.as_str())
- .collect()
- };
- let mut seen = HashSet::new();
- while let Some(node) = stack.pop() {
- if node == to {
- return true;
- }
- if node == stop || !seen.insert(node) {
- continue;
- }
- // Port labels are arbitrary. A node with multiple distinct output
- // ports is runtime-selective even when one label happens to be `main`,
- // so nothing beyond it is unconditionally reachable.
- if is_branching_node(graph, node) {
- continue;
- }
- stack.extend(
- graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == node && edge.from_port == "main")
- .map(|edge| edge.to_node.as_str()),
- );
- }
- false
-}
-
-fn is_branching_node(graph: &WorkflowGraph, node_id: &str) -> bool {
- graph.nodes.iter().any(|node| {
- node.id == node_id && matches!(node.kind, NodeKind::Condition | NodeKind::Switch)
- }) || graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == node_id)
- .map(|edge| edge.from_port.as_str())
- .collect::<HashSet<_>>()
- .len()
- >= 2
-}
-
-fn reaches_via_port(
- graph: &WorkflowGraph,
- brancher: &str,
- port: &str,
- target: &str,
- stop: &str,
-) -> bool {
- let mut stack: Vec<&str> = graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == brancher && edge.from_port == port)
- .map(|edge| edge.to_node.as_str())
- .collect();
- let mut seen = HashSet::new();
- while let Some(node) = stack.pop() {
- if node == target {
- return true;
- }
- if node == stop || !seen.insert(node) {
- continue;
- }
- stack.extend(
- graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == node)
- .map(|edge| edge.to_node.as_str()),
- );
- }
- false
-}
-
-fn reaches_deterministically_via_port(
- graph: &WorkflowGraph,
- brancher: &str,
- port: &str,
- target: &str,
- stop: &str,
-) -> bool {
- graph
- .edges
- .iter()
- .filter(|edge| edge.from_node == brancher && edge.from_port == port)
- .any(|edge| reaches_on_main_edges(graph, &edge.to_node, target, stop))
-}
-
/// Runs a raw graph JSON value through migration + deserialization **without**
/// the structural `validate` step. Splits the two so a caller that wants
/// *every* structural error (via `tinyflows::validate::validate_all`) can run