Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge pull request #1358 from lhzapata/fix/auto-improve-admission-outages
AkitaOnRailsb6f573548cdd
diff --cc CHANGELOG.mdindex 5e1ef29e,ad4eb189..cfb8b487--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -12,49 -12,12 +12,55 @@@ version in [`docs/changelog/`](docs/cha## [Unreleased]### Fixed+- `ai-memory auth login openai-oauth` and `auth login copilot` no longer print+ a failed endpoint's whole response body. Error bodies are bounded, scrubbed+ of secrets and terminal control sequences, then capped for display; provider+ errors, including OIDC login and refresh, use the same ordering so a secret+ at the display boundary is still redacted. (#1359)+- Fixed OIDC device login and refresh sending credential-bearing requests to+ non-TLS endpoints. Issuers and advertised or persisted device/token endpoints+ must now use `https` outside loopback, and authentication requests do not+ follow redirects. Plain `http` remains available for local test issuers on+ `localhost`, `127.0.0.1` and `::1`. (#1354)+- Fixed `install-instructions` printing a false "Claude Code reads <file> instead+ of AGENTS.md" note when `$HOME` is reached through a symlink. The home+ `.claude/CLAUDE.md` skip now compares with the same canonicalising+ `paths_match` helper the import check uses, so a symlinked home matches its+ resolved path. (#1345)+- Corrected stale claims in `docs/comparison.md` and `docs/competitive-parity.md`+ that said Windows has no service step and the Windows install is experimental.+ The 3.1 `install.ps1` + `setup` Windows service step is shipped production,+ not experimental; the "3.0 (unreleased)" observation-stream note is corrected+ to reflect the released 3.0 line. (#1271)+- Made the executable auto-improvement eval policy server-owned. Manual CLI and+ HTTP reviews now use `[auto_improve.eval]` from the server process, and legacy+ requests that try to supply an `eval` object fail closed with an upgrade+ message.+- Made managed cross-harness continuation survive quota exhaustion without a+ voluntary handoff. The startup packet now places its server-authored resume+ directive outside the untrusted transcript fence, and refreshed+ `CLAUDE.md` / `AGENTS.md` routing tells an incoming agent that "continue",+ "resume", and "pick up where we left off" must consult the private+ `AI_MEMORY_PREVIOUS_SESSION_HISTORY` dossier when the managed-run variables+ are present. The dossier remains untrusted evidence and stays local to the+ launcher machine.+- Fixed unbounded memory use in consolidation and auto-improve for long+ sessions: both paths now read a bounded projection of the session's+ observations instead of loading every row, keeping the LLM input+ byte-identical. Sessions with no observations in the consolidator's target+ scope (purged or foreign) are refused before any work, exactly as empty+ sessions were before. (#1363)+- Fixed the session page's uncapped `## Prompts` list. Above 500 prompts the+ page now lists the first 250 titles and the last 250, numbered by their real+ position, with one line between them saying how many were left out. The+ store reads at most 500 titles for it, and the page's prompt count and the+ digest stats still report the true total. (#1349)+ - Fixed auto-improve approvals that failed because a `reject`-policy admission- webhook was unreachable, timed out or answered 5xx being stored as++ webhook was unreachable, timed out, rate-limited or answered 5xx being stored as+ rejections. The proposal is still marked `failed`, but the outage no longer+ enters the rejection buffer, so later reviews are not told to avoid a+ proposal nobody refused and rejection telemetry counts only real+ refusals. (#1358)## [3.1.0] - 2026-10-16diff --cc crates/ai-memory-wiki/src/admission.rsindex 693d9613,2bc0cf0b..8c7f532d--- a/crates/ai-memory-wiki/src/admission.rs+++ b/crates/ai-memory-wiki/src/admission.rs@@@ -439,7 -479,10 +479,13 @@@ impl AdmissionChain);tracing::warn!(webhook = %hook.name, status = %status, body = %body_txt, "admission error response");if matches!(hook.failure_policy, FailurePolicy::Reject) {- return Err(WikiError::Io(std::io::Error::other(err_msg)));- return Err(AdmissionFailure::into_error(- status.is_server_error(),- err_msg,- ));++ let unavailable = status.is_server_error()++ || matches!(++ status,++ reqwest::StatusCode::REQUEST_TIMEOUT++ | reqwest::StatusCode::TOO_MANY_REQUESTS++ );++ return Err(AdmissionFailure::into_error(unavailable, err_msg));}}Err(e) => {diff --cc crates/ai-memory-wiki/tests/suite/auto_improve_admission.rsindex 00000000,f884db23..70779067mode 000000,100644..100644--- a/crates/ai-memory-wiki/tests/suite/auto_improve_admission.rs+++ b/crates/ai-memory-wiki/tests/suite/auto_improve_admission.rs@@@ -1,0 -1,216 +1,241 @@@+ //! Approving an auto-improve proposal through a `reject`-policy admission+ //! chain: which failures land in `auto_improve_rejections`.++ use std::time::Duration;++ use ai_memory_core::{ActorContext, PagePath, ProjectId, WorkspaceId};+ use ai_memory_store::{+ AutoImproveProposalOperation, AutoImproveProposalStatus, NewAutoImproveProposal,+ StageAutoImproveRun, Store,+ };+ use ai_memory_wiki::{AdmissionChain, AdmissionOp, FailurePolicy, WebhookConfig, Wiki};+ use axum::Router;+ use axum::http::StatusCode;+ use axum::routing::post;+ use tempfile::TempDir;++ struct Fixture {+ _tmp: TempDir,+ store: Store,+ wiki: Wiki,+ ws: WorkspaceId,+ proj: ProjectId,+ }++ async fn fixture(chain: AdmissionChain) -> Fixture {+ let tmp = TempDir::new().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let ws = store+ .writer+ .get_or_create_workspace("default")+ .await+ .unwrap();+ let proj = store+ .writer+ .get_or_create_project(ws, "a", None)+ .await+ .unwrap();+ let wiki = Wiki::new(tmp.path(), store.writer.clone())+ .unwrap()+ .with_store_reader(store.reader.clone())+ .with_admission_chain(chain);+ std::fs::create_dir_all(wiki.project_root(ws, proj)).unwrap();+ Fixture {+ _tmp: tmp,+ store,+ wiki,+ ws,+ proj,+ }+ }++ async fn spawn_server(app: Router) -> String {+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();+ let addr = listener.local_addr().unwrap();+ tokio::spawn(async move {+ axum::serve(listener, app).await.unwrap();+ });+ format!("http://{addr}")+ }++ fn chain(url: String, timeout_ms: u64, failure_policy: FailurePolicy) -> AdmissionChain {+ AdmissionChain::new(vec![WebhookConfig {+ name: "policy".into(),+ url,+ timeout_ms,+ failure_policy,+ events: vec![AdmissionOp::WritePage],+ blocking: true,+ }])+ .unwrap()+ }++ async fn stage_one(fx: &Fixture) -> ai_memory_core::AutoImproveProposalId {+ fx.store+ .writer+ .stage_auto_improve_run(StageAutoImproveRun {+ workspace_id: fx.ws,+ project_id: fx.proj,+ session_id: None,+ provider: None,+ model: None,+ summary: None,+ warnings_json: serde_json::json!([]),+ rejected_candidates_json: serde_json::json!([]),+ config_json: serde_json::json!({}),+ proposal_actor: ActorContext::anonymous(),+ proposals: vec![NewAutoImproveProposal {+ operation: AutoImproveProposalOperation::Create,+ target_path: PagePath::new("decisions/rule.md").unwrap(),+ kind: "rule".into(),+ title: "Rule".into(),+ confidence: 0.9,+ rationale: "because".into(),+ evidence_json: serde_json::json!([]),+ body_markdown: "# Rule\n\nAlways do the thing.\n".into(),+ artifact_sha256: None,+ edit_mode: None,+ patch_json: None,+ expected_base_body_sha256: None,+ }],+ })+ .await+ .unwrap()+ .proposal_ids[0]+ }++ /// Approve once and return (approval errored, proposal status, rejection reasons).+ async fn approve(fx: &Fixture) -> (bool, AutoImproveProposalStatus, Vec<String>) {+ let id = stage_one(fx).await;+ let res = fx+ .wiki+ .approve_auto_improve_proposal(fx.ws, fx.proj, id, ActorContext::anonymous(), None, None)+ .await;+ let status = fx+ .store+ .reader+ .auto_improve_proposal_detail(fx.ws, fx.proj, id)+ .await+ .unwrap()+ .unwrap()+ .summary+ .status;+ let reasons = fx+ .store+ .reader+ .recent_auto_improve_rejections(fx.ws, fx.proj, 10, None)+ .await+ .unwrap()+ .into_iter()+ .map(|r| r.reason)+ .collect();+ (res.is_err(), status, reasons)+ }++ // Negative: an admission server that times out did not reject anything.+ #[tokio::test]+ async fn reject_policy_timeout_is_not_recorded_as_a_rejection() {+ let app = Router::new().route(+ "/policy",+ post(|| async {+ tokio::time::sleep(Duration::from_secs(5)).await;+ StatusCode::OK+ }),+ );+ let base = spawn_server(app).await;+ let fx = fixture(chain(format!("{base}/policy"), 200, FailurePolicy::Reject)).await;+ let (errored, status, reasons) = approve(&fx).await;+ assert!(errored);+ assert_eq!(status, AutoImproveProposalStatus::Failed);+ assert!(+ reasons.is_empty(),+ "outage recorded as rejection: {reasons:?}"+ );+ }++ // Negative: a 503 from the admission server is an outage, not a verdict.+ #[tokio::test]+ async fn reject_policy_503_is_not_recorded_as_a_rejection() {+ let app = Router::new().route(+ "/policy",+ post(|| async { (StatusCode::SERVICE_UNAVAILABLE, "down for maintenance") }),+ );+ let base = spawn_server(app).await;+ let fx = fixture(chain(+ format!("{base}/policy"),+ 1_000,+ FailurePolicy::Reject,+ ))+ .await;+ let (errored, status, reasons) = approve(&fx).await;+ assert!(errored);+ assert_eq!(status, AutoImproveProposalStatus::Failed);+ assert!(+ reasons.is_empty(),+ "outage recorded as rejection: {reasons:?}"+ );+ }+++// Negative: 408 and 429 are transient availability responses, not policy verdicts.++#[tokio::test]++async fn reject_policy_transient_client_status_is_not_recorded_as_a_rejection() {++ for status_code in [StatusCode::REQUEST_TIMEOUT, StatusCode::TOO_MANY_REQUESTS] {++ let app = Router::new().route(++ "/policy",++ post(move || async move { (status_code, "try again later") }),++ );++ let base = spawn_server(app).await;++ let fx = fixture(chain(++ format!("{base}/policy"),++ 1_000,++ FailurePolicy::Reject,++ ))++ .await;++ let (errored, status, reasons) = approve(&fx).await;++ assert!(errored);++ assert_eq!(status, AutoImproveProposalStatus::Failed);++ assert!(++ reasons.is_empty(),++ "{status_code} outage recorded as rejection: {reasons:?}"++ );++ }++}+++ // Control: an explicit 403 is a policy verdict and must stay a rejection.+ #[tokio::test]+ async fn reject_policy_403_is_recorded_as_a_rejection() {+ let app = Router::new().route(+ "/policy",+ post(|| async { (StatusCode::FORBIDDEN, "no secrets") }),+ );+ let base = spawn_server(app).await;+ let fx = fixture(chain(+ format!("{base}/policy"),+ 1_000,+ FailurePolicy::Reject,+ ))+ .await;+ let (errored, status, reasons) = approve(&fx).await;+ assert!(errored);+ assert_eq!(status, AutoImproveProposalStatus::Failed);+ assert_eq!(reasons.len(), 1, "{reasons:?}");+ assert!(reasons[0].contains("403"), "{reasons:?}");+ }++ // Control: with the ignore policy an outage neither fails nor rejects.+ #[tokio::test]+ async fn ignore_policy_timeout_approves_without_rejection() {+ let app = Router::new().route(+ "/policy",+ post(|| async {+ tokio::time::sleep(Duration::from_secs(5)).await;+ StatusCode::OK+ }),+ );+ let base = spawn_server(app).await;+ let fx = fixture(chain(format!("{base}/policy"), 200, FailurePolicy::Ignore)).await;+ let (errored, status, reasons) = approve(&fx).await;+ assert!(!errored);+ assert_eq!(status, AutoImproveProposalStatus::Approved);+ assert!(reasons.is_empty(), "{reasons:?}");+ }diff --cc docs/auto-improvement-loop.mdindex aa8d14ce,06ec8293..83b98004--- a/docs/auto-improvement-loop.md+++ b/docs/auto-improvement-loop.md@@@ -415,7 -414,9 +415,9 @@@ imply each otherrejection-buffer summary included in future reviewer prompts. The buffer isscoped by `workspace_id` + `project_id` and stores human rejects, approvalconflicts/failures, and validator/model rejected candidates when they carry a- reason.+ reason. An approval that fails because a `reject`-policy admission webhook was-unreachable, timed out or answered 5xx still marks the proposal `failed`, but-is not stored: an outage says nothing about the proposal.++unreachable, timed out, rate-limited or answered 5xx still marks the proposal++`failed`, but is not stored: an outage says nothing about the proposal.## Proposal Format