Skip to content

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

fix(web_chat): handle missing memory guard in start chat

Steven Enamakel69165f29990a
diff --git a/crates/openhuman-core/src/memory/guard/test_support/core_and_docs_impls.rs b/crates/openhuman-core/src/memory/guard/test_support/core_and_docs_impls.rs
new file mode 100644
index 0000000000..e1605c6866
--- /dev/null
+++ b/crates/openhuman-core/src/memory/guard/test_support/core_and_docs_impls.rs
@@ -0,0 +1,541 @@
+//! `RecordingProvider`'s `Core`, `Recall`, `Portability`, `Ingest`,
+//! `Documents`, `Tree`, `Entities`, `Graph`, `Diff`, `Goals`, and
+//! `ToolMemory` family implementations — the write/tree/graph half.
+//!
+//! Split out of the original `test_support.rs`; see [`super::fixtures`] for
+//! `RecordingProvider`'s type and constructors.
+
+use crate::memory::api::chunks::Chunk;
+use crate::memory::api::error::MemoryError;
+use crate::memory::api::goals::GoalsDoc;
+use crate::memory::api::provider::types::{
+ DiffReport, EntityHit, ExportPage, ImportOutcome, IngestItem, IngestOutcome, SnapshotRef,
+ SourceScope,
+};
+use crate::memory::api::provider::{
+ MemoryCore, MemoryDiff, MemoryDocuments, MemoryEntities, MemoryGoals, MemoryGraph,
+ MemoryIngest, MemoryPortability, MemoryProvider, MemoryRecall, MemoryToolMemory, MemoryTree,
+};
+use crate::memory::api::recall::OwnedRecallOpts;
+use crate::memory::api::tool_memory::ToolMemoryRule;
+use crate::memory::api::tree::{IngestRequest, QueryResult, TreeStatus};
+use crate::memory::api::types::{
+ ExportRecord, GraphRelationRecord, MemoryCategory, MemoryEntry, MemoryKvRecord, MemoryTaint,
+ NamespaceDocumentInput, NamespaceRetrievalContext, NamespaceSummary, StoredMemoryDocument,
+};
+use async_trait::async_trait;
+
+use super::fixtures::{Call, RecordingProvider};
+
+/// A [`TreeStatus`] fixture.
+fn tree_status(namespace: &str) -> TreeStatus {
+ TreeStatus {
+ namespace: namespace.to_string(),
+ total_nodes: 0,
+ depth: 0,
+ oldest_entry: None,
+ newest_entry: None,
+ last_run_at: None,
+ }
+}
+
+impl MemoryCore for RecordingProvider {
+ async fn store(
+ &self,
+ _namespace: &str,
+ _key: &str,
+ content: &str,
+ _category: MemoryCategory,
+ _session_id: Option<&str>,
+ taint: MemoryTaint,
+ ) -> Result<(), MemoryError> {
+ self.record(Call {
+ method: "core.store".into(),
+ content: Some(content.to_string()),
+ taint: Some(taint),
+ scoped: None,
+ });
+ Ok(())
+ }
+
+ async fn get(&self, _namespace: &str, _key: &str) -> Result<Option<MemoryEntry>, MemoryError> {
+ self.record(Call::plain("core.get"));
+ Ok(None)
+ }
+
+ async fn forget(&self, _namespace: &str, _key: &str) -> Result<bool, MemoryError> {
+ self.record(Call::plain("core.forget"));
+ Ok(false)
+ }
+
+ async fn list(
+ &self,
+ _namespace: Option<&str>,
+ _category: Option<&MemoryCategory>,
+ _session_id: Option<&str>,
+ ) -> Result<Vec<MemoryEntry>, MemoryError> {
+ self.record(Call::plain("core.list"));
+ Ok(vec![])
+ }
+
+ async fn namespaces(&self) -> Result<Vec<NamespaceSummary>, MemoryError> {
+ self.record(Call::plain("core.namespaces"));
+ Ok(self.namespace_summaries.lock().unwrap().clone())
+ }
+}
+
+#[async_trait]
+impl MemoryRecall for RecordingProvider {
+ async fn recall(
+ &self,
+ query: &str,
+ _limit: usize,
+ _opts: &OwnedRecallOpts,
+ scope: Option<&SourceScope>,
+ ) -> Result<Vec<MemoryEntry>, MemoryError> {
+ self.record(Call {
+ method: "recall.recall".into(),
+ content: Some(query.to_string()),
+ taint: None,
+ scoped: Some(scope.is_some()),
+ });
+ Ok(self.recall_result.lock().unwrap().clone())
+ }
+}
+
+#[async_trait]
+impl MemoryPortability for RecordingProvider {
+ async fn export_page(
+ &self,
+ _cursor: Option<&str>,
+ _limit: usize,
+ ) -> Result<ExportPage, MemoryError> {
+ self.record(Call::plain("portability.export_page"));
+ Ok(ExportPage::default())
+ }
+
+ async fn import_records(
+ &self,
+ records: Vec<ExportRecord>,
+ ) -> Result<ImportOutcome, MemoryError> {
+ self.record(Call {
+ method: "portability.import_records".into(),
+ content: None,
+ taint: records.first().map(|r| r.taint),
+ scoped: None,
+ });
+ Ok(ImportOutcome::default())
+ }
+}
+
+#[async_trait]
+impl MemoryIngest for RecordingProvider {
+ async fn ingest_document(&self, item: IngestItem) -> Result<IngestOutcome, MemoryError> {
+ self.record(Call {
+ method: "ingest.ingest_document".into(),
+ content: Some(item.content),
+ taint: Some(item.taint),
+ scoped: None,
+ });
+ Ok(IngestOutcome::default())
+ }
+
+ async fn ingest_chat(&self, messages: Vec<IngestItem>) -> Result<IngestOutcome, MemoryError> {
+ self.record(Call {
+ method: "ingest.ingest_chat".into(),
+ content: messages.first().map(|m| m.content.clone()),
+ taint: messages.first().map(|m| m.taint),
+ scoped: None,
+ });
+ Ok(IngestOutcome::default())
+ }
+}
+
+#[async_trait]
+impl MemoryDocuments for RecordingProvider {
+ async fn put_document(&self, input: NamespaceDocumentInput) -> Result<String, MemoryError> {
+ self.record(Call {
+ method: "documents.put_document".into(),
+ content: Some(input.content),
+ taint: Some(input.taint),
+ scoped: None,
+ });
+ Ok("doc".into())
+ }
+
+ async fn get_document(
+ &self,
+ _namespace: &str,
+ _key: &str,
+ ) -> Result<Option<StoredMemoryDocument>, MemoryError> {
+ self.record(Call::plain("documents.get_document"));
+ Ok(None)
+ }
+
+ async fn list_documents(
+ &self,
+ _namespace: Option<&str>,
+ ) -> Result<serde_json::Value, MemoryError> {
+ self.record(Call::plain("documents.list_documents"));
+ Ok(serde_json::json!({"documents": []}))
+ }
+
+ async fn list_namespaces(&self) -> Result<Vec<String>, MemoryError> {
+ self.record(Call::plain("documents.list_namespaces"));
+ Ok(vec![])
+ }
+
+ async fn delete_document(
+ &self,
+ _namespace: &str,
+ _document_id: &str,
+ ) -> Result<serde_json::Value, MemoryError> {
+ self.record(Call::plain("documents.delete_document"));
+ Ok(serde_json::json!({"deleted": false}))
+ }
+
+ async fn clear_namespace(&self, _namespace: &str) -> Result<(), MemoryError> {
+ self.record(Call::plain("documents.clear_namespace"));
+ Ok(())
+ }
+
+ async fn query_documents(
+ &self,
+ namespace: &str,
+ query: &str,
+ _limit: usize,
+ ) -> Result<NamespaceRetrievalContext, MemoryError> {
+ self.record(Call {
+ method: "documents.query_documents".into(),
+ content: Some(query.to_string()),
+ taint: None,
+ scoped: None,
+ });
+ Ok(NamespaceRetrievalContext {
+ namespace: namespace.to_string(),
+ query: Some(query.to_string()),
+ context_text: String::new(),
+ hits: vec![],
+ })
+ }
+
+ async fn recall_documents(
+ &self,
+ namespace: &str,
+ _limit: usize,
+ ) -> Result<NamespaceRetrievalContext, MemoryError> {
+ self.record(Call::plain("documents.recall_documents"));
+ Ok(NamespaceRetrievalContext {
+ namespace: namespace.to_string(),
+ query: None,
+ context_text: String::new(),
+ hits: vec![],
+ })
+ }
+}
+
+#[async_trait]
+impl MemoryTree for RecordingProvider {
+ async fn append(&self, request: IngestRequest) -> Result<(), MemoryError> {
+ self.record(Call {
+ method: "tree.append".into(),
+ content: Some(request.content),
+ taint: None,
+ scoped: None,
+ });
+ Ok(())
+ }
+
+ async fn query_source(
+ &self,
+ _namespace: &str,
+ _source_id: &str,
+ _limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<Vec<Chunk>, MemoryError> {
+ self.record(Call {
+ method: "tree.query_source".into(),
+ // The scope's allow list, rendered so a test can assert which one
+ // arrived. Sorted because it comes from a `HashSet`.
+ content: scope.map(|s| {
+ let mut allow = s.allow.clone();
+ allow.sort();
+ allow.join(",")
+ }),
+ taint: None,
+ scoped: Some(scope.is_some()),
+ });
+ Ok(vec![])
+ }
+
+ async fn drill_down(
+ &self,
+ _namespace: &str,
+ _node_id: &str,
+ ) -> Result<QueryResult, MemoryError> {
+ self.record(Call::plain("tree.drill_down"));
+ Err(MemoryError::NotFound("node".into()))
+ }
+
+ async fn seal(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.record(Call::plain("tree.seal"));
+ Ok(tree_status(namespace))
+ }
+
+ async fn cascade(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.record(Call::plain("tree.cascade"));
+ Ok(tree_status(namespace))
+ }
+
+ /// Records the folded bodies as one blob, so a redaction test can assert on
+ /// what the driver's summariser would have been handed.
+ async fn summarise(
+ &self,
+ inputs: &[crate::memory::api::provider::content::SummaryInput],
+ _context: &crate::memory::api::provider::content::SummaryContext,
+ ) -> Result<crate::memory::api::provider::content::SummaryOutput, MemoryError> {
+ self.record(Call {
+ method: "tree.summarise".into(),
+ content: Some(
+ inputs
+ .iter()
+ .map(|input| input.content.clone())
+ .collect::<Vec<_>>()
+ .join("|"),
+ ),
+ taint: None,
+ scoped: None,
+ });
+ Ok(Default::default())
+ }
+
+ async fn root_summaries_with_caps(
+ &self,
+ _per_namespace_cap: usize,
+ _total_cap: usize,
+ ) -> Result<Vec<crate::memory::api::provider::content::RootSummary>, MemoryError>
+ {
+ self.record(Call::plain("tree.root_summaries_with_caps"));
+ Ok(Vec::new())
+ }
+
+ // ── The runtime-tree and flavour doors ──────────────────────────────────
+ //
+ // Overridden for the same reason `summarise` and `root_summaries_with_caps`
+ // are: each is defaulted on the trait, so a `GuardedTree` that forgot to
+ // forward one still compiles and answers `Unsupported`. A driver that
+ // *succeeds* here is what makes `the_defaulted_doors_are_forwarded_rather_than_refused`
+ // able to tell the two apart.
+
+ /// Records the buffered body, so a redaction test can assert what the
+ /// driver's buffer would have been handed — [`Self::append`]'s twin.
+ async fn runtime_buffer_write(
+ &self,
+ _namespace: &str,
+ content: &str,
+ _timestamp: chrono::DateTime<chrono::Utc>,
+ _metadata: Option<serde_json::Value>,
+ ) -> Result<String, MemoryError> {
+ self.record(Call {
+ method: "tree.runtime_buffer_write".into(),
+ content: Some(content.to_string()),
+ taint: None,
+ scoped: None,
+ });
+ Ok("/buffer/2026/01/01/00.md".to_string())
+ }
+
+ async fn runtime_read_node(
+ &self,
+ _namespace: &str,
+ _node_id: &str,
+ ) -> Result<Option<crate::memory::api::tree::TreeNode>, MemoryError> {
+ self.record(Call::plain("tree.runtime_read_node"));
+ Ok(None)
+ }
+
+ async fn runtime_read_children(
+ &self,
+ _namespace: &str,
+ _parent_id: &str,
+ ) -> Result<Vec<crate::memory::api::tree::TreeNode>, MemoryError> {
+ self.record(Call::plain("tree.runtime_read_children"));
+ Ok(Vec::new())
+ }
+
+ async fn runtime_tree_status(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.record(Call::plain("tree.runtime_tree_status"));
+ Ok(tree_status(namespace))
+ }
+
+ async fn runtime_summarize(
+ &self,
+ _namespace: &str,
+ _timestamp: chrono::DateTime<chrono::Utc>,
+ ) -> Result<Option<crate::memory::api::tree::TreeNode>, MemoryError> {
+ self.record(Call::plain("tree.runtime_summarize"));
+ Ok(None)
+ }
+
+ async fn runtime_rebuild(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.record(Call::plain("tree.runtime_rebuild"));
+ Ok(tree_status(namespace))
+ }
+
+ async fn flavour_profile(&self, _scope: &str) -> Result<Option<String>, MemoryError> {
+ self.record(Call::plain("tree.flavour_profile"));
+ Ok(None)
+ }
+}
+
+#[async_trait]
+impl MemoryEntities for RecordingProvider {
+ async fn entities(
+ &self,
+ _namespace: &str,
+ _query: Option<&str>,
+ _limit: usize,
+ ) -> Result<Vec<EntityHit>, MemoryError> {
+ self.record(Call::plain("entities.entities"));
+ Ok(vec![])
+ }
+
+ async fn entity_edges(
+ &self,
+ _namespace: &str,
+ _entity_id: &str,
+ _limit: usize,
+ ) -> Result<Vec<GraphRelationRecord>, MemoryError> {
+ self.record(Call::plain("entities.entity_edges"));
+ Ok(vec![])
+ }
+
+ async fn touch_entities(
+ &self,
+ _namespace: &str,
+ _entity_ids: &[String],
+ ) -> Result<(), MemoryError> {
+ self.record(Call::plain("entities.touch_entities"));
+ Ok(())
+ }
+}
+
+#[async_trait]
+impl MemoryGraph for RecordingProvider {
+ async fn kv_get(
+ &self,
+ _namespace: Option<&str>,
+ _key: &str,
+ ) -> Result<Option<MemoryKvRecord>, MemoryError> {
+ self.record(Call::plain("graph.kv_get"));
+ Ok(None)
+ }
+
+ async fn kv_put(
+ &self,
+ _namespace: Option<&str>,
+ _key: &str,
+ value: serde_json::Value,
+ ) -> Result<(), MemoryError> {
+ self.record(Call {
+ method: "graph.kv_put".into(),
+ content: Some(value.to_string()),
+ taint: None,
+ scoped: None,
+ });
+ Ok(())
+ }
+
+ async fn kv_delete(&self, _namespace: Option<&str>, _key: &str) -> Result<bool, MemoryError> {
+ self.record(Call::plain("graph.kv_delete"));
+ Ok(false)
+ }
+
+ async fn kv_list(
+ &self,
+ _namespace: Option<&str>,
+ _prefix: Option<&str>,
+ _limit: usize,
+ ) -> Result<Vec<MemoryKvRecord>, MemoryError> {
+ self.record(Call::plain("graph.kv_list"));
+ Ok(vec![])
+ }
+
+ async fn relations(
+ &self,
+ _namespace: Option<&str>,
+ _subject: Option<&str>,
+ _predicate: Option<&str>,
+ _limit: usize,
+ ) -> Result<Vec<GraphRelationRecord>, MemoryError> {
+ self.record(Call::plain("graph.relations"));
+ Ok(vec![])
+ }
+
+ async fn put_relation(&self, _relation: GraphRelationRecord) -> Result<(), MemoryError> {
+ self.record(Call::plain("graph.put_relation"));
+ Ok(())
+ }
+}
+
+#[async_trait]
+impl MemoryDiff for RecordingProvider {
+ async fn capture_snapshot(&self, _source_id: &str) -> Result<SnapshotRef, MemoryError> {
+ self.record(Call::plain("diff.capture_snapshot"));
+ Err(MemoryError::NotFound("source".into()))
+ }
+
+ async fn snapshots(
+ &self,
+ _source_id: &str,
+ _limit: usize,
+ ) -> Result<Vec<SnapshotRef>, MemoryError> {
+ self.record(Call::plain("diff.snapshots"));
+ Ok(vec![])
+ }
+
+ async fn diff(
+ &self,
+ _source_id: &str,
+ _from: Option<&str>,
+ _to: &str,
+ ) -> Result<DiffReport, MemoryError> {
+ self.record(Call::plain("diff.diff"));
+ Err(MemoryError::NotFound("snapshot".into()))
+ }
+}
+
+#[async_trait]
+impl MemoryGoals for RecordingProvider {
+ async fn goals(&self) -> Result<GoalsDoc, MemoryError> {
+ self.record(Call::plain("goals.goals"));
+ Ok(GoalsDoc::default())
+ }
+
+ async fn set_goals(&self, _goals: GoalsDoc) -> Result<(), MemoryError> {
+ self.record(Call::plain("goals.set_goals"));
+ Ok(())
+ }
+}
+
+#[async_trait]
+impl MemoryToolMemory for RecordingProvider {
+ async fn tool_rules(&self, _tool_name: &str) -> Result<Vec<ToolMemoryRule>, MemoryError> {
+ self.record(Call::plain("tool_memory.tool_rules"));
+ Ok(vec![])
+ }
+
+ async fn put_tool_rule(&self, _rule: ToolMemoryRule) -> Result<(), MemoryError> {
+ self.record(Call::plain("tool_memory.put_tool_rule"));
+ Ok(())
+ }
+
+ async fn delete_tool_rule(
+ &self,
+ _tool_name: &str,
+ _rule_id: &str,
+ ) -> Result<bool, MemoryError> {
+ self.record(Call::plain("tool_memory.delete_tool_rule"));
+ Ok(false)
+ }
+}
diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
index a4681eb908..0c1e1430f0 100644
--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs
+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
@@ -524,7 +524,7 @@ pub async fn start_chat(
let mut in_flight = IN_FLIGHT.lock().await;
in_flight.insert(
map_key,
- crate::web_chat::types::InFlightEntry {
+ InFlightEntry {
request_id: request_id.clone(),
handle,
run_queue: turn_run_queue,