Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agents): let owners delete external agent sessions (#9561)
Eric Hayes5f3eef4c5056
diff --git a/crates/agent_harness/src/outbound/routing.rs b/crates/agent_harness/src/outbound/routing.rsindex 0e0630c4f0..8d6486ef4e 100644--- a/crates/agent_harness/src/outbound/routing.rs+++ b/crates/agent_harness/src/outbound/routing.rs@@ -8,7 +8,9 @@//!//! `spawn` routes on the bot the command names. `resume` and `teardown` get//! only a session id, so they read the session's bot from the repo — the same-//! key, recovered from the same durable row that spawn wrote it to.+//! key, recovered from the same durable row that spawn wrote it to. External+//! sessions have no provider here: teardown is a no-op for them, and every+//! other operation refuses.use agent_runtime_protocol::domain::ports::{Transport, TransportError, TransportReceiver, TransportSender,@@ -140,7 +142,9 @@ whereAgentKind::CodexCloud => self.codex.teardown(session).await,AgentKind::Cursor => self.cursor.teardown(session).await,AgentKind::SandboxedCoder | AgentKind::InMemory => self.sandbox.teardown(session).await,- AgentKind::External => Err(external_is_unroutable()),+ // Its operator hosts the runtime, so no provider holds anything to+ // release; refusing here would leave the session undeletable.+ AgentKind::External => Ok(()),}}@@ -170,9 +174,9 @@ where}/// The trigger gate never routes external bots here — their operators host-/// their runtimes — so an external kind reaching a provider decision means a-/// corrupt session row or a broken gate, and refusing loudly beats picking a-/// provider that cannot serve it.+/// their runtimes — so an external kind reaching a provider decision other+/// than teardown means a corrupt session row or a broken gate, and refusing+/// loudly beats picking a provider that cannot serve it.fn external_is_unroutable() -> HarnessError {HarnessError::Container("this session requires a provider outside the sandbox/Cursor router".to_owned(),diff --git a/crates/agent_harness/src/outbound/routing/test.rs b/crates/agent_harness/src/outbound/routing/test.rsindex 07545bf5b3..c0ab0ff253 100644--- a/crates/agent_harness/src/outbound/routing/test.rs+++ b/crates/agent_harness/src/outbound/routing/test.rs@@ -105,9 +105,9 @@ impl ContainerManager for TaggedManager {}}-/// Answers every session lookup with a fixed bot.+/// Answers every session lookup with a fixed bot and harness slug.#[derive(Clone)]-struct FixedBotSessions(BotId);+struct FixedBotSessions(BotId, &'static str);impl AgentSessionRepo for FixedBotSessions {async fn create(&self, _params: CreateAgentSessionParams) -> SessionResult<AgentSession> {@@ -148,7 +148,7 @@ impl AgentSessionRepo for FixedBotSessions {originating_message_id: None,bot_id: self.0,model: "auto".to_owned(),- harness: "cursor".to_owned(),+ harness: self.1.to_owned(),repo_url: None,workspace: "/workspace".to_owned(),name: DEFAULT_AGENT_SESSION_NAME.to_owned(),@@ -349,7 +349,7 @@ async fn the_cursor_bot_routes_to_cursor_and_everything_else_to_the_sandbox() {sandbox.clone(),cursor.clone(),TaggedManager::new("codex"),- FixedBotSessions(bot_id::CURSOR_BOT_ID),+ FixedBotSessions(bot_id::CURSOR_BOT_ID, "cursor"),);let spawned = router@@ -377,7 +377,7 @@ async fn preflight_routes_by_kind_before_any_session_exists() {sandbox.clone(),cursor.clone(),codex.clone(),- FixedBotSessions(bot_id::CURSOR_BOT_ID),+ FixedBotSessions(bot_id::CURSOR_BOT_ID, "cursor"),);let owner = MacroUserIdStr::try_from_email("[email protected]").expect("a valid user id");@@ -412,7 +412,7 @@ async fn resume_and_teardown_route_by_the_stored_bot() {sandbox.clone(),cursor.clone(),TaggedManager::new("codex"),- FixedBotSessions(bot_id::CURSOR_BOT_ID),+ FixedBotSessions(bot_id::CURSOR_BOT_ID, "cursor"),);let session = AgentSessionId::new();@@ -430,7 +430,7 @@ async fn a_database_backed_cursor_agent_routes_by_its_stored_harness() {sandbox.clone(),cursor.clone(),TaggedManager::new("codex"),- FixedBotSessions(BotId::TEST_A),+ FixedBotSessions(BotId::TEST_A, "cursor"),);let session = AgentSessionId::new();@@ -453,7 +453,7 @@ async fn codex_routes_all_lifecycle_operations_and_rejects_resize() {sandbox.clone(),cursor.clone(),codex.clone(),- FixedBotSessions(bot_id::CODEX_BOT_ID),+ FixedBotSessions(bot_id::CODEX_BOT_ID, "cursor"),);router.spawn(spawn_for(AgentKind::CodexCloud))@@ -481,3 +481,26 @@ async fn codex_routes_all_lifecycle_operations_and_rejects_resize() {AgentKind::CodexCloud);}++/// An external session's runtime is its operator's, so deleting it has no+/// provider to release: teardown succeeds without reaching one, while+/// operations that would need a provider still refuse.+#[tokio::test]+async fn external_teardown_is_a_no_op_and_resume_still_refuses() {+ let sandbox = TaggedManager::new("sandbox");+ let cursor = TaggedManager::new("cursor");+ let codex = TaggedManager::new("codex");+ let router = RoutedContainerManager::new(+ sandbox.clone(),+ cursor.clone(),+ codex.clone(),+ FixedBotSessions(BotId::TEST_A, harness_id::MACROD_HARNESS_SLUG),+ );++ let session = AgentSessionId::new();+ router.teardown(session).await.expect("teardown");+ assert!(router.resume(session).await.is_err());+ assert!(sandbox.calls().is_empty());+ assert!(cursor.calls().is_empty());+ assert!(codex.calls().is_empty());+}