Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agent-session): answer 409, not 500, when a runtime is not attached (#5984)

Wolf Mermelstein934993aa83d3
diff --git a/crates/agent_session/src/inbound/axum_router.rs b/crates/agent_session/src/inbound/axum_router.rs
index 578174a153..2d78bcde62 100644
--- a/crates/agent_session/src/inbound/axum_router.rs
+++ b/crates/agent_session/src/inbound/axum_router.rs
@@ -248,6 +248,20 @@ impl From<AgentSessionError> for AgentSessionApiError {
impl IntoResponse for AgentSessionApiError {
fn into_response(self) -> Response {
match self {
+ // A session whose runtime is not attached is the everyday state of
+ // a self-hosted agent: the operator's daemon dials on a trigger and
+ // its bridge ends when the session goes quiet. Nothing is wrong
+ // here, and nothing the caller does again right now will land, so it
+ // answers 409 with a reason rather than a 500 that reads as a bug
+ // and buries the one fact worth showing a user.
+ Self::Domain(AgentSessionError::Disconnected(session_id)) => {
+ tracing::info!(%session_id, "action refused: the session's runtime is not connected");
+ (
+ StatusCode::CONFLICT,
+ "the agent's runtime is not connected to this session",
+ )
+ .into_response()
+ }
Self::Domain(AgentSessionError::Forbidden) => {
(StatusCode::FORBIDDEN, "forbidden").into_response()
}
diff --git a/crates/agent_session/src/inbound/axum_router/test.rs b/crates/agent_session/src/inbound/axum_router/test.rs
index fe1a813f3f..d9a408b2df 100644
--- a/crates/agent_session/src/inbound/axum_router/test.rs
+++ b/crates/agent_session/src/inbound/axum_router/test.rs
@@ -389,3 +389,29 @@ async fn an_unknown_bot_is_a_404() {
assert_eq!(response.status(), StatusCode::NOT_FOUND);
assert!(opener.opened.lock().unwrap().is_empty());
}
+
+#[tokio::test]
+async fn a_session_whose_runtime_is_gone_is_a_409() {
+ let error =
+ AgentSessionApiError::Domain(AgentSessionError::Disconnected(AgentSessionId::new()));
+
+ let response = error.into_response();
+
+ assert_eq!(response.status(), StatusCode::CONFLICT);
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX)
+ .await
+ .unwrap();
+ assert_eq!(
+ body.as_ref(),
+ b"the agent's runtime is not connected to this session"
+ );
+}
+
+#[test]
+fn other_domain_failures_stay_500() {
+ let error = AgentSessionApiError::Domain(AgentSessionError::UnknownOwner);
+
+ let response = error.into_response();
+
+ assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
+}