Skip to content

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

test(e2e): add session reset test case

Steven Enamakel8c94fbe556c6
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 9c7010e4df..94fbc50db4 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -477,6 +477,177 @@ async fn remote_clear_rejects_an_unconfigured_captured_account() {
assert!(result.is_err(), "unknown provider account must fail closed");
}
+#[cfg(feature = "modules")]
+#[tokio::test]
+async fn remote_clear_resets_only_the_captured_tenant_session() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+ use tinyagents_session::transcript::{
+ SessionRef, TranscriptHistory, TranscriptLocator, TranscriptMessage, TranscriptMeta,
+ TranscriptRead,
+ };
+
+ struct ConfiguredChannel;
+ #[async_trait]
+ impl Channel for ConfiguredChannel {
+ fn name(&self) -> &str {
+ "telegram:bot-a"
+ }
+ async fn send(&self, _message: &SendMessage) -> anyhow::Result<()> {
+ Ok(())
+ }
+ async fn listen(
+ &self,
+ _tx: tokio::sync::mpsc::Sender<ChannelMessage>,
+ ) -> anyhow::Result<()> {
+ Ok(())
+ }
+ }
+
+ fn transcript_meta(thread_id: &str) -> TranscriptMeta {
+ TranscriptMeta {
+ agent_name: "orchestrator".into(),
+ agent_id: Some("orchestrator".into()),
+ agent_type: Some("root".into()),
+ dispatcher: "native".into(),
+ provider: Some("mock".into()),
+ model: Some("session-test".into()),
+ created: "2026-10-20T00:00:00Z".into(),
+ updated: "2026-10-20T00:00:00Z".into(),
+ turn_count: 1,
+ prefix_message_count: Some(0),
+ prefix_reset: false,
+ input_tokens: 0,
+ output_tokens: 0,
+ cached_input_tokens: 0,
+ charged_amount_usd: 0.0,
+ thread_id: Some(thread_id.into()),
+ task_id: None,
+ session_id: None,
+ parent_session_id: None,
+ }
+ }
+
+ fn seed_session(core: &CoreContext, workspace: &Path, key: &str) -> SessionRef {
+ let session = SessionRef::scoped(key, "orchestrator");
+ let history =
+ crate::agent::session_store::transcripts_or_files_in(core, "orchestrator", workspace)
+ .open_session(&session, transcript_meta(key))
+ .unwrap();
+ history
+ .append(TranscriptMessage::user("prior tenant turn"))
+ .unwrap();
+ history
+ .append(TranscriptMessage::assistant("prior tenant reply"))
+ .unwrap();
+ session
+ }
+
+ fn messages(core: &CoreContext, workspace: &Path, session: &SessionRef) -> Vec<String> {
+ let locator =
+ crate::agent::session_store::transcripts_or_files_in(core, "orchestrator", workspace);
+ let head = locator.head_generation(session);
+ locator
+ .read_session_transcript(&head)
+ .expect("durable transcript exists")
+ .read_session()
+ .unwrap()
+ .expect("transcript is readable")
+ .messages
+ .into_iter()
+ .map(|message| message.content)
+ .collect()
+ }
+
+ let tmp = tempfile::TempDir::new().unwrap();
+ let workspace = tmp.path().to_path_buf();
+ let make_context = |profile: &str| {
+ let config = crate::config::Config {
+ workspace_dir: workspace.clone(),
+ action_dir: workspace.clone(),
+ config_path: workspace.join("config.toml"),
+ ..Default::default()
+ };
+ let core = CoreContext::for_test(DomainSet::none(), Some(workspace.clone())).derive_with(
+ ContextOverlay::new(config.clone(), DomainSet::full(), Default::default())
+ .profile(profile),
+ );
+ let mut runtime = runtime_context(workspace.clone());
+ runtime.config = Some(Arc::new(config));
+ runtime.core = Some(Arc::downgrade(&core));
+ runtime.channels_by_name = Arc::new(HashMap::from([(
+ "telegram:bot-a".into(),
+ Arc::new(ConfiguredChannel) as Arc<dyn Channel>,
+ )]));
+ (core, runtime)
+ };
+
+ let (alice_core, alice_runtime) = make_context("remote-reset-alice");
+ let (bob_core, bob_runtime) = make_context("remote-reset-bob");
+ let alice_dispatch = DispatchCtx::new(Arc::clone(&alice_core));
+ let bob_dispatch = DispatchCtx::new(Arc::clone(&bob_core));
+ let alice_tenant = alice_dispatch.tenant().unwrap();
+ let bob_tenant = bob_dispatch.tenant().unwrap();
+ let canonical = "channel-session:telegram:bot-a:group:room-1";
+ let alice_key = crate::core::runtime::tenant::tenant_key(&alice_tenant, canonical);
+ let bob_key = crate::core::runtime::tenant::tenant_key(&bob_tenant, canonical);
+ assert_ne!(alice_key, bob_key);
+ let alice_session = seed_session(&alice_core, &workspace, &alice_key);
+ let bob_session = seed_session(&bob_core, &workspace, &bob_key);
+
+ let scope = remote_session_scope();
+ let reset_context = crate::channels::host::remote_control::RemoteResetContext {
+ scope: scope.clone(),
+ durable_session_key: alice_key,
+ message: ChannelMessage {
+ channel: "telegram".into(),
+ reply_target: "room-1".into(),
+ content: "/new".into(),
+ ..Default::default()
+ },
+ history_key: "legacy-key-is-not-authority".into(),
+ };
+ let cancellation = tokio_util::sync::CancellationToken::new();
+
+ let mut forged_scope = scope.clone();
+ forged_scope.conversation.id = "other-room".into();
+ let forged = crate::channels::host::remote_control::dispatch_callback(
+ &alice_dispatch,
+ &alice_runtime,
+ &alice_tenant,
+ &cancellation,
+ Some(&reset_context),
+ tinychannels_bus::module_remote::RemoteHostRequest::ClearHistory {
+ session_scope: forged_scope,
+ },
+ )
+ .await;
+ assert!(forged.is_err(), "forged callback scope must be rejected");
+ assert_eq!(messages(&alice_core, &workspace, &alice_session).len(), 2);
+ assert_eq!(messages(&bob_core, &workspace, &bob_session).len(), 2);
+
+ let cleared = crate::channels::host::remote_control::dispatch_callback(
+ &alice_dispatch,
+ &alice_runtime,
+ &alice_tenant,
+ &cancellation,
+ Some(&reset_context),
+ tinychannels_bus::module_remote::RemoteHostRequest::ClearHistory {
+ session_scope: scope,
+ },
+ )
+ .await
+ .expect("captured tenant reset succeeds");
+ assert_eq!(
+ cleared,
+ tinychannels_bus::module_remote::RemoteHostResult::Completed
+ );
+ assert!(messages(&alice_core, &workspace, &alice_session).is_empty());
+ assert_eq!(
+ messages(&bob_core, &workspace, &bob_session),
+ ["prior tenant turn", "prior tenant reply"]
+ );
+}
+
#[tokio::test]
async fn handle_runtime_command_telegram_status_replies_without_agent() {
let ctx = runtime_context(PathBuf::from("/tmp"));
diff --git a/tests/native_channel_session_restart_e2e.rs b/tests/native_channel_session_restart_e2e.rs
index 46e477673b..245fe07172 100644
--- a/tests/native_channel_session_restart_e2e.rs
+++ b/tests/native_channel_session_restart_e2e.rs
@@ -29,7 +29,6 @@ const BOT_TOKEN: &str = "session-restart-token";
const MOCK_API_KEY: &str = "loopback-session-restart-key";
const RPC_TOKEN: &str = "native-session-restart-rpc-token";
const FIRST_TEXT: &str = "remember this after the core restarts";
-const SECOND_TEXT: &str = "what did I ask before the restart?";
const OTHER_CHAT_TEXT: &str = "remember a separate chat history";
const AFTER_RESET_TEXT: &str = "this starts a fresh session after new";
const RESET_AFTER_RESTART_TEXT: &str = "continue the reset conversation after restart";