The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(memory): store only what a person sent as a conversation memory
yh928fd4c47f3d3a9
diff --git a/src/openhuman/agent/agent_tests.rs b/src/openhuman/agent/agent_tests.rsindex 6f8abd0d9a..a3c32970b5 100644--- a/src/openhuman/agent/agent_tests.rs+++ b/src/openhuman/agent/agent_tests.rs@@ -349,3 +349,5 @@ fn xml_tool_response(name: &str, args: &str) -> ChatResponse {mod part_01_tests;#[path = "agent_tests_part_02_tests.rs"]mod part_02_tests;+#[path = "agent_tests_part_03_tests.rs"]+mod part_03_tests;diff --git a/src/openhuman/agent/agent_tests_part_01_tests.rs b/src/openhuman/agent/agent_tests_part_01_tests.rsindex 9e35bf5b58..6f6f10d137 100644--- a/src/openhuman/agent/agent_tests_part_01_tests.rs+++ b/src/openhuman/agent/agent_tests_part_01_tests.rs@@ -320,7 +320,20 @@ async fn auto_save_stores_messages_in_memory() {true, // auto_save enabled);- let _ = agent.turn("Remember this fact").await.unwrap();+ // Scoped like a real chat turn. The autosave only stores what a person sent+ // (`turn_origin::current_is_user_authored`), and production entry points+ // scope an origin — web chat `WebChat`, channels `ExternalChannel` — so a+ // test that skipped it would be asserting a shape no caller produces.+ let _ = crate::openhuman::agent::turn_origin::with_origin(+ crate::openhuman::agent::turn_origin::AgentTurnOrigin::WebChat {+ thread_id: "t-autosave".into(),+ client_id: "c-autosave".into(),+ request_id: None,+ },+ agent.turn("Remember this fact"),+ )+ .await+ .unwrap();// Both user message and assistant response should be saved. The assistant// reply is persisted synchronously, but the user message is saveddiff --git a/src/openhuman/agent/agent_tests_part_03_tests.rs b/src/openhuman/agent/agent_tests_part_03_tests.rsnew file mode 100644index 0000000000..56dacb4898--- /dev/null+++ b/src/openhuman/agent/agent_tests_part_03_tests.rs@@ -0,0 +1,152 @@+use super::*;++// Origin-gated conversation autosave (#5312).+//+// `turn()` stores the user message only when the turn's text was written by a+// person — `turn_origin::current_is_user_authored`. These cover both directions+// of that allowlist: the two user-authored origins that were not already pinned+// by the `WebChat` case in part 01, and the two host-written ones that must not+// reach the user's conversation memory.++/// Poll for a `user_msg:` conversation memory over the same one-second window+/// the positive autosave test uses, and report whether one ever landed.+///+/// The user message is stored fire-and-forget (`tokio::spawn` in+/// `turn/core.rs`, #3610), so both directions need the *same* window or the+/// negative tests are the weaker assertion: a broken guard whose spawned store+/// lands after a short fixed sleep would pass them while failing in production.+/// Returns as soon as one appears, so a genuinely broken guard fails fast+/// instead of costing the full second.+async fn poll_for_stored_user_message(mem: &Arc<dyn Memory>) -> Vec<String> {+ let mut keys: Vec<String> = Vec::new();+ for _ in 0..50 {+ keys = mem+ .list(None, None, None)+ .await+ .expect(+ "memory list must succeed; an empty list here would let the \+ autosave assertions below pass without reading storage",+ )+ .into_iter()+ .map(|e| e.key)+ .collect();+ if keys.iter().any(|k| k.starts_with("user_msg:")) {+ break;+ }+ tokio::time::sleep(std::time::Duration::from_millis(20)).await;+ }+ keys+}++/// `ExternalChannel` is in the user-authored allowlist alongside `WebChat`, so+/// it needs its own positive case: a Telegram/Discord/Slack message is a person+/// talking, and the allowlist would be half-tested if only the web thread had a+/// stored-message assertion.+#[tokio::test]+async fn an_external_channel_turn_stores_the_user_message() {+ use crate::openhuman::agent::turn_origin::{with_origin, AgentTurnOrigin};++ let (mem, _tmp) = make_sqlite_memory();+ let provider = Arc::new(ScriptedProvider::new(vec![text_response("got it")]));+ let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);++ let origin = AgentTurnOrigin::ExternalChannel {+ channel: "telegram".into(),+ sender: Some("user-42".into()),+ reply_target: "chat-7".into(),+ message_id: "m-1".into(),+ };+ let _ = with_origin(origin, agent.turn("remember my flight is at nine"))+ .await+ .unwrap();++ let keys = poll_for_stored_user_message(&mem).await;+ assert!(+ keys.iter().any(|k| k.starts_with("user_msg:")),+ "a channel message is a person talking and must be stored: {keys:?}"+ );+}++/// The desktop Settings agent-chat panel calls `openhuman.agent_chat`, which+/// scopes `DirectChat`. That is a person typing, so it stores — the origin+/// exists precisely because `Cli` (its previous label, chosen for the approval+/// gate) would have dropped these messages.+#[tokio::test]+async fn a_direct_chat_turn_stores_the_user_message() {+ use crate::openhuman::agent::turn_origin::{with_origin, AgentTurnOrigin};++ let (mem, _tmp) = make_sqlite_memory();+ let provider = Arc::new(ScriptedProvider::new(vec![text_response("noted")]));+ let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);++ let _ = with_origin(+ AgentTurnOrigin::DirectChat,+ agent.turn("my dog is called Pip"),+ )+ .await+ .unwrap();++ let keys = poll_for_stored_user_message(&mem).await;+ assert!(+ keys.iter().any(|k| k.starts_with("user_msg:")),+ "a direct-chat message is a person typing and must be stored: {keys:?}"+ );+}+++/// An internal agent runs on the same config as the chat, so it inherits+/// `auto_save` — but its "user message" is the prompt the host wrote for it.+/// Storing that as a conversation memory puts prompt boilerplate where the+/// user's own words belong, and it competes for slots in every later recall+/// (#5312). A `TrustedAutomation` turn therefore saves nothing.+#[tokio::test]+async fn an_automation_turn_does_not_store_its_prompt_as_the_users_memory() {+ use crate::openhuman::agent::turn_origin::{+ with_origin, AgentTurnOrigin, TrustedAutomationSource,+ };++ let (mem, _tmp) = make_sqlite_memory();+ let provider = Arc::new(ScriptedProvider::new(vec![text_response("goals updated")]));+ let (mut agent, _tmp2) = build_agent_with_memory(+ provider,+ vec![],+ mem.clone(),+ true, // auto_save enabled, exactly as a config-built internal agent gets it+ );++ let origin = AgentTurnOrigin::TrustedAutomation {+ job_id: "memory_goals:enrich:1".into(),+ source: TrustedAutomationSource::Subconscious,+ };+ let _ = with_origin(origin, agent.turn("Maintain the existing goals list."))+ .await+ .unwrap();++ // The fire-and-forget store would land shortly after the turn returns, so+ // give it the same one-second window the positive tests poll for before+ // concluding it never happened.+ let keys = poll_for_stored_user_message(&mem).await;+ assert!(+ !keys.iter().any(|k| k.starts_with("user_msg:")),+ "an automation prompt must not be stored as a user message: {keys:?}"+ );+}++/// An unscoped turn is not a user turn either. `turn_origin` documents that+/// every entry point scopes an origin and that an unlabelled one fails closed;+/// the autosave follows the same allowlist, so a caller that forgets cannot+/// quietly write host text into the user's memory.+#[tokio::test]+async fn an_unscoped_turn_stores_no_user_message() {+ let (mem, _tmp) = make_sqlite_memory();+ let provider = Arc::new(ScriptedProvider::new(vec![text_response("ok")]));+ let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);++ let _ = agent.turn("who wrote this?").await.unwrap();++ let keys = poll_for_stored_user_message(&mem).await;+ assert!(+ !keys.iter().any(|k| k.starts_with("user_msg:")),+ "an unscoped turn must not be credited to the user: {keys:?}"+ );+}diff --git a/src/openhuman/agent/harness/session/turn/core_turn.rs b/src/openhuman/agent/harness/session/turn/core_turn.rsindex b5747b5c01..312e044459 100644--- a/src/openhuman/agent/harness/session/turn/core_turn.rs+++ b/src/openhuman/agent/harness/session/turn/core_turn.rs@@ -224,7 +224,22 @@ impl Agent {);}- if self.auto_save {+ // `auto_save` says the workspace keeps its chat in memory; the origin says+ // whether this turn is chat at all. An internal agent is built from the+ // same config (`Agent::from_config_for_agent`), so it inherits the flag —+ // and its "user message" is the prompt the host wrote for it, not+ // anything the user said. Live, that stored `memory_goals::enrich`'s+ // prompt as a `Conversation` document keyed `user_msg:…`, where it then+ // competed for slots in every later recall (#5312). Gating here rather+ // than at each caller keeps a new internal agent from having to remember+ // to opt out, which is a thing nobody notices forgetting.+ //+ // Upstream of the same-session exclusion filter `main` added alongside+ // `CONVERSATION_RAW_NAMESPACE`: that filter stops this document echoing+ // back inside the turn that wrote it, but a host-written prompt stored+ // here still surfaces in a *later* session's recall. This gate is what+ // keeps it from being written at all.+ if self.auto_save && crate::openhuman::agent::turn_origin::current_is_user_authored() {// Fire-and-forget: persisting the user message to the memory store// does an embedding round-trip (Voyage) + memory-tree write that the// in-flight turn never reads back. Awaiting it delayed the start ofdiff --git a/src/openhuman/agent/turn_origin.rs b/src/openhuman/agent/turn_origin.rsindex e4c27f30dc..d82464aabf 100644--- a/src/openhuman/agent/turn_origin.rs+++ b/src/openhuman/agent/turn_origin.rs@@ -124,6 +124,34 @@ impl AgentTurnOrigin {AgentTurnOrigin::Unknown => "Unknown".to_string(),}}++ /// Whether the turn's text was written by a **person**.+ ///+ /// `WebChat` and `ExternalChannel` carry what a human sent. Every other+ /// origin carries text the host wrote for an agent to act on: a+ /// `TrustedAutomation` prompt (cron, subconscious, goal continuation,+ /// workflow), a `Cli` invocation — which this module documents as+ /// "command-line / **sub-agent** / one-off internal" — or an unscoped+ /// `Unknown`.+ ///+ /// An allowlist, not a denylist, and for the same reason the permission+ /// gate uses one: a new origin is a turn nobody has classified yet, and+ /// mistaking a host-written prompt for a user message writes it into the+ /// user's memory, where it is indistinguishable from something they said.+ /// A caller that genuinely relays a person's text scopes one of the two+ /// origins above.+ pub fn is_user_authored(&self) -> bool {+ matches!(+ self,+ AgentTurnOrigin::WebChat { .. } | AgentTurnOrigin::ExternalChannel { .. }+ )+ }+}++/// Whether the current turn's text was written by a person — `false` outside+/// any origin scope, matching [`AgentTurnOrigin::is_user_authored`]'s allowlist.+pub fn current_is_user_authored() -> bool {+ current().is_some_and(|origin| origin.is_user_authored())}tokio::task_local! {