Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

feat(serve): add an unauthenticated GET /healthz liveness probe

Thiago Zanluca8a976b68e7f6
diff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rs
index c86ad0ea..b5154d88 100644
--- a/crates/ai-memory-cli/src/commands/serve.rs
+++ b/crates/ai-memory-cli/src/commands/serve.rs
@@ -1343,6 +1343,7 @@ pub async fn run(config: &Config, args: ServeArgs) -> Result<()> {
},
)?;
let router = machine
+ .merge(healthz_router())
.merge(admin)
.merge(public_auth_router(auth_state.clone()))
.merge(session_auth_router(auth_state.clone()))
@@ -2285,6 +2286,22 @@ fn llm_retry_hint(provider: &str, model: &str, base_url: Option<&str>) -> String
command
}
+/// Liveness probe for process supervisors.
+///
+/// Unauthenticated on purpose: launchd, systemd and `HEALTHCHECK` have no
+/// bearer token, and the answer ("this process is listening") is already
+/// observable by connecting to the port. It reads nothing and reports no
+/// store, provider or auth state.
+///
+/// Without it the only live signal is `GET /mcp` answering 405, which is an
+/// accident of method routing rather than a contract a supervisor can rely on.
+fn healthz_router() -> axum::Router {
+ axum::Router::new().route(
+ "/healthz",
+ axum::routing::get(|| async { axum::Json(serde_json::json!({ "status": "ok" })) }),
+ )
+}
+
fn apply_host_layer(router: axum::Router, allowed_hosts: Vec<String>) -> axum::Router {
router.layer(axum::middleware::from_fn_with_state(
Arc::new(allowed_hosts),
@@ -3912,7 +3929,8 @@ mod tests {
require_dual_auth,
)))
.merge(web.public)
- .merge(ai_memory_web::favicon_router());
+ .merge(ai_memory_web::favicon_router())
+ .merge(healthz_router());
// Mutation captured: dropping any host-owned route merge lets the root SPA
// wildcard return its HTML shell instead of the reserved route response.
@@ -3941,6 +3959,21 @@ mod tests {
);
}
+ // A supervisor probing liveness sends no bearer token, so /healthz has to
+ // answer 200 with auth configured — and it is a host-owned route like the
+ // ones above, so the SPA wildcard must not serve its shell here either.
+ let health = router
+ .clone()
+ .oneshot(
+ Request::builder()
+ .uri("/healthz")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(health.status(), StatusCode::OK);
+
let api = router
.clone()
.oneshot(