Skip to content

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

Rust

test(mcp): make the pending-write 404 tests reach the changed path

AkitaOnRailsca906eb6d1b3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 18de8a42..58c6be75 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,18 +32,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`workdir` points at another project, is no longer judged only by the
destination's policy. (#1199)
-- `POST /admin/pending-writes/{id}/approve` and `/reject` now answer
- `404 Not Found` when the id does not exist or belongs to a
- different workspace, matching the `/detail` and `/diff` routes.
- Previously an unknown id surfaced as `500 Internal Server Error`
- because the routes skipped the lookup and let the wiki method
- surface a generic error. Approve and reject now share the same
- `pending_detail` helper the detail and diff routes use, so all
- four routes agree on `400` for an unparsable id, `404` for an
- unknown or foreign-scope id, and `500` only for unexpected
- internal errors. Six new tests in `admin::tests` cover the
- four unknown / foreign / unparsable / happy-path combinations
- for both `approve` and `reject`. (#1205)
+- `POST /admin/pending-writes/{id}/approve` and `/reject` answered
+ `500 Internal Server Error` for an id that did not exist or belonged
+ to a different workspace, because the routes skipped the lookup and
+ let the wiki method surface a generic error. They now share the same
+ `pending_detail` helper the `/detail` and `/diff` routes already used,
+ so all four routes agree on `400` for an unparsable id, `404` for an
+ unknown or foreign-scope id, and `500` only for unexpected internal
+ errors. New tests in `admin::tests` cover the unknown, foreign-scope,
+ and unparsable cases for both `approve` and `reject`. (#1205)
## [2.6.3] - 2026-10-09
diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rs
index a7c5d7d3..a62aac07 100644
--- a/crates/ai-memory-mcp/src/admin.rs
+++ b/crates/ai-memory-mcp/src/admin.rs
@@ -12168,9 +12168,14 @@ mod tests {
let wiki = Wiki::new(tmp.path(), store.writer.clone())
.unwrap()
.with_store_reader(store.reader.clone());
- // No `stage_pending_write` call: the DB is empty, the id is
- // brand-new. Approve must surface it as a 404, not a 500.
+ // The requested scope must exist, or the scope lookup itself 404s
+ // and the test never reaches the proposal lookup this regression
+ // is about. Stage an unrelated write so `default/scratch` resolves.
+ let (_ws, _proj, _staged_id) =
+ stage_pending_write(&store, "default", "scratch", "notes/other.md", "# Other\n").await;
let router = admin_router(admin_state_for_store(&tmp, &store, wiki));
+ // The requested id is brand-new: no proposal carries it. Approve
+ // must surface that as a 404, not a 500.
let unknown_id = AutoImproveProposalId::new();
let resp = router
@@ -12205,6 +12210,10 @@ mod tests {
let wiki = Wiki::new(tmp.path(), store.writer.clone())
.unwrap()
.with_store_reader(store.reader.clone());
+ // Same fixture need as approve: the requested scope must exist so
+ // the request reaches the proposal lookup.
+ let (_ws, _proj, _staged_id) =
+ stage_pending_write(&store, "default", "scratch", "notes/other.md", "# Other\n").await;
let router = admin_router(admin_state_for_store(&tmp, &store, wiki));
let unknown_id = AutoImproveProposalId::new();
@@ -12255,6 +12264,11 @@ mod tests {
",
)
.await;
+ // The requested scope must also exist: without it the scope lookup
+ // 404s first and the test never reaches the proposal lookup that
+ // #1205 is about.
+ let (_ws_default, _proj_default, _own_id) =
+ stage_pending_write(&store, "default", "scratch", "notes/own.md", "# Own\n").await;
let router = admin_router(admin_state_for_store(&tmp, &store, wiki));
// Try to approve it as if it lived in `default`. The lookup must
@@ -12299,6 +12313,11 @@ mod tests {
"# Foreign\n",
)
.await;
+ // The requested scope must also exist: without it the scope lookup
+ // 404s first and the test never reaches the proposal lookup that
+ // #1205 is about.
+ let (_ws_default, _proj_default, _own_id) =
+ stage_pending_write(&store, "default", "scratch", "notes/own.md", "# Own\n").await;
let router = admin_router(admin_state_for_store(&tmp, &store, wiki));
let resp = router
@@ -12321,9 +12340,8 @@ mod tests {
)
.await
.unwrap();
- // Note: a reject that targets the *real* workspace must be 404 too
- // for symmetry (no reject of a foreign id via the foreign scope
- // either). This exercises the same lookup path from the other side.
+ // Legitimate control: rejecting the id through its own scope must
+ // still succeed, so the 404 below cannot be a blanket deny.
assert_eq!(
resp.status(),
StatusCode::OK,
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index 4cf48719..f294f666 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -33,7 +33,7 @@ means the boundary is not built yet.
| 2 | Workspace isolation | same as #1; same-named project → distinct ids per workspace | `scope.rs` cross-workspace resolution rows; `multi_scope` dedup/validate | STRONG |
| 2b | Managed-workstream discovery stays checkout-local, including pagination | `ai-memory-workstream/src/repository.rs` `inspect_repository_fingerprints` shares the launch identity derivation without checkpoint scans; `ai-memory-cli/src/commands/resume.rs` `candidates_for_checkout` queries only the cwd, never registry links; the explicit `--all` walk (`candidates_across_checkouts`) lists each linked checkout through its own fingerprint-scoped request and applies `--workspace` before any request; `ai-memory-hooks/src/workstream.rs` `list_recent_workstreams` resolves an authorized explicit scope on every page; `ai-memory-store/src/workstream.rs` `list_recent` applies workspace/project/repository/worktree predicates before `LIMIT`/`OFFSET` | `resume.rs` `resume_lists_all_current_checkout_rows_not_registered_foreign_checkouts` (same scope/remote foreign checkout refused, 125 local rows visible), `empty_current_checkout_does_not_fall_back_to_the_registry`, `resume_all_walks_every_linked_checkout_and_honours_the_workspace_filter` (a foreign workspace filter sends no request; the default picker still ignores the registry); `workstream.rs` `recent_workstream_pages_reach_older_rows_without_crossing_checkout_or_scope` (foreign repo, worktree, project and workspace excluded on every page; 105 legitimate rows reach the client, huge offsets return nothing); store `recent_workstreams_are_checkout_local_and_include_linked_harnesses` (page two keeps native harness links); `repository.rs` `reports_origin_push_url_and_linked_worktree` verifies lightweight/full fingerprint parity and distinct worktree keys; CLI `resume_yolo_displays_picker_without_scanning_git_status` verifies listing skips status scans | STRONG |
| 3 | Multi-user auth ladder | `ai-memory-core/src/actor.rs` `AuthLevel::authorize`; `ai-memory-mcp/src/auth.rs` middleware; `admin.rs` `require_root_for_multiuser_admin` / `require_root`; `identity.rs` authorizes `NormalRead` behind the same machine bearer middleware as MCP; `serve.rs` mounts API-only and web+API protected routers behind `require_dual_auth` | `admin.rs` `multiuser_admin_routes_reject_db_user_tier` / `…reject_anonymous` / `create_user_as_user_tier_returns_403`; `auth.rs` unknown-bearer 401; `actor.rs` `skip_admission_chain_rejects_db_users`; `identity.rs` `identity_real_auth_isolates_users_root_and_revoked_keys`, `identity_anonymous_ignores_forged_headers_and_proxy_qualifies_oidc` (distinct users and root, invalid/revoked keys, forged headers, anonymous control); `serve.rs` `api_only_mode_keeps_data_authenticated_and_web_absent` (anonymous API read refused, authenticated control admitted, browser route absent; #986) | STRONG |
-| 3b | Browser triage of pending writes (#855) | `ai-memory-web/src/routes/pending.rs` `require_admin` (`AuthLevel::authorize(Capability::Admin, distinguishes_operators)`, trusted-proxy flag from `WebMountSpec`) gates `GET {web_slug}/pending`; `html_auth.rs` `AdminRequired` keeps a non-root 403 off the change-password redirect; decisions post to the existing `/admin/pending-writes/{id}/approve\|reject` behind `require_dual_auth` (session + CSRF) and `require_root_for_multiuser_admin`. `ai-memory-web` has no write route | `ai-memory-web` `tests/suite/pending.rs` — anonymous refused (401, login redirect), DB user refused (403, no proposal text, no redirect), trusted-proxy flag reaches the gate, single-operator control admits, POSTs to `/pending*` refused, project filter keys do not collide on `/` in names, projects past the 500-row read cap stay counted and reachable; `ai-memory-mcp` `tests/suite/admin_pending_writes_session.rs` — anonymous and DB-user sessions refused, root session without a matching CSRF header refused (each leaves the proposal pending and no file), root approval keeps `auto_improve_proposal_id`/`auto_improve_run_id` and records the approver, root reject writes no file (each proven to fail with its guard removed) | STRONG |
+| 3b | Browser triage of pending writes (#855) | `ai-memory-web/src/routes/pending.rs` `require_admin` (`AuthLevel::authorize(Capability::Admin, distinguishes_operators)`, trusted-proxy flag from `WebMountSpec`) gates `GET {web_slug}/pending`; `html_auth.rs` `AdminRequired` keeps a non-root 403 off the change-password redirect; decisions post to the existing `/admin/pending-writes/{id}/approve\|reject` behind `require_dual_auth` (session + CSRF) and `require_root_for_multiuser_admin`. `ai-memory-web` has no write route | `ai-memory-web` `tests/suite/pending.rs` — anonymous refused (401, login redirect), DB user refused (403, no proposal text, no redirect), trusted-proxy flag reaches the gate, single-operator control admits, POSTs to `/pending*` refused, project filter keys do not collide on `/` in names, projects past the 500-row read cap stay counted and reachable; `ai-memory-mcp` `tests/suite/admin_pending_writes_session.rs` — anonymous and DB-user sessions refused, root session without a matching CSRF header refused (each leaves the proposal pending and no file), root approval keeps `auto_improve_proposal_id`/`auto_improve_run_id` and records the approver, root reject writes no file (each proven to fail with its guard removed); `ai-memory-mcp` `admin.rs` `pending_write_approve_foreign_scope_returns_404` and `pending_write_reject_foreign_scope_returns_404` — an id staged in workspace `alpha` requested through an existing `default` scope is 404 (never approved or rejected across the boundary), with the in-scope reject as the legitimate control (each proven to fail with 500 with the `pending_detail` guard removed, #1205) | STRONG |
| 4 | Handoff single-claim / no-steal | `ai-memory-store/src/ops.rs` `accept_handoff_in_transaction` (metadata `state='open'` guard + atomic CAS) | `multi_session.rs` `a_second_accept_cannot_steal_an_accepted_handoff`; `handoff_ownership.rs` `another_operator_cannot_claim_the_handoff` | STRONG |
| 4b | Handoff owner-scoped recovery (`any_owner` admin gate) | `ai-memory-mcp/src/server.rs` `require_admin_capability` on `memory_handoff_accept`/`_cancel` `any_owner` | `handoff_admission.rs` — cancel gate + **accept gate** (adversarial: non-admin `any_owner` accept refused) | STRONG |
| 4c | Turn-checkpoint baton is owner+scope-bound | `ai-memory-store/src/ops.rs` `checkpoint_session_handoff` — reads the session's own `(workspace, project, owner_user)` from `sessions WHERE id=?1 AND ended_at IS NULL`, refuses on scope/owner mismatch, refreshes only that session's own `state='open'` baton (id preserved), returns `None` when the session already ended | `ops.rs` `checkpoint_session_handoff_refreshes_only_the_live_sessions_own_baton` (#865) | STRONG |