Skip to content

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

Rust

fix(admin): answer an omitted confirm with the documented 400

Djalma Júnior7e6423afc4b4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fee7fa0b..2a276a2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,13 @@ version in [`docs/changelog/`](docs/changelog/):
## [Unreleased]
### Fixed
+- Fixed the guarded admin routes answering a body without `confirm` with a bare
+ 422 from the JSON extractor. `POST /admin/compact`,
+ `/admin/reclaim-ledger-versions`, `/admin/purge-project`,
+ `/admin/purge-session`, `/admin/move-project` and `/admin/handoffs/expire`
+ now read an omitted `confirm` as `false` and return the documented 400 that
+ names the flag, as `/admin/merge-workspace` already did. Nothing runs without
+ `confirm: true`.
- Fixed `memory_lint` reporting findings for TTL-expired pages. The lint pass
now omits expired pages before evaluating episodic staleness, rule suggestions,
duplicate titles, and vector or LLM contradiction candidates, preventing
diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rs
index ead356ea..9bb2b3e6 100644
--- a/crates/ai-memory-mcp/src/admin.rs
+++ b/crates/ai-memory-mcp/src/admin.rs
@@ -3085,6 +3085,7 @@ struct ExpireHandoffsRequest {
workspace: String,
project: String,
/// Mandatory. Without `confirm: true` the server returns 400.
+ #[serde(default)]
confirm: bool,
/// Only expire handoffs at least this many days old. Omitted clears the
/// whole open backlog for the scope.
@@ -4398,6 +4399,7 @@ struct PurgeSessionRequest {
session_id: String,
/// Mandatory confirmation flag. Without `confirm: true` the server
/// returns 400 — purging is destructive and irreversible.
+ #[serde(default)]
confirm: bool,
/// Reclaim freed bytes: rebuild the FTS indexes and `VACUUM` after the
/// delete commits. Off by default; see `ai_memory_store::Compaction` for
@@ -4931,6 +4933,7 @@ struct PurgeProjectRequest {
project_id: Option<String>,
/// Mandatory confirmation flag. Without `confirm: true` the server
/// returns 400 — purging is destructive and irreversible.
+ #[serde(default)]
confirm: bool,
/// Purge even when a managed workstream under this project still holds a
/// live run lease. Off by default: the cascade would delete that lease row
@@ -5521,7 +5524,10 @@ struct CompactRequest {
/// Mandatory confirmation. Not because compaction destroys anything — it
/// deletes nothing — but because it takes an exclusive lock and rewrites
/// the whole database, so every write blocks until it finishes. That is an
- /// availability decision, and it should be deliberate.
+ /// availability decision, and it should be deliberate. An omitted field
+ /// reads as `false`, so the caller gets the 400 that says what to send
+ /// instead of the extractor's bare 422.
+ #[serde(default)]
confirm: bool,
}
@@ -5578,6 +5584,7 @@ struct ReclaimLedgerVersionsRequest {
/// `compact` it is not reversible by re-running anything: the bytes are
/// only in the markdown the ledger mirrors, and only if the file on disk
/// still holds them.
+ #[serde(default)]
confirm: bool,
/// Report what would go without deleting it. A dry run changes nothing,
/// so it needs no `confirm` — that is the whole point of it.
@@ -6069,6 +6076,7 @@ struct MoveProjectRequest {
to_workspace: String,
/// Mandatory confirmation flag. The move PURGES the source after
/// copying, so without `confirm: true` the server returns 400.
+ #[serde(default)]
confirm: bool,
/// Override the active-project guard. By default the server refuses (409)
/// to move the project the hook router is currently writing to, since a
diff --git a/crates/ai-memory-mcp/tests/suite/admin_purge.rs b/crates/ai-memory-mcp/tests/suite/admin_purge.rs
index 64d7cce9..6fadb01f 100644
--- a/crates/ai-memory-mcp/tests/suite/admin_purge.rs
+++ b/crates/ai-memory-mcp/tests/suite/admin_purge.rs
@@ -982,6 +982,51 @@ async fn purge_project_without_confirm_returns_400() {
);
}
+/// Omitting `confirm` entirely is the same refusal as `confirm: false`: the
+/// documented 400 that names the flag, not the JSON extractor's bare 422 that
+/// operators read as a malformed request. Every route whose docs promise that
+/// 400 is listed here.
+#[tokio::test]
+async fn omitted_confirm_is_the_documented_400_on_every_guarded_route() {
+ let cases = [
+ (
+ "/admin/handoffs/expire",
+ json!({ "workspace": "default", "project": "any" }),
+ ),
+ (
+ "/admin/purge-session",
+ json!({
+ "workspace": "default",
+ "project": "any",
+ "session_id": "00000000-0000-0000-0000-000000000000",
+ }),
+ ),
+ (
+ "/admin/purge-project",
+ json!({ "workspace": "default", "project": "any" }),
+ ),
+ ("/admin/compact", json!({})),
+ ("/admin/reclaim-ledger-versions", json!({})),
+ (
+ "/admin/move-project",
+ json!({ "from_workspace": "default", "project": "any", "to_workspace": "other" }),
+ ),
+ ];
+ for (uri, body) in cases {
+ let tmp = TempDir::new().unwrap();
+ let (state, _store) = make_state(&tmp).await;
+
+ let resp = post(state, uri, body).await;
+ assert_eq!(resp.status(), StatusCode::BAD_REQUEST, "{uri}");
+
+ let body = body_json(resp).await;
+ assert!(
+ body["error"].as_str().unwrap_or("").contains("confirm"),
+ "{uri}: the refusal must name the flag: {body}"
+ );
+ }
+}
+
/// Non-existent project must return 404.
#[tokio::test]
async fn purge_project_nonexistent_returns_404() {
diff --git a/crates/ai-memory-mcp/tests/suite/admin_reclaim_ledger_versions.rs b/crates/ai-memory-mcp/tests/suite/admin_reclaim_ledger_versions.rs
index 94575ce9..601c5763 100644
--- a/crates/ai-memory-mcp/tests/suite/admin_reclaim_ledger_versions.rs
+++ b/crates/ai-memory-mcp/tests/suite/admin_reclaim_ledger_versions.rs
@@ -127,10 +127,8 @@ async fn deleting_without_confirm_is_refused_and_changes_nothing() {
);
}
-/// `confirm` has no serde default, so a body that omits it is rejected by the
-/// extractor before the handler runs — the same fail-closed shape
-/// `/admin/compact` uses. A request that never states its intent cannot
-/// delete.
+/// An omitted `confirm` reads as `false`, so a body that never states its
+/// intent gets the same 400 as an explicit `false` — and cannot delete.
#[tokio::test]
async fn omitting_confirm_entirely_is_refused() {
let tmp = TempDir::new().unwrap();
@@ -139,11 +137,7 @@ async fn omitting_confirm_entirely_is_refused() {
let resp = post(state, "/admin/reclaim-ledger-versions", json!({})).await;
- assert!(
- resp.status().is_client_error(),
- "expected a client error, got {}",
- resp.status(),
- );
+ assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
assert_eq!(page_rows(&store).await, 2);
}