Skip to content

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

refactor: split resumed tool surface and Juice regressions

Steven Enamakel585e29a11a8b
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 78ca1a6278..5f3e73bc4d 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -360,177 +360,6 @@ impl OpenHumanTurnPrelude {
.clone()
}
- /// Rebuild every delegation-dependent tool view from the current cached
- /// integration set, replacing rather than appending. A revoked delegate is
- /// removed from the executable source, schema, and policy together before
- /// this request is prepared.
- fn refresh_delegation_tool_surface(&self) -> anyhow::Result<()> {
- use crate::agent::harness::definition::AgentDefinitionRegistry;
- use crate::tools::agent_policy::ToolPolicyEngine;
- use crate::tools::orchestrator_tools::collect_orchestrator_tools;
-
- let Some(registry) = AgentDefinitionRegistry::current() else {
- return Ok(());
- };
- let Some(definition) = self.session_definition(&registry) else {
- return Ok(());
- };
- let has_recorded_tool_snapshot = self
- .mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .recorded_tool_snapshot_adopted;
- if definition.subagents.is_empty() && !has_recorded_tool_snapshot {
- return Ok(());
- }
- let (integrations, integrations_are_authoritative, recorded_tool_snapshot_adopted) = {
- let mutable = self
- .mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- (
- mutable.connected_integrations.clone(),
- mutable.connected_integrations_authoritative,
- mutable.recorded_tool_snapshot_adopted,
- )
- };
- #[cfg(feature = "mcp")]
- let mcp_tools = self.collect_mcp_search_tools();
- let mut surface = self
- .tool_surface
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- let mut collected = collect_orchestrator_tools(&definition, &registry, &integrations);
- #[cfg(feature = "mcp")]
- collected.extend(mcp_tools);
- let rebuilt = self.rebuilt_recorded_tools(
- &definition,
- &surface.tools,
- &collected,
- &integrations,
- integrations_are_authoritative,
- );
- collected.extend(rebuilt);
- super::managed_tools::reject_synthesized_collisions(
- &surface.permanent_tool_names,
- &collected,
- )?;
- let synthesized =
- super::builder::drop_synthesized_name_collisions(&surface.tools, collected);
- let synthesized_names = synthesized
- .iter()
- .map(|tool| tool.name().to_string())
- .collect::<std::collections::HashSet<_>>();
- let previous_synthesized = std::mem::replace(
- &mut surface.synthesized_tool_names,
- synthesized_names.clone(),
- );
- let auto_include_new_synthesized_tools = surface.auto_include_new_synthesized_tools;
- reconcile_synthesized_visibility(
- &mut surface.visible_tool_names,
- &previous_synthesized,
- &synthesized_names,
- auto_include_new_synthesized_tools,
- );
- if recorded_tool_snapshot_adopted {
- surface.visible_tool_names.extend(
- self.mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .recorded_repl_tools
- .iter()
- .map(|spec| spec.name.clone()),
- );
- }
- // Preserve permanently attached tools when re-deriving the surface.
- permanent::refresh_visibility(&mut surface, &synthesized);
-
- let mut specs = surface
- .durable_tool_specs
- .iter()
- .cloned()
- .chain(synthesized.iter().map(|tool| Arc::new(tool.spec())))
- .collect::<Vec<_>>();
- {
- let recorded = self
- .mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .recorded_repl_tools
- .clone();
- let recorded_names = recorded
- .iter()
- .map(|spec| spec.name.as_str())
- .collect::<std::collections::HashSet<_>>();
- if recorded_tool_snapshot_adopted {
- specs.retain(|spec| {
- !crate::inference::tokenjuice::is_repl_tool(&spec.name)
- || recorded_names.contains(spec.name.as_str())
- });
- surface.visible_tool_names.retain(|name| {
- !crate::inference::tokenjuice::is_repl_tool(name)
- || recorded_names.contains(name.as_str())
- });
- }
- let recorded = recorded
- .iter()
- .map(|spec| (spec.name.as_str(), spec))
- .collect::<std::collections::HashMap<_, _>>();
- for spec in &mut specs {
- if let Some(frozen) = recorded.get(spec.name.as_str()) {
- *spec = Arc::new((*frozen).clone());
- }
- }
- }
- let synthesized_tools = Arc::new(synthesized);
- crate::tools::toolpacks::bind_synthesized_pack_registry(&surface.tools, &synthesized_tools);
- let all_tools = surface
- .tools
- .iter()
- .chain(synthesized_tools.iter())
- .map(|tool| tool.as_ref())
- .collect::<Vec<_>>();
- // Advertised plus deferred, like the session host: a deferred tool
- // outside the set would be `HideFromPrompt`, which the direct-call
- // gate refuses.
- let reachable: std::collections::HashSet<String> = if surface.visible_tool_names.is_empty()
- {
- std::collections::HashSet::new()
- } else {
- surface
- .visible_tool_names
- .iter()
- .chain(surface.deferred_tool_names.iter())
- .cloned()
- .collect()
- };
- let mut policy = ToolPolicyEngine::build_session_from_refs(
- &surface.agent_definition_name,
- &surface.event_channel,
- "session",
- &self.config.channel_permissions,
- &all_tools,
- &reachable,
- );
- crate::tools::toolpacks::close_handed_off_packs(
- &mut policy,
- &surface.agent_definition_name,
- &all_tools,
- );
- let visible = super::builder::dedup_visible_tool_specs(
- super::builder::visible_tool_specs_for_policy(
- &specs,
- &surface.visible_tool_names,
- &policy,
- ),
- );
- surface.tool_specs = Arc::new(specs);
- surface.synthesized_tools = synthesized_tools;
- surface.visible_tool_specs = Arc::new(visible);
- surface.tool_policy_session = policy;
- Ok(())
- }
-
fn drain_host_events(&self) -> bool {
let mut mutable = self
.mutable
@@ -1340,6 +1169,13 @@ impl OpenHumanSessionHost {
}
}
+#[path = "runtime_session_tool_surface.rs"]
+mod tool_surface;
+
+#[cfg(test)]
+#[path = "runtime_session_juice_tests.rs"]
+mod juice_tests;
+
#[path = "prelude_integrations.rs"]
mod prelude_integrations;
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rs
new file mode 100644
index 0000000000..1a464585ae
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rs
@@ -0,0 +1,228 @@
+//! Frozen Juice declarations and executors survive configuration changes.
+
+use super::*;
+
+#[tokio::test]
+async fn a_resumed_thread_keeps_recorded_juice_specs_and_executors_when_repl_is_off() {
+ use crate::inference::tokenjuice::{repl_tools_for, REPL_TOOL_NAMES};
+
+ crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
+ .expect("builtin definitions");
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let mut active_config = crate::config::Config {
+ workspace_dir: tmp.path().join("workspace"),
+ action_dir: tmp.path().join("workspace"),
+ config_path: tmp.path().join("config.toml"),
+ ..Default::default()
+ };
+ std::fs::create_dir_all(&active_config.workspace_dir).expect("workspace");
+ active_config.context.compaction_enabled = true;
+ active_config.tokenjuice.router_enabled = true;
+ active_config.tokenjuice.ccr_enabled = true;
+ active_config.tokenjuice.repl_handle_enabled = true;
+ let mut recorded_specs = repl_tools_for(&active_config)
+ .iter()
+ .map(|tool| tool.spec())
+ .collect::<Vec<_>>();
+ assert_eq!(
+ recorded_specs
+ .iter()
+ .map(|spec| spec.name.as_str())
+ .collect::<Vec<_>>(),
+ REPL_TOOL_NAMES
+ );
+ for spec in &mut recorded_specs {
+ spec.description = format!("frozen declaration for {}", spec.name);
+ spec.parameters = serde_json::json!({"type":"object","frozen":spec.name});
+ }
+ let recorded = ToolSnapshot::new(recorded_specs.clone()).expect("recorded tool snapshot");
+
+ // A fresh process has the same workspace but current policy no longer
+ // creates new handles. The resumed thread must still regain only the
+ // REPL tools it was sent, with their original declarations.
+ let mut current_config = crate::config::Config {
+ workspace_dir: active_config.workspace_dir.clone(),
+ action_dir: active_config.action_dir.clone(),
+ config_path: active_config.config_path.clone(),
+ modules: crate::config::schema::ModulesConfig {
+ enabled: false,
+ ..Default::default()
+ },
+ ..Default::default()
+ };
+ current_config.context.compaction_enabled = false;
+ current_config.tokenjuice.router_enabled = false;
+ current_config.tokenjuice.ccr_enabled = false;
+ current_config.tokenjuice.repl_handle_enabled = false;
+ assert!(repl_tools_for(&current_config).is_empty());
+ let mut host =
+ crate::agent::OpenHumanSessionHost::from_config_for_agent(&current_config, "summarizer")
+ .expect("summarizer session");
+ host.ensure_runtime_session().expect("runtime session");
+ let prelude = host
+ .runtime_state
+ .lock()
+ .expect("runtime state")
+ .prelude
+ .clone()
+ .expect("prelude");
+
+ prelude.adopt_recorded_tools(Some(&recorded));
+ assert_eq!(
+ prelude
+ .mutable
+ .lock()
+ .expect("prelude state")
+ .recorded_repl_tools
+ .len(),
+ recorded_specs.len()
+ );
+ prelude.refresh_turn_boundary(false).await.expect("refresh");
+ let surface_names = {
+ let surface = prelude.tool_surface.lock().expect("tool surface");
+ (
+ surface
+ .tools
+ .iter()
+ .map(|tool| tool.name().to_string())
+ .collect::<Vec<_>>(),
+ surface
+ .synthesized_tools
+ .iter()
+ .map(|tool| tool.name().to_string())
+ .collect::<Vec<_>>(),
+ surface
+ .visible_tool_specs
+ .iter()
+ .map(|spec| spec.name.clone())
+ .collect::<Vec<_>>(),
+ surface.visible_tool_names.clone(),
+ )
+ };
+ let prepared = prelude.prepare(false).await.expect("prepared surface");
+ let prepared = prepared.tools.expect("prepared tool snapshot");
+
+ for recorded_spec in &recorded_specs {
+ let prepared_spec = prepared
+ .specs()
+ .iter()
+ .find(|spec| spec.name == recorded_spec.name)
+ .unwrap_or_else(|| {
+ panic!(
+ "the resumed request lost {}; surface={surface_names:?}",
+ recorded_spec.name
+ )
+ });
+ assert_eq!(prepared_spec.description, recorded_spec.description);
+ assert_eq!(prepared_spec.parameters, recorded_spec.parameters);
+ let surface = prelude.tool_surface.lock().expect("tool surface");
+ assert!(
+ surface
+ .tools
+ .iter()
+ .chain(surface.synthesized_tools.iter())
+ .any(|tool| tool.name() == recorded_spec.name),
+ "the recorded declaration {} needs an executor",
+ recorded_spec.name
+ );
+ }
+ let unavailable = {
+ let surface = prelude.tool_surface.lock().expect("tool surface");
+ let tool = surface
+ .tools
+ .iter()
+ .chain(surface.synthesized_tools.iter())
+ .find(|tool| tool.name() == "juice_find")
+ .expect("recorded executor remains registered");
+ tool.execute(serde_json::json!({"handle":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}))
+ .await
+ .expect("tool reports disabled module as a result")
+ };
+ assert!(
+ unavailable.is_error,
+ "a recorded executor must fail closed when modules are disabled: {}",
+ unavailable.output()
+ );
+}
+
+#[tokio::test]
+async fn resumed_juice_snapshot_does_not_add_live_repl_declarations() {
+ use crate::inference::tokenjuice::{repl_tools_for, REPL_TOOL_NAMES};
+
+ crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
+ .expect("builtin definitions");
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let mut config = crate::config::Config {
+ workspace_dir: tmp.path().join("workspace"),
+ action_dir: tmp.path().join("workspace"),
+ config_path: tmp.path().join("config.toml"),
+ ..Default::default()
+ };
+ std::fs::create_dir_all(&config.workspace_dir).expect("workspace");
+ config.context.compaction_enabled = true;
+ config.tokenjuice.router_enabled = true;
+ config.tokenjuice.ccr_enabled = true;
+ config.tokenjuice.repl_handle_enabled = true;
+ let mut recorded_spec = repl_tools_for(&config)
+ .into_iter()
+ .find(|tool| tool.name() == REPL_TOOL_NAMES[0])
+ .expect("juice_find")
+ .spec();
+ recorded_spec.description = "frozen juice_find declaration".into();
+ recorded_spec.parameters = serde_json::json!({"type":"object","frozen":true});
+ let recorded = ToolSnapshot::new(vec![recorded_spec.clone()]).expect("recorded snapshot");
+
+ let mut host = crate::agent::OpenHumanSessionHost::from_config_for_agent(&config, "summarizer")
+ .expect("summarizer session");
+ host.ensure_runtime_session().expect("runtime session");
+ let prelude = host
+ .runtime_state
+ .lock()
+ .expect("runtime state")
+ .prelude
+ .clone()
+ .expect("prelude");
+ prelude.adopt_recorded_tools(Some(&recorded));
+ prelude.refresh_turn_boundary(false).await.expect("refresh");
+ let prepared = prelude
+ .prepare(false)
+ .await
+ .expect("prepared surface")
+ .tools
+ .expect("tool snapshot");
+
+ let juice_names = prepared
+ .specs()
+ .iter()
+ .filter(|spec| crate::inference::tokenjuice::is_repl_tool(&spec.name))
+ .map(|spec| spec.name.as_str())
+ .collect::<Vec<_>>();
+ assert_eq!(juice_names, [REPL_TOOL_NAMES[0]]);
+ let frozen = prepared
+ .specs()
+ .iter()
+ .find(|spec| spec.name == recorded_spec.name)
+ .expect("recorded spec");
+ assert_eq!(frozen.description, recorded_spec.description);
+ assert_eq!(frozen.parameters, recorded_spec.parameters);
+
+ let empty = ToolSnapshot::new(Vec::new()).expect("empty recorded snapshot");
+ prelude.adopt_recorded_tools(Some(&empty));
+ prelude
+ .refresh_turn_boundary(false)
+ .await
+ .expect("refresh empty");
+ let prepared = prelude
+ .prepare(false)
+ .await
+ .expect("prepared empty snapshot")
+ .tools
+ .expect("tool snapshot");
+ assert!(
+ prepared
+ .specs()
+ .iter()
+ .all(|spec| !crate::inference::tokenjuice::is_repl_tool(&spec.name)),
+ "an empty frozen transcript must not gain Juice declarations from the live catalog"
+ );
+}
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
index 3b106637e1..a19e1d18ad 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
@@ -189,231 +189,6 @@ fn spec(name: &str) -> ToolSpec {
}
}
-#[tokio::test]
-async fn a_resumed_thread_keeps_recorded_juice_specs_and_executors_when_repl_is_off() {
- use crate::inference::tokenjuice::{repl_tools_for, REPL_TOOL_NAMES};
-
- crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
- .expect("builtin definitions");
- let tmp = tempfile::tempdir().expect("tempdir");
- let mut active_config = crate::config::Config {
- workspace_dir: tmp.path().join("workspace"),
- action_dir: tmp.path().join("workspace"),
- config_path: tmp.path().join("config.toml"),
- ..Default::default()
- };
- std::fs::create_dir_all(&active_config.workspace_dir).expect("workspace");
- active_config.context.compaction_enabled = true;
- active_config.tokenjuice.router_enabled = true;
- active_config.tokenjuice.ccr_enabled = true;
- active_config.tokenjuice.repl_handle_enabled = true;
- let mut recorded_specs = repl_tools_for(&active_config)
- .iter()
- .map(|tool| tool.spec())
- .collect::<Vec<_>>();
- assert_eq!(
- recorded_specs
- .iter()
- .map(|spec| spec.name.as_str())
- .collect::<Vec<_>>(),
- REPL_TOOL_NAMES
- );
- for spec in &mut recorded_specs {
- spec.description = format!("frozen declaration for {}", spec.name);
- spec.parameters = serde_json::json!({"type":"object","frozen":spec.name});
- }
- let recorded = ToolSnapshot::new(recorded_specs.clone()).expect("recorded tool snapshot");
-
- // A fresh process has the same workspace but current policy no longer
- // creates new handles. The resumed thread must still regain only the
- // REPL tools it was sent, with their original declarations.
- let mut current_config = crate::config::Config {
- workspace_dir: active_config.workspace_dir.clone(),
- action_dir: active_config.action_dir.clone(),
- config_path: active_config.config_path.clone(),
- modules: crate::config::schema::ModulesConfig {
- enabled: false,
- ..Default::default()
- },
- ..Default::default()
- };
- current_config.context.compaction_enabled = false;
- current_config.tokenjuice.router_enabled = false;
- current_config.tokenjuice.ccr_enabled = false;
- current_config.tokenjuice.repl_handle_enabled = false;
- assert!(repl_tools_for(&current_config).is_empty());
- let mut host =
- crate::agent::OpenHumanSessionHost::from_config_for_agent(&current_config, "summarizer")
- .expect("summarizer session");
- host.ensure_runtime_session().expect("runtime session");
- let prelude = host
- .runtime_state
- .lock()
- .expect("runtime state")
- .prelude
- .clone()
- .expect("prelude");
-
- prelude.adopt_recorded_tools(Some(&recorded));
- assert_eq!(
- prelude
- .mutable
- .lock()
- .expect("prelude state")
- .recorded_repl_tools
- .len(),
- recorded_specs.len()
- );
- prelude.refresh_turn_boundary(false).await.expect("refresh");
- let surface_names = {
- let surface = prelude.tool_surface.lock().expect("tool surface");
- (
- surface
- .tools
- .iter()
- .map(|tool| tool.name().to_string())
- .collect::<Vec<_>>(),
- surface
- .synthesized_tools
- .iter()
- .map(|tool| tool.name().to_string())
- .collect::<Vec<_>>(),
- surface
- .visible_tool_specs
- .iter()
- .map(|spec| spec.name.clone())
- .collect::<Vec<_>>(),
- surface.visible_tool_names.clone(),
- )
- };
- let prepared = prelude.prepare(false).await.expect("prepared surface");
- let prepared = prepared.tools.expect("prepared tool snapshot");
-
- for recorded_spec in &recorded_specs {
- let prepared_spec = prepared
- .specs()
- .iter()
- .find(|spec| spec.name == recorded_spec.name)
- .unwrap_or_else(|| {
- panic!(
- "the resumed request lost {}; surface={surface_names:?}",
- recorded_spec.name
- )
- });
- assert_eq!(prepared_spec.description, recorded_spec.description);
- assert_eq!(prepared_spec.parameters, recorded_spec.parameters);
- let surface = prelude.tool_surface.lock().expect("tool surface");
- assert!(
- surface
- .tools
- .iter()
- .chain(surface.synthesized_tools.iter())
- .any(|tool| tool.name() == recorded_spec.name),
- "the recorded declaration {} needs an executor",
- recorded_spec.name
- );
- }
- let unavailable = {
- let surface = prelude.tool_surface.lock().expect("tool surface");
- let tool = surface
- .tools
- .iter()
- .chain(surface.synthesized_tools.iter())
- .find(|tool| tool.name() == "juice_find")
- .expect("recorded executor remains registered");
- tool.execute(serde_json::json!({"handle":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}))
- .await
- .expect("tool reports disabled module as a result")
- };
- assert!(
- unavailable.is_error,
- "a recorded executor must fail closed when modules are disabled: {}",
- unavailable.output()
- );
-}
-
-#[tokio::test]
-async fn resumed_juice_snapshot_does_not_add_live_repl_declarations() {
- use crate::inference::tokenjuice::{repl_tools_for, REPL_TOOL_NAMES};
-
- crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
- .expect("builtin definitions");
- let tmp = tempfile::tempdir().expect("tempdir");
- let mut config = crate::config::Config {
- workspace_dir: tmp.path().join("workspace"),
- action_dir: tmp.path().join("workspace"),
- config_path: tmp.path().join("config.toml"),
- ..Default::default()
- };
- std::fs::create_dir_all(&config.workspace_dir).expect("workspace");
- config.context.compaction_enabled = true;
- config.tokenjuice.router_enabled = true;
- config.tokenjuice.ccr_enabled = true;
- config.tokenjuice.repl_handle_enabled = true;
- let mut recorded_spec = repl_tools_for(&config)
- .into_iter()
- .find(|tool| tool.name() == REPL_TOOL_NAMES[0])
- .expect("juice_find")
- .spec();
- recorded_spec.description = "frozen juice_find declaration".into();
- recorded_spec.parameters = serde_json::json!({"type":"object","frozen":true});
- let recorded = ToolSnapshot::new(vec![recorded_spec.clone()]).expect("recorded snapshot");
-
- let mut host = crate::agent::OpenHumanSessionHost::from_config_for_agent(&config, "summarizer")
- .expect("summarizer session");
- host.ensure_runtime_session().expect("runtime session");
- let prelude = host
- .runtime_state
- .lock()
- .expect("runtime state")
- .prelude
- .clone()
- .expect("prelude");
- prelude.adopt_recorded_tools(Some(&recorded));
- prelude.refresh_turn_boundary(false).await.expect("refresh");
- let prepared = prelude
- .prepare(false)
- .await
- .expect("prepared surface")
- .tools
- .expect("tool snapshot");
-
- let juice_names = prepared
- .specs()
- .iter()
- .filter(|spec| crate::inference::tokenjuice::is_repl_tool(&spec.name))
- .map(|spec| spec.name.as_str())
- .collect::<Vec<_>>();
- assert_eq!(juice_names, [REPL_TOOL_NAMES[0]]);
- let frozen = prepared
- .specs()
- .iter()
- .find(|spec| spec.name == recorded_spec.name)
- .expect("recorded spec");
- assert_eq!(frozen.description, recorded_spec.description);
- assert_eq!(frozen.parameters, recorded_spec.parameters);
-
- let empty = ToolSnapshot::new(Vec::new()).expect("empty recorded snapshot");
- prelude.adopt_recorded_tools(Some(&empty));
- prelude
- .refresh_turn_boundary(false)
- .await
- .expect("refresh empty");
- let prepared = prelude
- .prepare(false)
- .await
- .expect("prepared empty snapshot")
- .tools
- .expect("tool snapshot");
- assert!(
- prepared
- .specs()
- .iter()
- .all(|spec| !crate::inference::tokenjuice::is_repl_tool(&spec.name)),
- "an empty frozen transcript must not gain Juice declarations from the live catalog"
- );
-}
-
#[cfg(feature = "mcp")]
#[test]
fn connected_mcp_actions_enter_search_and_leave_on_disconnect() {
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_tool_surface.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_tool_surface.rs
new file mode 100644
index 0000000000..7b8efe6cf5
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_tool_surface.rs
@@ -0,0 +1,176 @@
+//! Refresh the executable, declared and policy tool surfaces at a turn boundary.
+
+use super::*;
+
+impl OpenHumanTurnPrelude {
+ /// Rebuild every delegation-dependent tool view from the current cached
+ /// integration set, replacing rather than appending. A revoked delegate is
+ /// removed from the executable source, schema, and policy together before
+ /// this request is prepared.
+ pub(super) fn refresh_delegation_tool_surface(&self) -> anyhow::Result<()> {
+ use crate::agent::harness::definition::AgentDefinitionRegistry;
+ use crate::tools::agent_policy::ToolPolicyEngine;
+ use crate::tools::orchestrator_tools::collect_orchestrator_tools;
+
+ let Some(registry) = AgentDefinitionRegistry::current() else {
+ return Ok(());
+ };
+ let Some(definition) = self.session_definition(&registry) else {
+ return Ok(());
+ };
+ let has_recorded_tool_snapshot = self
+ .mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .recorded_tool_snapshot_adopted;
+ if definition.subagents.is_empty() && !has_recorded_tool_snapshot {
+ return Ok(());
+ }
+ let (integrations, integrations_are_authoritative, recorded_tool_snapshot_adopted) = {
+ let mutable = self
+ .mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ (
+ mutable.connected_integrations.clone(),
+ mutable.connected_integrations_authoritative,
+ mutable.recorded_tool_snapshot_adopted,
+ )
+ };
+ #[cfg(feature = "mcp")]
+ let mcp_tools = self.collect_mcp_search_tools();
+ let mut surface = self
+ .tool_surface
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ let mut collected = collect_orchestrator_tools(&definition, &registry, &integrations);
+ #[cfg(feature = "mcp")]
+ collected.extend(mcp_tools);
+ let rebuilt = self.rebuilt_recorded_tools(
+ &definition,
+ &surface.tools,
+ &collected,
+ &integrations,
+ integrations_are_authoritative,
+ );
+ collected.extend(rebuilt);
+ super::super::managed_tools::reject_synthesized_collisions(
+ &surface.permanent_tool_names,
+ &collected,
+ )?;
+ let synthesized =
+ super::super::builder::drop_synthesized_name_collisions(&surface.tools, collected);
+ let synthesized_names = synthesized
+ .iter()
+ .map(|tool| tool.name().to_string())
+ .collect::<std::collections::HashSet<_>>();
+ let previous_synthesized = std::mem::replace(
+ &mut surface.synthesized_tool_names,
+ synthesized_names.clone(),
+ );
+ let auto_include_new_synthesized_tools = surface.auto_include_new_synthesized_tools;
+ reconcile_synthesized_visibility(
+ &mut surface.visible_tool_names,
+ &previous_synthesized,
+ &synthesized_names,
+ auto_include_new_synthesized_tools,
+ );
+ if recorded_tool_snapshot_adopted {
+ surface.visible_tool_names.extend(
+ self.mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .recorded_repl_tools
+ .iter()
+ .map(|spec| spec.name.clone()),
+ );
+ }
+ // Preserve permanently attached tools when re-deriving the surface.
+ permanent::refresh_visibility(&mut surface, &synthesized);
+
+ let mut specs = surface
+ .durable_tool_specs
+ .iter()
+ .cloned()
+ .chain(synthesized.iter().map(|tool| Arc::new(tool.spec())))
+ .collect::<Vec<_>>();
+ {
+ let recorded = self
+ .mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .recorded_repl_tools
+ .clone();
+ let recorded_names = recorded
+ .iter()
+ .map(|spec| spec.name.as_str())
+ .collect::<std::collections::HashSet<_>>();
+ if recorded_tool_snapshot_adopted {
+ specs.retain(|spec| {
+ !crate::inference::tokenjuice::is_repl_tool(&spec.name)
+ || recorded_names.contains(spec.name.as_str())
+ });
+ surface.visible_tool_names.retain(|name| {
+ !crate::inference::tokenjuice::is_repl_tool(name)
+ || recorded_names.contains(name.as_str())
+ });
+ }
+ let recorded = recorded
+ .iter()
+ .map(|spec| (spec.name.as_str(), spec))
+ .collect::<std::collections::HashMap<_, _>>();
+ for spec in &mut specs {
+ if let Some(frozen) = recorded.get(spec.name.as_str()) {
+ *spec = Arc::new((*frozen).clone());
+ }
+ }
+ }
+ let synthesized_tools = Arc::new(synthesized);
+ crate::tools::toolpacks::bind_synthesized_pack_registry(&surface.tools, &synthesized_tools);
+ let all_tools = surface
+ .tools
+ .iter()
+ .chain(synthesized_tools.iter())
+ .map(|tool| tool.as_ref())
+ .collect::<Vec<_>>();
+ // Advertised plus deferred, like the session host: a deferred tool
+ // outside the set would be `HideFromPrompt`, which the direct-call
+ // gate refuses.
+ let reachable: std::collections::HashSet<String> = if surface.visible_tool_names.is_empty()
+ {
+ std::collections::HashSet::new()
+ } else {
+ surface
+ .visible_tool_names
+ .iter()
+ .chain(surface.deferred_tool_names.iter())
+ .cloned()
+ .collect()
+ };
+ let mut policy = ToolPolicyEngine::build_session_from_refs(
+ &surface.agent_definition_name,
+ &surface.event_channel,
+ "session",
+ &self.config.channel_permissions,
+ &all_tools,
+ &reachable,
+ );
+ crate::tools::toolpacks::close_handed_off_packs(
+ &mut policy,
+ &surface.agent_definition_name,
+ &all_tools,
+ );
+ let visible = super::super::builder::dedup_visible_tool_specs(
+ super::super::builder::visible_tool_specs_for_policy(
+ &specs,
+ &surface.visible_tool_names,
+ &policy,
+ ),
+ );
+ surface.tool_specs = Arc::new(specs);
+ surface.synthesized_tools = synthesized_tools;
+ surface.visible_tool_specs = Arc::new(visible);
+ surface.tool_policy_session = policy;
+ Ok(())
+ }
+}
diff --git a/docs/module-boundary-inventory.md b/docs/module-boundary-inventory.md
index a2d6b858dc..e9caf2c3b7 100644
--- a/docs/module-boundary-inventory.md
+++ b/docs/module-boundary-inventory.md
@@ -222,11 +222,14 @@ and verified against both published checksums and GitHub asset digests. The
source pin is `b89632a8f7b96580a9f6718d185eb60b14a41a8a`; HTML and query
adapters now use the module. The isolated `module-tinyjuice-host` checkout owns
the turn-bound summary callback registry using the existing callback DTO.
-All 54 current TokenJuice tests pass with the released native library configured
-through OpenHuman's pinned loader, including cached-handle queries,
-supplied-content queries and HTML extraction. The library checks pass both
-without the loader and with the repository-pinned Rust compiler. Recorded
-TinyJuice tool restoration is still under regression testing.
+All 66 Juice tests pass with the released native library configured through
+OpenHuman's pinned loader, including cached-handle queries, supplied-content
+queries, HTML extraction and resumed frozen tool declarations. Resume retains
+recorded executors when current REPL flags are off, preserves the recorded
+schemas verbatim, and does not add live declarations to a frozen subset or
+empty snapshot. Disabled module loading still fails the retained executor
+explicitly. The library checks pass both without the loader and with the
+repository-pinned Rust compiler.
The TinyJuice cut removes its host implementation exception. The transitional
audit now reports zero violations, zero stale exceptions, 30 remaining temporary
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index e59d2e4094..da6ec3c20b 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -40,7 +40,7 @@ const LEGACY_LIMIT_ENTRIES = [
// under the general 750 limit, so it needs no exception at all.
// The session-todo integration added transcript metadata construction to
// this already-exempt composition seam. Keep its allowance exact.
- ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1293],
+ ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1184],
// Session-host factory still assembles the product's deliberately coupled
// provider, security, memory, tool and prompt policy. Generic session
// state moved to tinyagents-runtime; this remaining composition is split in