Skip to content

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

fix(saas): Phase 2 review round 1 — scoped config lookup, safe deprovision, per-agent files

Steven Enamakeld43c9d6271f2
diff --git a/crates/openhuman-core/src/core/runtime/spawn_tests.rs b/crates/openhuman-core/src/core/runtime/spawn_tests.rs
index 651a0bd963..357492183f 100644
--- a/crates/openhuman-core/src/core/runtime/spawn_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/spawn_tests.rs
@@ -61,3 +61,17 @@ async fn outside_any_scope_spawn_scoped_is_a_plain_spawn() {
let (_, identity) = spawn_scoped(async { seen() }).await.unwrap();
assert_eq!(identity, None);
}
+
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn spawn_blocking_scoped_keeps_the_memory_identity() {
+ let ctx = agent_context("u-ravi");
+ let seen = CoreContext::scope(ctx, async {
+ crate::memory::scope::within(MemoryIdentity::agent("planner"), async {
+ spawn_blocking_scoped(seen).await.unwrap()
+ })
+ .await
+ })
+ .await;
+ assert_eq!(seen.0.as_deref(), Some("u-ravi"));
+ assert_eq!(seen.1.as_deref(), Some("planner"));
+}
diff --git a/crates/openhuman-core/src/user_agents/host_tests.rs b/crates/openhuman-core/src/user_agents/host_tests.rs
index ab37acc505..0b50c9b439 100644
--- a/crates/openhuman-core/src/user_agents/host_tests.rs
+++ b/crates/openhuman-core/src/user_agents/host_tests.rs
@@ -137,3 +137,33 @@ fn list_reports_provisioned_agents_only() {
.collect();
assert_eq!(open, vec![&b]);
}
+
+#[test]
+fn an_agent_in_use_is_not_archived_from_under_it() {
+ let tmp = tempfile::tempdir().unwrap();
+ let host = host(&tmp, 4, 60);
+ let id = agent("alice");
+ host.provision(&id).unwrap();
+ let state = host.open(&id).unwrap();
+ let err = host.deprovision(&id).unwrap_err();
+ assert!(err.contains("in use"), "{err}");
+ assert!(host.is_open(&id), "a refused deprovision leaves it open");
+ drop(state);
+ assert!(host.deprovision(&id).unwrap());
+ assert!(!host.is_open(&id));
+}
+
+#[test]
+fn deprovisioning_twice_in_a_second_archives_twice() {
+ let tmp = tempfile::tempdir().unwrap();
+ let host = host(&tmp, 4, 60);
+ let id = agent("alice");
+ for _ in 0..2 {
+ host.provision(&id).unwrap();
+ assert!(host.deprovision(&id).unwrap());
+ }
+ let archived = std::fs::read_dir(layout::archive_dir(tmp.path()))
+ .unwrap()
+ .count();
+ assert_eq!(archived, 2);
+}
diff --git a/crates/openhuman-core/src/user_agents/layout_tests.rs b/crates/openhuman-core/src/user_agents/layout_tests.rs
index da9ee6121a..e4d85dc64e 100644
--- a/crates/openhuman-core/src/user_agents/layout_tests.rs
+++ b/crates/openhuman-core/src/user_agents/layout_tests.rs
@@ -59,3 +59,11 @@ fn the_policy_is_on_and_closed() {
assert!(!autonomy.allow_tool_install);
assert!(autonomy.trusted_roots.is_empty());
}
+
+#[test]
+fn artifacts_land_in_the_agents_sandbox() {
+ let id = UserAgentId::for_user("alice").unwrap();
+ let layout = UserAgentLayout::new(std::path::Path::new("/srv/oh"), &id);
+ let config = agent_config(&layout, &id);
+ assert!(config.files_dir().starts_with(&layout.sandbox_dir));
+}