Skip to content

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

feat(ops_discover): resolve cross-scope skill collisions with scope precedence

Steven Enamakelfe27dec3b984
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context.rs b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context.rs
index ccc98152c2..85f67e5571 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context.rs
@@ -28,4 +28,4 @@ pub use scout_run::{run_context_scout, run_context_scout_with_catalog};
pub use tool::AgentPrepareContextTool;
#[cfg(test)]
-use scout_run::{extract_context_bundle, is_expected_billing_failure, scout_failure_signal};
+use scout_run::{extract_context_bundle, is_expected_billing_failure, log_scout_failure, scout_failure_signal};
diff --git a/crates/openhuman-core/src/skills/ops_discover/collision.rs b/crates/openhuman-core/src/skills/ops_discover/collision.rs
index d694985e2f..a5fc2fa1a9 100644
--- a/crates/openhuman-core/src/skills/ops_discover/collision.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/collision.rs
@@ -1,6 +1,57 @@
-//! Compatibility helper for scope precedence tests.
+//! Cross-scope collision resolution for discovered skills.
-use crate::skills::ops_types::WorkflowScope;
+use std::collections::HashMap;
+
+use crate::skills::ops_types::{Workflow, WorkflowScope};
+
+pub(super) fn absorb(by_name: &mut HashMap<String, Workflow>, incoming: Vec<Workflow>) {
+ for mut skill in incoming {
+ let key = skill.name.clone();
+ let collision_keys: Vec<String> = by_name
+ .iter()
+ .filter(|(existing_name, existing)| {
+ existing_name.as_str() == key || existing.dir_name == skill.dir_name
+ })
+ .map(|(existing_name, _)| existing_name.clone())
+ .collect();
+
+ if let Some((highest_name, highest_scope)) = collision_keys
+ .iter()
+ .filter_map(|collision_key| by_name.get(collision_key))
+ .map(|existing| (existing.name.clone(), existing.scope))
+ .max_by_key(|(_, scope)| precedence(*scope))
+ && precedence(skill.scope) < precedence(highest_scope)
+ {
+ if let Some(kept) = by_name.get_mut(&highest_name) {
+ kept.warnings.push(format!(
+ "workflow id '{}' or name '{}' also declared in {:?} scope at {} (ignored)",
+ skill.dir_name,
+ skill.name,
+ skill.scope,
+ skill.location
+ .as_deref()
+ .map_or_else(|| "<unknown>".to_owned(), |path| path.display().to_string())
+ ));
+ }
+ continue;
+ }
+
+ for collision_key in collision_keys {
+ if let Some(loser) = by_name.remove(&collision_key) {
+ skill.warnings.push(format!(
+ "shadowed {:?}-scope skill '{}' (workflow id '{}') at {}",
+ loser.scope,
+ loser.name,
+ loser.dir_name,
+ loser.location
+ .as_deref()
+ .map_or_else(|| "<unknown>".to_owned(), |path| path.display().to_string())
+ ));
+ }
+ }
+ by_name.insert(key, skill);
+ }
+}
pub(super) const fn precedence(scope: WorkflowScope) -> u8 {
match scope {
diff --git a/crates/openhuman-core/src/skills/ops_discover/resource.rs b/crates/openhuman-core/src/skills/ops_discover/resource.rs
index e09c1b70d1..e4fe81d9df 100644
--- a/crates/openhuman-core/src/skills/ops_discover/resource.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/resource.rs
@@ -8,6 +8,19 @@ use crate::skills::ops_types::WorkflowScope;
use super::api::load_workflow_metadata_for_profile;
use super::scan::scan_root;
+fn reject_symlink_components(root: &Path, relative_path: &Path) -> Result<(), String> {
+ let mut current = root.to_path_buf();
+ for component in relative_path.components() {
+ current.push(component.as_os_str());
+ let metadata = std::fs::symlink_metadata(&current)
+ .map_err(|error| format!("failed to stat resource {}: {error}", current.display()))?;
+ if metadata.file_type().is_symlink() {
+ return Err("resource path is a symlink".to_owned());
+ }
+ }
+ Ok(())
+}
+
pub fn read_workflow_resource(
workspace_dir: &Path,
skill_id: &str,
@@ -40,5 +53,11 @@ pub fn read_workflow_resource_with_profile(
load_workflow_metadata_for_profile(workspace_dir, profile_skills_root),
skill_id,
)?;
+ let root = skill
+ .location
+ .as_deref()
+ .and_then(Path::parent)
+ .ok_or_else(|| format!("skill '{skill_id}' has no on-disk location"))?;
+ reject_symlink_components(root, relative_path)?;
tinyskills::read_resource(&skill, relative_path)
}
diff --git a/crates/openhuman-core/src/skills/ops_discover/scan.rs b/crates/openhuman-core/src/skills/ops_discover/scan.rs
index 0761e7af84..61f943a9e0 100644
--- a/crates/openhuman-core/src/skills/ops_discover/scan.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/scan.rs
@@ -3,9 +3,12 @@
//! the full discovery surface and the automations-only view share.
use std::path::{Path, PathBuf};
+use std::collections::HashMap;
use crate::skills::ops_types::{Workflow, WorkflowScope};
+use super::collision::absorb;
+
/// Which on-disk root category a bundle was discovered under.
///
/// `Workflow` roots (`.openhuman/workflows/`) hold task *automations* authored
@@ -46,7 +49,7 @@ pub(super) fn discover_filtered(
);
// Scan order matters for collision resolution: the last scope to register
// a name wins, so we scan user first, then project, then legacy.
- let mut discovered = Vec::new();
+ let mut discovered = HashMap::new();
// Builtin skills (`<workspace>/.openhuman/builtin-skills/`) are a skill
// root scanned FIRST and at the lowest precedence, so every other scope
@@ -62,7 +65,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::Builtin,
"[workflows] discover:branch:builtin"
);
- discovered.extend(scan_bundled_root(&root, WorkflowScope::Builtin));
+ absorb(&mut discovered, scan_bundled_root(&root, WorkflowScope::Builtin));
}
}
@@ -75,7 +78,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::User,
"[workflows] discover:branch:user"
);
- discovered.extend(scan_root(&root, WorkflowScope::User));
+ absorb(&mut discovered, scan_root(&root, WorkflowScope::User));
}
}
}
@@ -90,7 +93,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::Project,
"[workflows] discover:branch:project"
);
- discovered.extend(scan_root(&root, WorkflowScope::Project));
+ absorb(&mut discovered, scan_root(&root, WorkflowScope::Project));
}
}
}
@@ -105,7 +108,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::Legacy,
"[workflows] discover:branch:legacy"
);
- discovered.extend(scan_root(&legacy_root, WorkflowScope::Legacy));
+ absorb(&mut discovered, scan_root(&legacy_root, WorkflowScope::Legacy));
}
}
@@ -124,7 +127,7 @@ pub(super) fn discover_filtered(
"[profiles] discover:branch:profile-local skills"
);
let before = discovered.len();
- discovered.extend(scan_root(profile_root, WorkflowScope::Profile));
+ absorb(&mut discovered, scan_root(profile_root, WorkflowScope::Profile));
tracing::debug!(
names_before = before,
names_after = discovered.len(),
@@ -133,7 +136,8 @@ pub(super) fn discover_filtered(
}
}
- let out = tinyskills::resolve_collisions(discovered);
+ let mut out: Vec<_> = discovered.into_values().collect();
+ out.sort_by(|left, right| left.name.cmp(&right.name));
tracing::debug!(discovered_count = out.len(), "[workflows] discover:exit");
out
}