Skip to content

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

fix(agent): close a handed-off pack by construction, not by visibility (#6302)

M3gA-Mindddeb0d65c945
diff --git a/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs b/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs
index 1dec7b8687..db4c774209 100644
--- a/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs
+++ b/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs
@@ -98,7 +98,6 @@ impl AgentBuilder {
crate::tools::toolpacks::close_handed_off_packs(
&mut tool_policy_session,
&agent_definition_name,
- &visible_names,
&all_tools,
);
diff --git a/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs b/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs
index c1a17923c6..f732908631 100644
--- a/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs
@@ -456,7 +456,6 @@ impl Agent {
crate::tools::toolpacks::close_handed_off_packs(
&mut session,
&self.agent_definition_name,
- &self.visible_tool_names,
&all_tools,
);
self.tool_policy_session = session;
diff --git a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.md b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.md
index aca05c3bf1..60cf1f9934 100644
--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.md
+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.md
@@ -25,10 +25,11 @@ Take the first branch that applies:
4. **Needs a specialist** — every specialist you can call directly is already in your tool list with its own description, so read those rather than a table restating them. A capability that is _not_ in your tool list is not missing: **Capabilities not in your tool list** below names the ones a skill is holding and how to reach them.
- Never recite a UI menu path from memory. Channels and apps live under **Connections** in the left sidebar (Channels / OAuth tabs); there is no "Settings → Connections" submenu. Unsure of the exact path? Say so instead of guessing.
- Crypto and market work enforces read → simulate → confirm → execute and refuses to fabricate chain ids, token addresses or market symbols. **Never** route a crypto write through `delegate_to_integrations_agent` or `run_code`.
- - **Skills.** Find or install a skill → `setup_skills`. Run an installed one (see **Installed Skills**) → `run_skill`. Hand over the whole task: don't search a registry, install, or read a skill yourself.
- - **MCP servers.** Use an already-connected server (see **Connected MCP Servers**) → `use_mcp_server`. Add, install or connect a new one → `setup_mcp_server`. Pass a plain-language task, not server ids or tool names.
+ - **Skills.** Find or install a skill → `setup_skills`. Run an installed one (see **Installed Skills**) → `run_skill`. Hand over the whole task: don't search a registry, install, or read a skill yourself.<!--route:skills-->
+ - **MCP servers.** Use an already-connected server (see **Connected MCP Servers**) → `use_mcp_server`. Add, install or connect a new one → `setup_mcp_server`. Pass a plain-language task, not server ids or tool names.<!--route:mcp-->
- A skill runs in an isolated worker, so its instructions never enter this conversation — you get only its result. If that result carries a `## Handoff Plan` (steps its narrow toolset couldn't perform, e.g. sending email or writing memory), carry them out yourself through the routes above and report the combined outcome. Treat them as _proposed_ actions: never bypass the approval gate, especially for third-party skills.
- - Live or time-sensitive asks (weather, forecasts, prices, recent news, "use live data") get answered **now**. If a server under **Connected MCP Servers** can answer, hand it to `use_mcp_server` first. Otherwise, one quick fact direct, anything broader via `research` with a prompt that asks for live sources. Don't stop at "on it", and don't wait for a named provider that isn't wired in.
+ - Live or time-sensitive asks (weather, forecasts, prices, recent news, "use live data") get answered **now**: one quick fact direct, anything broader via `research` with a prompt that asks for live sources. Don't stop at "on it", and don't wait for a named provider that isn't wired in.
+ - Before either, check **Connected MCP Servers**: if one of them can answer, hand it to `use_mcp_server` first.<!--route:mcp-->
5. **Distill every delegated reply.** A sub-agent's output is raw material, not your answer. Extract only what answers the question; drop its working notes, restated context, and anything the user already has. If the useful answer is two sentences, send two, even when the sub-agent returned eight paragraphs. Never paste a sub-agent's response verbatim.
diff --git a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
index 0c88d7e775..da1c3b22b3 100644
--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
@@ -43,7 +43,18 @@ pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
out.push_str("\n\n");
}
- out.push_str(ARCHETYPE.trim_end());
+ // Resolved once: the same three routes decide both the static rows below
+ // and the generated sections further down, and they must agree (#6302).
+ let skill_run = hand_off_route(ctx, "skill_executor");
+ let skill_install = hand_off_route(ctx, "skill_setup");
+ let mcp_route = hand_off_route(ctx, "mcp_agent");
+
+ let archetype = strip_route_lines(
+ ARCHETYPE,
+ skill_run.is_some() || skill_install.is_some(),
+ mcp_route.is_some(),
+ );
+ out.push_str(archetype.trim_end());
out.push_str("\n\n");
let user_files = render_user_files(ctx)?;
@@ -60,8 +71,8 @@ pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
let skills = render_installed_skills(
ctx.workflows,
- hand_off_route(ctx, "skill_executor").as_deref(),
- hand_off_route(ctx, "skill_setup").as_deref(),
+ skill_run.as_deref(),
+ skill_install.as_deref(),
);
if !skills.trim().is_empty() {
out.push_str(skills.trim_end());
@@ -80,7 +91,7 @@ pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
out.push_str("\n\n");
}
- let mcp_servers = render_connected_mcp_servers(hand_off_route(ctx, "mcp_agent").as_deref());
+ let mcp_servers = render_connected_mcp_servers(mcp_route.as_deref());
if !mcp_servers.trim().is_empty() {
out.push_str(mcp_servers.trim_end());
out.push_str("\n\n");
@@ -236,6 +247,13 @@ fn hand_off_route(ctx: &PromptContext<'_>, specialist: &str) -> Option<String> {
if ctx.visible_tool_names.is_empty() || ctx.visible_tool_names.contains(&tool) {
return Some(format!("`{tool}`"));
}
+ // A packed route is only a route if this session can call `use_skill`
+ // itself. A filtered belt holding neither the delegate nor `use_skill` has
+ // no way to reach the specialist, and naming one anyway is the same "call a
+ // tool you do not have" failure this whole block exists to end (#6302).
+ if !ctx.visible_tool_names.contains(toolpacks::USE_SKILL) {
+ return None;
+ }
toolpacks::pack_for_tool(&tool).map(|pack| {
format!(
"`use_skill {{ \"skill\": \"{}\", \"tool\": \"{tool}\" }}`",
@@ -244,6 +262,33 @@ fn hand_off_route(ctx: &PromptContext<'_>, specialist: &str) -> Option<String> {
})
}
+/// `prompt.md` with the route-tagged rows this build cannot honour removed.
+///
+/// A row tagged `<!--route:skills-->` or `<!--route:mcp-->` names a hand-off
+/// that exists only while that family is compiled in: with `skills` off the
+/// loader drops `skill_setup` and `skill_executor` from the builtins, so no
+/// delegate is synthesised and the static row would order the model to call a
+/// tool nobody has — the very failure this issue is about (#6302). The tag is
+/// stripped from every row that stays, so it never reaches the model.
+fn strip_route_lines(archetype: &str, skills: bool, mcp: bool) -> String {
+ const SKILLS_TAG: &str = "<!--route:skills-->";
+ const MCP_TAG: &str = "<!--route:mcp-->";
+ archetype
+ .lines()
+ .filter(|line| {
+ if line.contains(SKILLS_TAG) {
+ skills
+ } else if line.contains(MCP_TAG) {
+ mcp
+ } else {
+ true
+ }
+ })
+ .map(|line| line.replace(SKILLS_TAG, "").replace(MCP_TAG, ""))
+ .collect::<Vec<_>>()
+ .join("\n")
+}
+
/// The registry entry behind `agent_id`, tolerating the web channel's rename.
///
/// `PromptContext::agent_id` carries `Agent::agent_definition_name`, which the
diff --git a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt_tests_session_routing_tests.rs b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt_tests_session_routing_tests.rs
index 089cbe94c8..d1349bb4b2 100644
--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt_tests_session_routing_tests.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt_tests_session_routing_tests.rs
@@ -164,10 +164,16 @@ fn prompt_routes_workflow_authoring_to_the_builder_not_use_skill() {
fn skill_and_mcp_sections_name_the_hand_off_this_session_can_call() {
crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
.expect("builtin agent definitions must load");
- let belt: HashSet<String> = ["setup_skills", "run_skill", "use_mcp_server", "research"]
- .iter()
- .map(|s| s.to_string())
- .collect();
+ let belt: HashSet<String> = [
+ "setup_skills",
+ "run_skill",
+ "use_mcp_server",
+ "research",
+ "use_skill",
+ ]
+ .iter()
+ .map(|s| s.to_string())
+ .collect();
let mut ctx = ctx_with(&[]);
ctx.agent_id = "orchestrator";
ctx.visible_tool_names = &belt;
@@ -205,4 +211,56 @@ fn skill_and_mcp_sections_name_the_hand_off_this_session_can_call() {
"`{handoff}` is a direct tool and must not be listed as withheld:\n{block}"
);
}
+
+ // A packed route needs `use_skill` on the belt. A session filtered down to
+ // neither the delegate nor `use_skill` cannot reach the specialist at all,
+ // and naming a call it cannot make is the bug, not the fix.
+ let no_use_skill: HashSet<String> = ["setup_skills", "research"]
+ .iter()
+ .map(|s| s.to_string())
+ .collect();
+ ctx.visible_tool_names = &no_use_skill;
+ assert_eq!(
+ hand_off_route(&ctx, "crypto_agent"),
+ None,
+ "without `use_skill` there is no packed route to name"
+ );
+ assert_eq!(
+ hand_off_route(&ctx, "skill_setup").as_deref(),
+ Some("`setup_skills`"),
+ "a delegate on the belt is still a direct route"
+ );
+}
+
+/// A row `prompt.md` tags for a family this build lacks must not reach the
+/// model, and the tag itself never does.
+#[test]
+fn a_route_tagged_prompt_row_is_dropped_when_its_family_is_absent() {
+ let md = "keep me\n - Skills row<!--route:skills-->\n - MCP row<!--route:mcp-->\ntail";
+
+ let both = strip_route_lines(md, true, true);
+ assert!(
+ both.contains("Skills row") && both.contains("MCP row"),
+ "both rows survive when both families are present: {both}"
+ );
+ assert!(
+ !both.contains("<!--route:"),
+ "the tag is an authoring marker and must never reach the model: {both}"
+ );
+
+ let neither = strip_route_lines(md, false, false);
+ assert!(
+ !neither.contains("Skills row") && !neither.contains("MCP row"),
+ "a row whose family is compiled out must be dropped: {neither}"
+ );
+ assert!(
+ neither.contains("keep me") && neither.contains("tail"),
+ "untagged prose is untouched: {neither}"
+ );
+
+ let skills_only = strip_route_lines(md, true, false);
+ assert!(
+ skills_only.contains("Skills row") && !skills_only.contains("MCP row"),
+ "each tag is decided on its own: {skills_only}"
+ );
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs
index 5051a9cbc9..2f4981eccc 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs
@@ -207,23 +207,18 @@ impl ToolPolicyMiddleware {
.render(),
);
}
- let tool = self.resolve_tool(&call.name)?;
- let call_required = tool.permission_level_with_args(&call.arguments);
- if call_required > decision.allowed_permission {
- return Some(
- PolicyDenial::PermissionTooLow {
- tool: &call.name,
- required: call_required,
- allowed: decision.allowed_permission,
- channel: &self.channel,
- }
- .render(),
- );
- }
- // For `use_skill`, also validate the resolved inner tool against the
- // session allowlist. Role-hidden packed tools are not checked by the
- // outer policy name; without this check `use_skill` would bypass the
+ // For `use_skill`, validate the resolved inner tool against the session
+ // allowlist. Role-hidden packed tools are not checked by the outer
+ // policy name; without this check `use_skill` would bypass the
// session's effective allowlist for any packed tool.
+ //
+ // This runs BEFORE the argument-level permission check below, and the
+ // order is load-bearing. That check asks
+ // `UseSkillTool::permission_level_with_args`, which reports the
+ // pack-wide CEILING for an inner name it cannot resolve — so on a
+ // channel sitting under that ceiling, an invented name came back as
+ // `PermissionTooLow`: a permission denial for a tool that does not
+ // exist. Existence is not a policy question (#6302).
if call.name == "use_skill" {
if let Some(inner_tool) = call
.arguments
@@ -234,14 +229,17 @@ impl ToolPolicyMiddleware {
// in `skills`) is not a policy problem, and answering it with a
// denial reads as "installs are forbidden" (#6302). A tool the
// named skill does not contain gets that answer, with what this
- // session can call in the skill instead.
+ // session can call in the skill instead — and so does a pack
+ // member this core never registered (feature gate, or an
+ // embedder's `ToolGroups::Off`), which is equally absent no
+ // matter what the static pack table says.
if let Some(pack) = call
.arguments
.get("skill")
.and_then(serde_json::Value::as_str)
.and_then(crate::tools::toolpacks::pack)
{
- if !pack.owns(inner_tool) {
+ if !pack.owns(inner_tool) || self.resolve_tool(inner_tool).is_none() {
return Some(self.no_such_pack_tool(pack, inner_tool).render());
}
}
@@ -268,6 +266,24 @@ impl ToolPolicyMiddleware {
}
}
}
+
+ // Per-call permission ceiling, last: an unregistered tool has no level
+ // to compare, and for `use_skill` the level comes from the INNER tool
+ // (`permission_level_with_args`), which the block above has already
+ // proved to exist and to be reachable in this session.
+ let tool = self.resolve_tool(&call.name)?;
+ let call_required = tool.permission_level_with_args(&call.arguments);
+ if call_required > decision.allowed_permission {
+ return Some(
+ PolicyDenial::PermissionTooLow {
+ tool: &call.name,
+ required: call_required,
+ allowed: decision.allowed_permission,
+ channel: &self.channel,
+ }
+ .render(),
+ );
+ }
None
}
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs
index 0e07ee2963..aa685b0844 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs
@@ -54,6 +54,13 @@ fn allow(name: &str) -> (String, ToolPolicyDecision) {
/// tool — exactly the orchestrator's shape. Anything not named here is denied,
/// because `decision_for` defaults to `Deny`.
fn non_owner_middleware() -> ToolPolicyMiddleware {
+ non_owner_middleware_at(PermissionLevel::Dangerous)
+}
+
+/// The same session at a chosen ceiling, so a test can sit a channel BELOW the
+/// pack's permission ceiling — where `use_skill` reports the pack-wide maximum
+/// for an inner name it cannot resolve (#6302).
+fn non_owner_middleware_at(allowed: PermissionLevel) -> ToolPolicyMiddleware {
let mut tools: Vec<Box<dyn crate::tools::traits::Tool>> = vec![
Box::new(RoutingFakeTool("build_workflow")),
Box::new(RoutingFakeTool("propose_workflow")),
@@ -73,7 +80,7 @@ fn non_owner_middleware() -> ToolPolicyMiddleware {
channel: "web_chat".to_string(),
entrypoint: "chat".to_string(),
risk_level: TaskRiskLevel::Low,
- allowed_permission: PermissionLevel::Dangerous,
+ allowed_permission: allowed,
},
capabilities: vec![ToolCapability {
name: "build_workflow".to_string(),
@@ -396,3 +403,66 @@ async fn an_invented_tool_name_in_a_skill_is_not_reported_as_a_denial() {
"the answer must name what this session can call in the skill: {message}"
);
}
+
+/// A channel under the pack's ceiling must still get "no such tool".
+///
+/// `UseSkillTool::permission_level_with_args` cannot resolve an invented inner
+/// name, so it reports the pack-wide CEILING. With the ceiling check running
+/// first, that turned an invented name into `PermissionTooLow` — a permission
+/// denial for a tool that does not exist, on exactly the restricted channels
+/// where the wording matters most (#6302).
+#[test]
+fn an_invented_tool_name_is_not_found_even_under_the_packs_permission_ceiling() {
+ let mw = non_owner_middleware_at(PermissionLevel::ReadOnly);
+ let message = mw
+ .channel_permission_block(&call(
+ "use_skill",
+ json!({ "skill": "workflows", "tool": "install_workflow" }),
+ ))
+ .expect("an invented tool must be answered, not dispatched");
+
+ assert!(
+ message.starts_with(crate::tools::status::NOT_FOUND_MARKER),
+ "a restricted channel must still answer an invented name as not-found: {message}"
+ );
+ assert!(
+ !message.contains("permission"),
+ "existence is not a permission question: {message}"
+ );
+}
+
+/// A pack member this core never registered is absent, not forbidden.
+///
+/// A feature gate or an embedder's `ToolGroups::Off` removes tools the static
+/// pack table still lists. `pack.owns` says yes, so the call fell through to
+/// the default `Deny` and read as "not allowed in the current session" — which
+/// sends the model looking for permission it can never be granted, instead of
+/// telling it the tool is not here.
+#[test]
+fn a_pack_member_this_session_never_registered_is_not_found_not_forbidden() {
+ let mw = non_owner_middleware();
+ // `save_workflow` is in the `workflows` pack, but this session's registry
+ // holds only `build_workflow` and `propose_workflow`.
+ let workflows = crate::tools::toolpacks::pack("workflows").expect("workflows pack");
+ assert!(
+ workflows.owns("save_workflow"),
+ "the fixture depends on `save_workflow` being a real pack member"
+ );
+
+ let message = mw
+ .channel_permission_block(&call(
+ "use_skill",
+ json!({ "skill": "workflows", "tool": "save_workflow" }),
+ ))
+ .expect("an unregistered member must be answered, not dispatched");
+
+ assert_eq!(
+ message,
+ mw.no_such_pack_tool(workflows, "save_workflow").render(),
+ "an absent pack member gets the typed not-found message"
+ );
+ assert!(
+ !message.contains("not allowed"),
+ "absence must not read as a permission denial: {message}"
+ );
+}
diff --git a/crates/openhuman-core/src/tools/toolpacks/ops.rs b/crates/openhuman-core/src/tools/toolpacks/ops.rs
index f7554a3d82..49682e5d12 100644
--- a/crates/openhuman-core/src/tools/toolpacks/ops.rs
+++ b/crates/openhuman-core/src/tools/toolpacks/ops.rs
@@ -151,26 +151,31 @@ pub fn is_withheld_from(agent_id: &str, tool: &str) -> bool {
///
/// A pack closes only when all of this holds:
/// * it is withheld from `agent_id` (a pack's owner keeps its own belt),
-/// * a tool in `visible` delegates to one of the pack's owners
-/// ([`crate::tools::traits::delegation_target`]).
+/// * one of the pack's owners is the [`delegation_target`] of a hand-off this
+/// agent carries **unpacked** — a delegate no pack withholds, and therefore
+/// one it advertises by construction.
+///
+/// [`delegation_target`]: crate::tools::traits::delegation_target
///
/// Inside a closed pack, a tool that is itself a hand-off (e.g. `create_skill`)
/// stays reachable: it is a route, not a raw tool. A tool whose group an embedder
/// advertised is on the wire, not withheld, and is left alone too.
///
-/// Empty `visible` is the "everything visible" sentinel: nothing is withheld, so
-/// nothing closes.
-pub fn closed_by_direct_handoff(
- agent_id: &str,
- visible: &HashSet<String>,
- tools: &[&dyn Tool],
-) -> Vec<&'static str> {
- if visible.is_empty() {
- return Vec::new();
- }
+/// **Deliberately not keyed on the visible set.** It used to be, and that made
+/// the rule true in tests and false in production. An agent with
+/// `ToolScope::Named` is built with `visible` = its named list, which cannot
+/// contain a *synthesised* delegate like `setup_skills`; those names arrive
+/// later, when `refresh_delegation_tools` inserts them. So at build time no
+/// hand-off looked reachable and nothing closed, while a harness agent — whose
+/// empty visible set is seeded from every tool, synthesised ones included —
+/// closed correctly. The live orchestrator kept its raw `skill_registry_*` /
+/// `mcp_registry_*` route the whole time (#6302). Pack membership is knowable
+/// the moment the tools exist, so the answer no longer depends on when the
+/// visible set is filled in.
+pub fn closed_by_direct_handoff(agent_id: &str, tools: &[&dyn Tool]) -> Vec<&'static str> {
let reachable_owners: HashSet<&str> = tools
.iter()
- .filter(|tool| visible.contains(tool.name()))
+ .filter(|tool| registry::pack_for_tool(tool.name()).is_none())
.filter_map(|tool| crate::tools::traits::delegation_target(*tool))
.collect();
if reachable_owners.is_empty() {
@@ -202,10 +207,9 @@ pub fn closed_by_direct_handoff(
pub fn close_handed_off_packs(
session: &mut crate::tools::agent_policy::ToolPolicySession,
agent_id: &str,
- visible: &HashSet<String>,
tools: &[&dyn Tool],
) {
- let closed = closed_by_direct_handoff(agent_id, visible, tools);
+ let closed = closed_by_direct_handoff(agent_id, tools);
if closed.is_empty() {
return;
}
diff --git a/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs b/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs
index 88a3ac08e6..60279cf82a 100644
--- a/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs
+++ b/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs
@@ -353,13 +353,9 @@ fn a_direct_hand_off_closes_its_owners_pack_and_nothing_else() {
.map(|t| t.as_ref())
.chain(delegates.iter().map(|t| t.as_ref()))
.collect();
- // `setup_skills` is on the belt; `create_skill` and `do_crypto` are packed.
- let visible: HashSet<String> = ["setup_skills", USE_SKILL]
- .iter()
- .map(|s| s.to_string())
- .collect();
-
- let closed = closed_by_direct_handoff("orchestrator", &visible, &tools);
+ // `setup_skills` is unpacked, so the orchestrator advertises it by
+ // construction; `create_skill` and `do_crypto` are packed.
+ let closed = closed_by_direct_handoff("orchestrator", &tools);
assert!(
closed.contains(&"skill_registry_install"),
"a raw tool of the pack `setup_skills` hands off to must close: {closed:?}"
@@ -378,11 +374,83 @@ fn a_direct_hand_off_closes_its_owners_pack_and_nothing_else() {
);
assert!(
- closed_by_direct_handoff("skill_setup", &visible, &tools).is_empty(),
+ closed_by_direct_handoff("skill_setup", &tools).is_empty(),
"a pack's owner keeps its own belt"
);
+
+ // The live regression (#6302): a `ToolScope::Named` agent is built with
+ // `visible` = its named list, which never contains a synthesised delegate.
+ // Keyed on the visible set, this closed nothing on a real session while
+ // every test passed. Pack membership is knowable as soon as the tools are,
+ // so the raw tools close with no visible set in the picture at all.
+ let named_only: Vec<&dyn crate::tools::traits::Tool> = raw.iter().map(|t| t.as_ref()).collect();
+ assert!(
+ closed_by_direct_handoff("orchestrator", &named_only).is_empty(),
+ "with no hand-off among the tools there is nothing to close: the rule \
+ must key on a hand-off existing, not on a pack existing"
+ );
+}
+
+/// The live session shape, which the rule test above cannot catch.
+///
+/// This is the regression the first cut shipped (#6302): a `ToolScope::Named`
+/// agent is built with `visible` = the list its `agent.toml` names, and a
+/// *synthesised* delegate like `setup_skills` is by definition not in it — those
+/// names arrive later, when `refresh_delegation_tools` inserts them. Keyed on
+/// `visible`, the closing rule did nothing on a real chat session: the live
+/// orchestrator went on calling `use_skill skills/skill_registry_search` and
+/// `skill_registry_install` for real, while every harness test passed, because a
+/// harness agent's empty visible set is seeded from every tool, synthesised ones
+/// included.
+///
+/// Asserts `blocks_execution`, not `is_denied`: a merely withheld packed tool is
+/// `HideFromPrompt`, for which `is_denied()` answers true, so an `is_denied`
+/// assertion would pass without the fix.
+#[test]
+fn a_named_scope_session_closes_the_pack_its_visible_list_never_mentions() {
+ use crate::agent::orchestration::tools::{ArchetypeDelegationTool, DelegationTarget};
+ use crate::tools::agent_policy::ToolPolicyEngine;
+
+ let delegate: Box<dyn crate::tools::traits::Tool> = Box::new(ArchetypeDelegationTool {
+ tool_name: "setup_skills".to_string(),
+ agent_id: DelegationTarget("skill_setup".to_string()),
+ tool_description: String::new(),
+ });
+ let raw = registry_with_all(&["skill_registry_install"]);
+ let tools: Vec<&dyn crate::tools::traits::Tool> = raw
+ .iter()
+ .map(|t| t.as_ref())
+ .chain(std::iter::once(delegate.as_ref()))
+ .collect();
+
+ // Exactly what the builder hands a Named agent: its own list. No delegate.
+ let visible: HashSet<String> = ["shell", USE_SKILL].iter().map(|s| s.to_string()).collect();
+ let build = || {
+ ToolPolicyEngine::build_session_from_refs(
+ "orchestrator",
+ "web_chat",
+ "session",
+ &Default::default(),
+ &tools,
+ &visible,
+ )
+ };
+
+ assert!(
+ !build()
+ .decision_for("skill_registry_install")
+ .blocks_execution(),
+ "precondition: withheld-but-callable is the pack default, so this test \
+ can only fail for the right reason if closing is what blocks it"
+ );
+
+ let mut session = build();
+ close_handed_off_packs(&mut session, "orchestrator", &tools);
assert!(
- closed_by_direct_handoff("orchestrator", &HashSet::new(), &tools).is_empty(),
- "an empty visible set withholds nothing, so nothing closes"
+ session
+ .decision_for("skill_registry_install")
+ .blocks_execution(),
+ "`setup_skills` is unpacked, so the orchestrator advertises it and the \
+ raw registry tool must close — even though `visible` never named it"
);
}
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rs
index ffd007d19d..4ea905bf18 100644
--- a/tests/agent_harness_e2e.rs
+++ b/tests/agent_harness_e2e.rs
@@ -3239,10 +3239,13 @@ fn tool_result_text(requests: &[Value], tool_name: &str) -> Option<String> {
})
}
+#[cfg(feature = "skills")]
const REGISTRY_SKILL_ID: &str = "harness-registry-skill";
+#[cfg(feature = "skills")]
const SKILL_BODY_CANARY: &str = "SKILL_BODY_CANARY_7f3a";
/// A one-entry skill catalog plus the SKILL.md its download URL points at.
+#[cfg(feature = "skills")]
async fn serve_skill_registry_fixture() -> (
SocketAddr,
tokio::task::JoinHandle<Result<(), std::io::Error>>,
@@ -3274,6 +3277,10 @@ async fn serve_skill_registry_fixture() -> (
/// A skill found in the registry is installed by the agent (behind the approval
/// gate), lands on disk, and is then loaded by the skill executor, with its body
/// reaching the model.
+// `skills` off drops `skill_setup`/`skill_executor` from the builtins, and this
+// target declares no `required-features`, so an ungated skill test would run
+// and fail instead of being skipped.
+#[cfg(feature = "skills")]
#[test]
fn agent_installs_a_registry_skill_then_runs_it() {
run_on_agent_stack(
@@ -3282,6 +3289,7 @@ fn agent_installs_a_registry_skill_then_runs_it() {
);
}
+#[cfg(feature = "skills")]
async fn agent_installs_a_registry_skill_then_runs_it_inner() {
let _lock = env_lock();
let _ttl = EnvVarGuard::set("OPENHUMAN_APPROVAL_TTL_SECS", "120");
@@ -3566,6 +3574,7 @@ async fn wait_for_terminal_without_approval(
/// Skill requests reach `skill_setup` and `skill_executor` through their
/// hand-offs, called directly.
+#[cfg(feature = "skills")]
#[test]
fn orchestrator_hands_skill_requests_to_the_skill_specialists_directly() {
run_on_agent_stack(
@@ -3574,6 +3583,7 @@ fn orchestrator_hands_skill_requests_to_the_skill_specialists_directly() {
);
}
+#[cfg(feature = "skills")]
async fn orchestrator_hands_skill_requests_to_the_skill_specialists_directly_inner() {
let _lock = env_lock();
reset_script(Vec::new());
@@ -3610,6 +3620,7 @@ async fn orchestrator_hands_skill_requests_to_the_skill_specialists_directly_inn
/// With `setup_skills` on its belt, the orchestrator cannot install a skill
/// itself through `use_skill`: the gate refuses the raw tool and names the
/// hand-off even once the user has approved the call, and nothing lands on disk.
+#[cfg(feature = "skills")]
#[test]
fn orchestrator_cannot_install_a_skill_through_the_raw_registry_tool() {
run_on_agent_stack(
@@ -3618,6 +3629,7 @@ fn orchestrator_cannot_install_a_skill_through_the_raw_registry_tool() {
);
}
+#[cfg(feature = "skills")]
async fn orchestrator_cannot_install_a_skill_through_the_raw_registry_tool_inner() {
let _lock = env_lock();
let _ttl = EnvVarGuard::set("OPENHUMAN_APPROVAL_TTL_SECS", "120");