Skip to content

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

refactor(flows): restructure inference readiness evaluation

Steven Enamakel8a46b896c17f
diff --git a/crates/openhuman-core/src/flows/ops/inference_readiness.rs b/crates/openhuman-core/src/flows/ops/inference_readiness.rs
index 0a958949fa..aea226515c 100644
--- a/crates/openhuman-core/src/flows/ops/inference_readiness.rs
+++ b/crates/openhuman-core/src/flows/ops/inference_readiness.rs
@@ -1,5 +1,11 @@
use super::*;
+pub(super) struct InferenceReadinessEvaluation {
+ pub(super) status: &'static str,
+ pub(super) message: Option<String>,
+ pub(super) node_id: Option<String>,
+}
+
/// Resolve the effective inference workload for an agent node. This remains
/// beside the graph adapter because it depends on TinyFlows node configuration.
pub(super) fn agent_node_role(config: &Config, node: &tinyflows::model::Node) -> &'static str {
@@ -48,13 +54,16 @@ pub(super) fn agent_node_role(config: &Config, node: &tinyflows::model::Node) ->
}
fn format_evaluation(
- evaluation: crate::inference::readiness::ReadinessEvaluation,
+ evaluation: &crate::inference::readiness::ReadinessEvaluation,
) -> Option<String> {
if evaluation.status == "ready" {
return None;
}
if let [failure] = evaluation.failures.as_slice() {
- if let [node_id] = failure.node_ids.as_slice() {
+ if let [_node_id] = failure.node_ids.as_slice() {
+ if failure.session_wide {
+ return Some(failure.message.clone());
+ }
return Some(if evaluation.status == "provider_not_configured" {
format!(
"This flow's agent step needs a working AI provider, but the provider \
@@ -80,12 +89,7 @@ fn format_evaluation(
.map(|id| format!("'{id}'"))
.collect::<Vec<_>>()
.join(", ");
- if evaluation.status == "provider_not_configured"
- && failure
- .message
- .to_ascii_lowercase()
- .contains("api key not configured")
- {
+ if failure.status == "provider_not_configured" {
format!(
"Node(s) {nodes} (role `{}`): the provider returned: '{}'. Configure \
your provider API key in OpenHuman Settings > Providers, then try again.",
@@ -111,14 +115,24 @@ pub(super) async fn evaluate_inference_readiness(
ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
graph: &WorkflowGraph,
-) -> Option<crate::inference::readiness::ReadinessEvaluation> {
+) -> Option<InferenceReadinessEvaluation> {
let roles: Vec<_> = graph
.nodes
.iter()
.filter(|node| node.kind == NodeKind::Agent)
.map(|node| (node.id.clone(), agent_node_role(config, node)))
.collect();
- crate::inference::readiness::evaluate(ctx, config, &roles).await
+ let evaluation = crate::inference::readiness::evaluate(ctx, config, &roles).await?;
+ let message = format_evaluation(&evaluation);
+ let node_id = match evaluation.failures.as_slice() {
+ [failure] if failure.node_ids.len() == 1 => Some(failure.node_ids[0].clone()),
+ _ => None,
+ };
+ Some(InferenceReadinessEvaluation {
+ status: evaluation.status,
+ message,
+ node_id,
+ })
}
/// Run-time hard gate, returned in the flows domain's established error shape.
@@ -130,14 +144,11 @@ pub(crate) async fn validate_inference_readiness(
let Some(evaluation) = evaluate_inference_readiness(ctx, config, graph).await else {
return Vec::new();
};
- let Some(message) = format_evaluation(evaluation.clone()) else {
+ let Some(message) = evaluation.message else {
return Vec::new();
};
- if evaluation.failures.len() == 1 && evaluation.failures[0].node_ids.len() == 1 {
- vec![format!(
- "Node '{}': {message}",
- evaluation.failures[0].node_ids[0]
- )]
+ if let Some(node_id) = evaluation.node_id {
+ vec![format!("Node '{node_id}': {message}")]
} else {
vec![message]
}
diff --git a/crates/openhuman-core/src/flows/ops_connection_ref_gate_tests.rs b/crates/openhuman-core/src/flows/ops_connection_ref_gate_tests.rs
index ba7a8069fd..859dbb0eb5 100644
--- a/crates/openhuman-core/src/flows/ops_connection_ref_gate_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_connection_ref_gate_tests.rs
@@ -1,88 +1,5 @@
use super::*;
-/// The negative-probe cache (design correction, item 3): a definitive
-/// `provider_not_configured` result must be served from cache within the TTL
-/// exactly like a `"ready"` result, so an edit -> validate -> propose -> run
-/// authoring/run burst hits the mock backend once, not once per call (the judge's
-/// live run observed 4 network round trips in a single ~80s turn before this
-/// fix). Uses a real local axum server (no real network) that counts requests
-/// so a cache hit is provable, not just plausible.
-#[tokio::test]
-async fn cached_probe_inference_readiness_caches_a_negative_result() {
- use std::sync::atomic::{AtomicUsize, Ordering};
-
- let tmp = TempDir::new().unwrap();
- let mut config = test_config(&tmp);
- seed_app_session_for_gate_test(&tmp);
-
- let hit_count = std::sync::Arc::new(AtomicUsize::new(0));
- let counter = hit_count.clone();
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
- .await
- .expect("bind");
- let addr = listener.local_addr().expect("local_addr");
- let app = axum::Router::new().route(
- "/openai/v1/chat/completions",
- axum::routing::post(move || {
- let counter = counter.clone();
- async move {
- counter.fetch_add(1, Ordering::SeqCst);
- use axum::response::IntoResponse;
- (
- axum::http::StatusCode::BAD_REQUEST,
- axum::Json(json!({
- "success": false,
- "error": "API key not configured for provider",
- "errorCode": "BAD_REQUEST"
- })),
- )
- .into_response()
- }
- }),
- );
- tokio::spawn(async move {
- axum::serve(listener, app).await.expect("serve");
- });
- config.api_url = Some(format!("http://{addr}"));
-
- // First call: a real (mock) network round trip, definitively rejected.
- let first = cached_probe_inference_readiness(
- &crate::core::runtime::DispatchCtx::ambient(),
- "summarization",
- &config,
- )
- .await;
- let err = first.expect_err("a confirmed provider-not-configured 400 must reject");
- assert!(
- err.to_ascii_lowercase()
- .contains("api key not configured for provider"),
- "error must surface the backend's own message: {err}"
- );
- assert_eq!(
- hit_count.load(Ordering::SeqCst),
- 1,
- "the first call must hit the (mock) network exactly once"
- );
-
- // Second call, same (role, config_path) key, well within the TTL: must be
- // served from cache — the mock server's hit count must NOT increase.
- let second = cached_probe_inference_readiness(
- &crate::core::runtime::DispatchCtx::ambient(),
- "summarization",
- &config,
- )
- .await;
- assert!(
- second.is_err(),
- "the cached negative result must still be an Err"
- );
- assert_eq!(
- hit_count.load(Ordering::SeqCst),
- 1,
- "a repeat probe within the TTL must be served from cache, not hit the network again"
- );
-}
-
#[tokio::test]
async fn validate_tool_contracts_rejects_a_hallucinated_slug() {
seed_live_catalog_cache("slack", vec![seeded_slack_send_contract()]);
diff --git a/crates/openhuman-core/src/inference/readiness.rs b/crates/openhuman-core/src/inference/readiness.rs
index 0de63006d9..24e33e82aa 100644
--- a/crates/openhuman-core/src/inference/readiness.rs
+++ b/crates/openhuman-core/src/inference/readiness.rs
@@ -20,6 +20,7 @@ type Cache = HashMap<CacheKey, CacheEntry>;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ReadinessFailure {
pub status: &'static str,
+ pub session_wide: bool,
pub role: &'static str,
pub message: String,
pub node_ids: Vec<String>,
@@ -107,6 +108,7 @@ pub async fn evaluate(
status: "signed_out",
failures: vec![ReadinessFailure {
status: "signed_out",
+ session_wide: true,
role: nodes[0].1,
message: "Inference unavailable: you are signed out. Sign in to OpenHuman to run agent nodes.".into(),
node_ids: vec![first_node_id.clone()],
@@ -131,6 +133,7 @@ pub async fn evaluate(
status: "signed_out",
failures: vec![ReadinessFailure {
status: "signed_out",
+ session_wide: true,
role: nodes[0].1,
message: format!(
"Inference unavailable: {error} Sign in to OpenHuman to run agent nodes."
@@ -151,6 +154,7 @@ pub async fn evaluate(
tracing::warn!(target: "inference", nodes = ?node_ids, role, "inference readiness probe rejected: {message}");
failures.push(ReadinessFailure {
status: classify(&message),
+ session_wide: false,
role,
message,
node_ids,