Skip to content

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

fix(session): handle missing prelude integrations gracefully

Steven Enamakel1a9e4b709f4e
diff --git a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
index 0e455363a7..80234375f4 100644
--- a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
+++ b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
@@ -23,10 +23,13 @@ impl OpenHumanTurnPrelude {
actions.len(),
self.agent_definition_id
);
- self.mutable
+ let search_tools = super::super::recorded_tools::recorded_search_tools(recorded.specs());
+ let mut mutable = self
+ .mutable
.lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .recorded_integration_actions = actions;
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ mutable.recorded_integration_actions = actions;
+ mutable.recorded_search_tools = search_tools;
}
pub(super) async fn refresh_turn_boundary(&self, cold: bool) {
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
index 20d7c0de4f..78667de874 100644
--- a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
@@ -101,6 +101,55 @@ pub(super) fn rehydrate_integration_actions(
.collect()
}
+/// The recorded TinySearch role tools (`web_search_tool`, `web_answer_tool`,
+/// `web_contents_tool`), in recorded order.
+pub(super) fn recorded_search_tools(recorded: &[ToolSpec]) -> Vec<ToolSpec> {
+ recorded
+ .iter()
+ .filter(|spec| is_search_role_tool(&spec.name))
+ .cloned()
+ .collect()
+}
+
+fn is_search_role_tool(name: &str) -> bool {
+ [
+ tinysearch_bus::Role::Search,
+ tinysearch_bus::Role::Answer,
+ tinysearch_bus::Role::Contents,
+ ]
+ .into_iter()
+ .any(|role| tinysearch_bus::role_tool_name(role) == name)
+}
+
+/// Executors for recorded search role tools the live surface no longer
+/// builds (the user signed out, or turned a provider off). Each keeps its
+/// recorded declaration and resolves the live config per call, so a call
+/// answers with the actionable "no usable provider" error instead of an
+/// unknown-tool failure.
+#[cfg(feature = "modules")]
+pub(super) fn rehydrate_search_tools(
+ recorded: &[ToolSpec],
+ live: &[Box<dyn Tool>],
+) -> Vec<Box<dyn Tool>> {
+ let live_names: HashSet<&str> = live.iter().map(|tool| tool.name()).collect();
+ let mut seen = HashSet::new();
+ recorded
+ .iter()
+ .filter(|spec| is_search_role_tool(&spec.name))
+ .filter(|spec| !live_names.contains(spec.name.as_str()))
+ .filter(|spec| seen.insert(spec.name.clone()))
+ .map(|spec| {
+ Box::new(crate::search::TinySearchTool::recorded(
+ tinysearch_bus::ToolSpec {
+ name: spec.name.clone(),
+ description: spec.description.clone(),
+ parameters: spec.parameters.clone(),
+ },
+ )) as Box<dyn Tool>
+ })
+ .collect()
+}
+
#[cfg(test)]
#[path = "recorded_tools_tests.rs"]
mod tests;
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 819cf51b48..6a0d5b11b0 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -159,6 +159,9 @@ struct OpenHumanTurnPreludeMutable {
/// executors whenever the live integrations list does not supply them
/// (see `recorded_tools`).
recorded_integration_actions: Vec<tinytools::ToolSpec>,
+ /// Search role tools the resumed thread was sent (see
+ /// `recorded_tools::rehydrate_search_tools`).
+ recorded_search_tools: Vec<tinytools::ToolSpec>,
workflows: Vec<crate::skills::Workflow>,
composio_events: Option<tinybus::events::EventReceiver<crate::core::events::DomainEvent>>,
skill_events: Option<tinybus::events::EventReceiver<crate::core::events::DomainEvent>>,
@@ -478,6 +481,33 @@ impl OpenHumanTurnPrelude {
collected.extend(rebuilt);
}
}
+ #[cfg(feature = "modules")]
+ {
+ let recorded = self
+ .mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .recorded_search_tools
+ .clone();
+ let mut present: Vec<&dyn tinytools::Tool> =
+ surface.tools.iter().map(|tool| tool.as_ref()).collect();
+ present.extend(collected.iter().map(|tool| tool.as_ref()));
+ let present_names: std::collections::HashSet<String> =
+ present.iter().map(|tool| tool.name().to_string()).collect();
+ let missing: Vec<tinytools::ToolSpec> = recorded
+ .into_iter()
+ .filter(|spec| !present_names.contains(&spec.name))
+ .collect();
+ let rebuilt = super::recorded_tools::rehydrate_search_tools(&missing, &[]);
+ if !rebuilt.is_empty() {
+ log::info!(
+ "[session] rebuilt {} recorded search tool(s) the live surface did not supply agent={}",
+ rebuilt.len(),
+ self.agent_definition_id
+ );
+ collected.extend(rebuilt);
+ }
+ }
let synthesized =
super::builder::drop_synthesized_name_collisions(&surface.tools, collected);
let synthesized_names = synthesized
@@ -1570,6 +1600,7 @@ impl OpenHumanSessionHost {
// this session's current authorization refresh.
connected_integrations_authoritative: false,
recorded_integration_actions: Vec::new(),
+ recorded_search_tools: Vec::new(),
workflows: self.workflows.clone(),
composio_events: None,
skill_events: None,