Skip to content

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

Rust

fix(auto-improve): keep eval policy server-owned

AkitaOnRails5ed815a5c6db
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b9f8d75..1eb4e308 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,10 @@ version in [`docs/changelog/`](docs/changelog/):
## [Unreleased]
### Fixed
+- 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
diff --git a/crates/ai-memory-cli/src/commands/auto_improve.rs b/crates/ai-memory-cli/src/commands/auto_improve.rs
index 633a3f50..1389207c 100644
--- a/crates/ai-memory-cli/src/commands/auto_improve.rs
+++ b/crates/ai-memory-cli/src/commands/auto_improve.rs
@@ -34,7 +34,6 @@ struct AutoImproveRequest {
include_raw_fallback: bool,
proposal_actor: String,
pending_path: String,
- eval: ai_memory_consolidate::AutoImproveEvalConfig,
}
#[derive(Debug, Deserialize, Serialize)]
@@ -98,13 +97,6 @@ pub async fn run(config: &Config, args: AutoImproveArgs) -> Result<()> {
include_raw_fallback: args.include_raw_fallback || settings.include_raw_fallback,
proposal_actor: settings.proposal_actor.clone(),
pending_path: settings.pending_path.clone(),
- eval: ai_memory_consolidate::AutoImproveEvalConfig {
- enabled: settings.eval.enabled,
- command: settings.eval.command.clone(),
- timeout_secs: settings.eval.timeout_secs,
- targets: settings.eval.targets.clone(),
- min_delta: settings.eval.min_delta,
- },
};
let response: StageResponse = post_json(&endpoint, "/admin/auto-improve", &request).await?;
diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rs
index 89436b27..df6f3453 100644
--- a/crates/ai-memory-mcp/src/admin.rs
+++ b/crates/ai-memory-mcp/src/admin.rs
@@ -323,11 +323,10 @@ struct AutoImproveRequest {
/// Pending proposal sidecar folder.
#[serde(default = "default_auto_improve_pending_path")]
pending_path: String,
- /// Optional executable proposal eval gate. When omitted, direct admin
- /// requests inherit the server's configured eval policy; CLI requests send
- /// their local config explicitly.
+ /// Removed compatibility field. Executable eval policy is server-owned;
+ /// requests that still send this field fail closed.
#[serde(default)]
- eval: Option<ai_memory_consolidate::AutoImproveEvalConfig>,
+ eval: Option<serde_json::Value>,
/// Removed compatibility field. Requests that still send it fail closed so
/// old preview callers cannot accidentally write pages.
#[serde(default)]
@@ -2384,6 +2383,14 @@ async fn handle_auto_improve(
headers: HeaderMap,
Json(req): Json<AutoImproveRequest>,
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
+ if req.eval.is_some() {
+ return Err((
+ StatusCode::UNPROCESSABLE_ENTITY,
+ Json(serde_json::json!({
+ "error": "auto-improve eval request field was removed; configure [auto_improve.eval] on the server"
+ })),
+ ));
+ }
if req.dry_run.is_some() || req.stage.is_some() || req.mode.is_some() {
return Err((
StatusCode::UNPROCESSABLE_ENTITY,
@@ -2430,10 +2437,7 @@ async fn handle_auto_improve(
max_final_body_chars: req.max_final_body_chars,
max_rule_page_tokens: req.max_rule_page_tokens,
max_procedure_page_tokens: req.max_procedure_page_tokens,
- eval: req
- .eval
- .clone()
- .unwrap_or_else(|| state.auto_improve_review_config.eval.clone()),
+ eval: state.auto_improve_review_config.eval.clone(),
};
let report =
@@ -11711,7 +11715,7 @@ mod tests {
}
#[tokio::test]
- async fn auto_improve_admin_omitted_eval_inherits_server_defaults() {
+ async fn auto_improve_admin_refuses_request_eval_and_inherits_server_defaults() {
let tmp = TempDir::new().unwrap();
let store = Store::open(tmp.path()).unwrap();
let wiki = Wiki::new(tmp.path(), store.writer.clone())
@@ -11771,6 +11775,44 @@ mod tests {
};
let router = admin_router(state);
+ let rejected = router
+ .clone()
+ .oneshot(
+ Request::builder()
+ .method("POST")
+ .uri("/admin/auto-improve")
+ .header("content-type", "application/json")
+ .body(Body::from(
+ serde_json::to_vec(&serde_json::json!({
+ "workspace": "default",
+ "project": "scratch",
+ "session_id": session_id.to_string(),
+ "min_observations": 1,
+ "min_session_duration_secs": 0,
+ "min_confidence": 0.75,
+ "max_proposals_per_run": 5,
+ "eval": {
+ "enabled": true,
+ "command": tmp.path().join("request-controlled-program").display().to_string(),
+ "timeout_secs": 1,
+ "targets": ["notes"],
+ "min_delta": 0.0
+ }
+ }))
+ .unwrap(),
+ ))
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(rejected.status(), StatusCode::UNPROCESSABLE_ENTITY);
+ let body = to_bytes(rejected.into_body(), usize::MAX).await.unwrap();
+ let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
+ assert_eq!(
+ json["error"],
+ "auto-improve eval request field was removed; configure [auto_improve.eval] on the server"
+ );
+
let resp = router
.oneshot(
Request::builder()
diff --git a/docs/auto-improve-eval-gates.md b/docs/auto-improve-eval-gates.md
index cf73c612..5609cc56 100644
--- a/docs/auto-improve-eval-gates.md
+++ b/docs/auto-improve-eval-gates.md
@@ -19,6 +19,12 @@ The command is split on whitespace and executed directly, not through a shell.
Use a wrapper script if you need quoting, environment setup, or multiple
commands.
+The eval policy is owned by the server process. `ai-memory auto-improve` and
+direct HTTP requests cannot replace the configured command, targets, timeout,
+or score threshold. When a CLI talks to a remote server, configure
+`[auto_improve.eval]` in that server's config; older clients that send an
+`eval` request field receive `422 Unprocessable Entity` and must be upgraded.
+
## Request contract
The scorer receives one JSON object on stdin:
diff --git a/docs/auto-improvement-loop.md b/docs/auto-improvement-loop.md
index 465ef1be..aa8d14ce 100644
--- a/docs/auto-improvement-loop.md
+++ b/docs/auto-improvement-loop.md
@@ -235,7 +235,8 @@ timeouts, invalid JSON, `passed = false`, missing `passed`, or score deltas belo
`min_delta` reject only that targeted proposal. Non-targeted proposals bypass the
gate. If all proposals fail eval, the run is still staged with zero proposals and
the rejected candidates so the rejection buffer can remember the failed attempt.
-Hooks never run the eval command. See
+The server owns this executable policy: neither the CLI nor a direct admin
+request can replace it. Hooks never run the eval command. See
[`auto-improve-eval-gates.md`](auto-improve-eval-gates.md) for the full stdin /
stdout contract and example scorer scripts.
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index 1782316a..512c4114 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -65,6 +65,7 @@ means the boundary is not built yet.
| 7b | New public page metadata is bounded and cannot supply scope, author or admission controls; admin kind retains its legacy adapter | `ai-memory-core/src/page.rs` `PageWriteMetadata::into_frontmatter`; MCP validates all four fields; admin consumes legacy kind explicitly and shares entities/abstract/relations validation before scope creation; both use `Wiki::write_page` for sanitization/admission/authenticated attribution | `admin_write_page.rs` `write_page_metadata_rejects_invalid_payload_before_scope_creation` (invalid shapes, unknown relation kinds, raw-input over-limit values, untrimmed relation scopes and escaping paths refused; legitimate control admitted), `write_page_metadata_preserves_admin_auth_and_sanitization` (anonymous/DB-user refused, root control admitted with scrubbed metadata and authenticated attribution); `server.rs` `memory_write_page_metadata_rejects_invalid_before_scope_creation`, `memory_write_page_metadata_preserves_scope_author_and_sanitization` (foreign user denied; writer control admitted, forged frontmatter/author ignored, secrets scrubbed, invalid rewrite leaves disk and SQL latest unchanged); core `page_write_metadata_scope_components_refuse_surrounding_whitespace` and `page_write_metadata_limits_apply_before_trimming_and_normalization`; admin `write_page_metadata_admin_legacy_kind_matches_base` compares long/control-character kind behavior with the base adapter; entity-bound refusal bite-checked with its validation removed | STRONG |
| 7c | A compaction checkpoint cannot bypass `consolidate` admission by deferring its provider rewrite (#1229) | `ai-memory-hooks/src/router.rs` `write_checkpoint_page` gives the PreCompact / PostCompaction rule-based write the `consolidate` admission operation whenever a consolidator is configured, and `process_authorized` queues the durable rewrite only after that write succeeds; the worker's rewrite runs admission again through `Consolidator::consolidate_session` | `router.rs` `checkpoint_admission_refusal_writes_no_page_and_queues_no_rewrite` (a policy refusing `consolidate` leaves no page and no queued job; control: a policy gating only `handoff_begin` writes the page and queues the job), `checkpoint_preserves_the_consolidate_admission_operation` (the hook path sends exactly one `consolidate` admission call and never calls the provider); both bite-checked with the admission context removed | STRONG |
| 7d | The Cursor Agent CLI child, which reads captured session text, never sees the server's own credentials | `ai-memory-llm/src/cursor_agent.rs` `complete_text` spawns `agent` with `env_clear()` plus `CursorAuth::child_env`, which `CursorAuth::new` filters through `cursor_child_env` (an allowlist of `PATH`/`HOME`/user, locale, temp/XDG, session bus, proxy/CA and Windows basics, plus `LC_*`/`CURSOR_*`); the environment and the workspace root are captured once by `ai-memory-cli/src/config.rs` `Config::cursor_auth`, so the provider reads no environment itself; a relative workspace root is refused | `cursor_provider.rs` `the_child_gets_only_the_allowlisted_environment` (`AI_MEMORY_AUTH_TOKEN` and `OPENAI_API_KEY` canaries and the test process's own `CARGO_*` variables never reach the child; control: `PATH`, `HOME` and `CURSOR_API_KEY` do, and the workspace sits under the injected root; bite-checked by dropping `env_clear()`), `a_relative_workspace_root_is_refused`; `config.rs` `cursor_provider_hands_the_child_only_allowlisted_env` | STRONG |
+| 7e | Executable auto-improvement eval policy is server-owned | `ai-memory-mcp/src/admin.rs` retains the legacy request `eval` key only as a rejected compatibility field and builds `AutoImproveReviewConfig.eval` exclusively from `AdminState`; `ai-memory-cli/src/commands/auto_improve.rs` sends no executable policy over HTTP | MCP `auto_improve_admin_refuses_request_eval_and_inherits_server_defaults` sends a request-controlled program path and receives 422, then omits the field and proves the configured server gate still runs | STRONG |
| 8a | Messaging: recipient-only visibility | `ai-memory-store/src/ops.rs` pop target-select + `reader.rs` `list_messages` (`to_*` predicate) | `agent_messages.rs` `a_message_is_only_visible_to_its_recipient`; `agent_messages_tools.rs` non-recipient cannot pop | STRONG |
| 8b | Messaging: cancel-own-only | `ai-memory-store/src/ops.rs` `cancel_messages` (AND-gated on `from_*` sender coordinate) | `agent_messages.rs` — whole-outbox **and** a foreign **specific-id** cancel refused | STRONG |
| 8c | Messaging: pop-exactly-once | `ai-memory-store/src/ops.rs` `pop_message_in_transaction` atomic CAS `WHERE state='pending'` | `agent_messages.rs` — sequential **and** `tokio::join!` concurrent double-pop yields exactly one `Some` | STRONG |