Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(mcp): redact provider body from memory_explore degradation reason (#1103)
maintainerafb9bbc53dcd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5420e59d..703a59cc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed- Redacted provider response bodies from the error surfaces this changetouches: the `memory_consolidate` and `memory_auto_improve` MCP errors, the- reranker degradation warning, the consolidator's transient-retry warning,- the SessionEnd consolidation worker's queue `last_error` and failure logs,- the auto-improve scheduler's claim `last_error` and tick warnings, and the- hook router's checkpoint-fallback warning now carry a stable `class`/`status`+ `memory_explore` degradation reason and warning, the reranker degradation+ warning, the consolidator's transient-retry warning, the SessionEnd+ consolidation worker's queue `last_error` and failure logs, the+ auto-improve scheduler's claim `last_error` and tick warnings, and the hook+ router's checkpoint-fallback warning now carry a stable `class`/`status`summary (for example `class=provider status=400`) instead of the error's`Display`, which for a provider failure includes the upstream responsebody. Other error surfaces are unchanged. (#1103)diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rsindex 8c026ffe..bc55c281 100644--- a/crates/ai-memory-mcp/src/server.rs+++ b/crates/ai-memory-mcp/src/server.rs@@ -5311,10 +5311,23 @@ impl AiMemoryServer {let text = match provider.complete(request).await {Ok(resp) => resp.text,Err(e) => {- tracing::warn!(error = %e, "memory_explore LLM call failed; degrading to briefing");+ // Redacted fields only: the `Display` of a provider failure+ // carries the upstream response body, and this reason goes+ // back to the tool caller.+ tracing::warn!(+ error_class = %e.class(),+ error_status = ?e.http_status(),+ "memory_explore LLM call failed; degrading to briefing"+ );return ok_json(&serde_json::json!({"prose": null,- "reason": format!("LLM call failed: {e}"),+ "reason": format!(+ "LLM call failed: class={} status={}",+ e.class(),+ e.http_status()+ .map(|status| status.to_string())+ .unwrap_or_else(|| "none".into())+ ),"briefing": snapshot,}));}@@ -11630,6 +11643,52 @@ mod tests {);}+ /// Mutation captured: formatting the `LlmError`'s `Display` into the+ /// degraded-explore `reason` copies the provider body to the tool+ /// caller. The failure must degrade with the redacted class/status+ /// summary only, mirroring the `memory_consolidate` redaction tests.+ #[tokio::test]+ async fn memory_explore_degrades_with_redacted_summary_not_provider_body() {+ let (tmp, store, _server, ws, proj) = setup_server().await;+ let server = consolidating_server_failing_with_private_body(&tmp, &store, ws, proj).await;++ let result = server+ .memory_explore(+ Parameters(ExploreArgs {+ focus: None,+ recent_pages_limit: Some(5),+ project: None,+ workspace: None,+ reasoning: None,+ }),+ OptionalParts(test_parts_default()),+ )+ .await+ .expect("a provider failure must degrade to the briefing, not error");+ let text = result+ .content+ .first()+ .and_then(|c| c.as_text())+ .map(|t| t.text.clone())+ .unwrap();+ assert!(+ text.contains("LLM call failed: class=provider status=400"),+ "the degraded reason must carry only the redacted class/status summary\n{text}"+ );+ assert!(+ !text.contains("SENTINEL_PRIVATE_BODY"),+ "provider body leaked into the tool result\n{text}"+ );+ assert!(+ text.contains("\"prose\": null"),+ "expected null prose\n{text}"+ );+ assert!(+ text.contains("\"briefing\":"),+ "expected briefing payload\n{text}"+ );+ }+/// Provider failure for the `memory_consolidate` redaction tests: a 400/// whose private body must never reach the MCP error message.struct ConsolidationBodyFailure;