Skip to content

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

fix(ops_discover): handle collision detection in resource scanning

Steven Enamakel21f1f375ad8b
diff --git a/crates/openhuman-core/src/skills/ops_discover.rs b/crates/openhuman-core/src/skills/ops_discover.rs
index ef7f27e60b..b8ef8ea03c 100644
--- a/crates/openhuman-core/src/skills/ops_discover.rs
+++ b/crates/openhuman-core/src/skills/ops_discover.rs
@@ -3,11 +3,9 @@
//!
//! Split into submodules by responsibility: [`api`] holds the public
//! discovery entry points, [`scan`] holds the root-directory scan engine,
-//! [`collision`] holds cross-scope name-collision resolution, and
//! [`resource`] holds bundled-resource reading.
mod api;
-mod collision;
mod resource;
mod scan;
diff --git a/crates/openhuman-core/src/skills/ops_discover/collision.rs b/crates/openhuman-core/src/skills/ops_discover/collision.rs
deleted file mode 100644
index a9668a4c52..0000000000
--- a/crates/openhuman-core/src/skills/ops_discover/collision.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-//! Cross-scope collision resolution for discovered skills.
-
-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 {
- if !is_supported_scope(skill.scope) {
- continue;
- }
- 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();
-
- let highest = 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));
- if let Some((highest_name, highest_scope)) = highest {
- if precedence(skill.scope) >= precedence(highest_scope) {
- // The incoming skill wins ties, preserving the historical
- // last-writer behavior for equal-precedence roots.
- } else {
- 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 {
- WorkflowScope::Builtin => 0,
- WorkflowScope::Legacy => 1,
- WorkflowScope::User => 2,
- WorkflowScope::Project => 3,
- WorkflowScope::Flow => 4,
- _ => 0,
- }
-}
-
-const fn is_supported_scope(scope: WorkflowScope) -> bool {
- matches!(
- scope,
- WorkflowScope::Builtin
- | WorkflowScope::Legacy
- | WorkflowScope::User
- | WorkflowScope::Project
- | WorkflowScope::Flow
- )
-}
diff --git a/crates/openhuman-core/src/skills/ops_discover/resource.rs b/crates/openhuman-core/src/skills/ops_discover/resource.rs
index cdf46511c4..c362d97bf6 100644
--- a/crates/openhuman-core/src/skills/ops_discover/resource.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/resource.rs
@@ -1,36 +1,7 @@
//! OpenHuman discovery context around `tinyskills` resource reads.
use super::api::load_workflow_metadata;
-use std::path::{Component, Path};
-
-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(())
-}
-
-fn validate_relative_path(relative_path: &Path) -> Result<(), String> {
- if relative_path.as_os_str().is_empty() {
- return Err("relative_path must not be empty".to_owned());
- }
- if relative_path.is_absolute() {
- return Err("relative_path must not be absolute".to_owned());
- }
- if relative_path
- .components()
- .any(|component| !matches!(component, Component::Normal(_)))
- {
- return Err("relative_path must not contain '..' or escape the skill directory".to_owned());
- }
- Ok(())
-}
+use std::path::Path;
pub fn read_workflow_resource(
workspace_dir: &Path,
@@ -40,13 +11,6 @@ pub fn read_workflow_resource(
if skill_id.trim().is_empty() {
return Err("skill_id must not be empty".to_string());
}
- validate_relative_path(relative_path)?;
let skill = tinyskills::resolve_skill(load_workflow_metadata(workspace_dir), 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).map_err(|error| error.to_string())
}
diff --git a/crates/openhuman-core/src/skills/ops_discover/scan.rs b/crates/openhuman-core/src/skills/ops_discover/scan.rs
index 0b2ae0f76a..647519880a 100644
--- a/crates/openhuman-core/src/skills/ops_discover/scan.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/scan.rs
@@ -2,12 +2,11 @@
//! into `Workflow` entries, and the shared multi-root scan engine that both
//! the full discovery surface and the automations-only view share.
-use std::collections::HashMap;
use std::path::{Path, PathBuf};
-use crate::skills::ops_types::{Workflow, WorkflowScope};
+use tinyskills::{resolve_collisions_with, CollisionPolicy, TieBreak};
-use super::collision::absorb;
+use crate::skills::ops_types::{Workflow, WorkflowScope};
/// Which on-disk root category a bundle was discovered under.
///
@@ -45,9 +44,10 @@ pub(super) fn discover_filtered(
include_workflows = kinds.contains(&RootKind::Workflow),
"[workflows] discover:enter"
);
- // 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 = HashMap::new();
+ // Scan order matters for collision resolution: among equal-precedence
+ // scopes the last root to register a name wins (`TieBreak::LastWins`), so
+ // we scan builtin first, then user, then project, then legacy.
+ let mut discovered: Vec<Workflow> = Vec::new();
// Builtin skills (`<workspace>/.openhuman/builtin-skills/`) are a skill
// root scanned FIRST and at the lowest precedence, so every other scope
@@ -63,10 +63,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::Builtin,
"[workflows] discover:branch:builtin"
);
- absorb(
- &mut discovered,
- scan_bundled_root(&root, WorkflowScope::Builtin),
- );
+ discovered.extend(scan_bundled_root(&root, WorkflowScope::Builtin));
}
}
@@ -79,7 +76,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::User,
"[workflows] discover:branch:user"
);
- absorb(&mut discovered, scan_root(&root, WorkflowScope::User));
+ discovered.extend(scan_root(&root, WorkflowScope::User));
}
}
}
@@ -94,7 +91,7 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::Project,
"[workflows] discover:branch:project"
);
- absorb(&mut discovered, scan_root(&root, WorkflowScope::Project));
+ discovered.extend(scan_root(&root, WorkflowScope::Project));
}
}
}
@@ -109,15 +106,20 @@ pub(super) fn discover_filtered(
scope = ?WorkflowScope::Legacy,
"[workflows] discover:branch:legacy"
);
- absorb(
- &mut discovered,
- scan_root(&legacy_root, WorkflowScope::Legacy),
- );
+ discovered.extend(scan_root(&legacy_root, WorkflowScope::Legacy));
}
}
- let mut out: Vec<_> = discovered.into_values().collect();
- out.sort_by(|left, right| left.name.cmp(&right.name));
+ // Cross-scope precedence and shadowing warnings are owned by tinyskills;
+ // `Profile` bundles are not a filesystem scope OpenHuman scans.
+ let out = resolve_collisions_with(
+ discovered,
+ &CollisionPolicy {
+ tie_break: TieBreak::LastWins,
+ excluded_scopes: vec![WorkflowScope::Profile],
+ id_noun: "workflow".into(),
+ },
+ );
tracing::debug!(discovered_count = out.len(), "[workflows] discover:exit");
out
}
diff --git a/vendor/tinyskills b/vendor/tinyskills
index d345a858c5..08ca8e5a89 160000
--- a/vendor/tinyskills
+++ b/vendor/tinyskills
@@ -1 +1 @@
-Subproject commit d345a858c59a9a4006ff5de7b85a36e7cb7e435a
+Subproject commit 08ca8e5a898eb60d900e723cd039a19f79b1bde0