Skip to content

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

fix(validation): include member index in deserialization errors

Steven Enamakela2bd66fefc46
diff --git a/crates/openhuman-core/src/flows/ops/validation.rs b/crates/openhuman-core/src/flows/ops/validation.rs
index 84018f44d0..d661f3b54b 100644
--- a/crates/openhuman-core/src/flows/ops/validation.rs
+++ b/crates/openhuman-core/src/flows/ops/validation.rs
@@ -101,10 +101,39 @@ pub(super) fn ensure_config_aware_engine_compatible(
/// validation can surface many at once.
pub(crate) fn migrate_and_deserialize_graph(graph_json: Value) -> Result<WorkflowGraph, String> {
let migrated = tinyflows::migrate::migrate(graph_json).map_err(|e| e.to_string())?;
- let graph: WorkflowGraph = serde_json::from_value(migrated).map_err(|e| e.to_string())?;
+ let graph: WorkflowGraph = serde_json::from_value(migrated.clone()).map_err(|error| {
+ graph_member_deserialization_error(&migrated).unwrap_or_else(|| error.to_string())
+ })?;
Ok(graph)
}
+/// Returns an indexed member path when a graph collection contains the value
+/// that failed to deserialize. Serde's error reports the missing field but not
+/// which item in a collection owns it, which leaves flow authors unable to
+/// repair a multi-node graph from the error alone.
+fn graph_member_deserialization_error(graph: &Value) -> Option<String> {
+ let object = graph.as_object()?;
+
+ member_deserialization_error::<tinyflows::model::WorkflowInput>(object, "inputs")
+ .or_else(|| {
+ member_deserialization_error::<tinyflows::model::AgentDefinition>(object, "agents")
+ })
+ .or_else(|| member_deserialization_error::<tinyflows::model::Node>(object, "nodes"))
+ .or_else(|| member_deserialization_error::<tinyflows::model::Edge>(object, "edges"))
+}
+
+fn member_deserialization_error<T: serde::de::DeserializeOwned>(
+ graph: &serde_json::Map<String, Value>,
+ field: &str,
+) -> Option<String> {
+ let members = graph.get(field)?.as_array()?;
+ members.iter().enumerate().find_map(|(index, member)| {
+ serde_json::from_value::<T>(member.clone())
+ .err()
+ .map(|error| format!("{field}[{index}]: {error}"))
+ })
+}
+
/// Maps a portable `tinyflows` [`ValidationError`](tinyflows::error::ValidationError)
/// into the host's structured [`FlowValidationError`], carrying its stable
/// `code`, anchoring `node_id`, and human `message`. One place so the mapping
diff --git a/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rs b/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rs
index 33094928bf..cbcf64d9ce 100644
--- a/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rs
+++ b/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rs
@@ -28,13 +28,13 @@ fn subagent_anchors_to_parent_turn_by_spawn_timestamp() {
write_raw(dir.path(), root_stem, thread_id, &root_refs);
write_raw(
dir.path(),
- &format!("{root_stem}__999950_coder"),
+ &format!("{root_stem}__1000050_coder"),
thread_id,
&[r#"{"role":"assistant","content":"coder work"}"#],
);
write_raw(
dir.path(),
- &format!("{root_stem}__1000050_planner"),
+ &format!("{root_stem}__2000050_planner"),
thread_id,
&[r#"{"role":"assistant","content":"planner work"}"#],
);