Skip to content

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

Rust

fix(profile): keep admin reorg away from reserved scopes; note marker-follow semantics

AkitaOnRailsebc2c967bc92
diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rs
index a50d1b4f..388723a3 100644
--- a/crates/ai-memory-mcp/src/admin.rs
+++ b/crates/ai-memory-mcp/src/admin.rs
@@ -3444,6 +3444,11 @@ async fn build_reorg_plan(
.filter(|s| !s.is_empty())
.map(str::to_string)
.unwrap_or_else(|| "unknown".to_string());
+ // Capture never attributes to a reserved scope; a reorg must not
+ // either, or a directory named like one would create or fill it.
+ if ai_memory_core::profile::is_reserved_scope_project(&project_name) {
+ continue;
+ }
let proj = state
.writer
.get_or_create_project(ws, project_name.clone(), repo_path_from_reorg_cwd(cwd))
@@ -3455,7 +3460,9 @@ async fn build_reorg_plan(
let mut plan_entries: Vec<ReorgPlanEntry> = Vec::new();
let mut writer_plan: Vec<(SessionId, ProjectId)> = Vec::new();
for (session_id, old_project_id, cwd) in &sessions {
- let (_, new_project_id, project_name) = &cwd_to_proj[cwd.as_str()];
+ let Some((_, new_project_id, project_name)) = cwd_to_proj.get(cwd.as_str()) else {
+ continue;
+ };
if *new_project_id == *old_project_id {
continue;
}
diff --git a/crates/ai-memory-mcp/tests/suite/admin_phase3.rs b/crates/ai-memory-mcp/tests/suite/admin_phase3.rs
index 371e4ece..aa42f1b5 100644
--- a/crates/ai-memory-mcp/tests/suite/admin_phase3.rs
+++ b/crates/ai-memory-mcp/tests/suite/admin_phase3.rs
@@ -418,6 +418,60 @@ async fn reorg_dry_run_returns_plan_entries() {
assert!(body["dry_run"].as_bool().unwrap());
}
+/// A cwd named like a reserved scope stays where it is: the reorg neither
+/// moves sessions into `_global` / a profile project nor creates one.
+#[tokio::test]
+async fn reorg_never_targets_a_reserved_scope() {
+ let tmp = TempDir::new().unwrap();
+ let (state, store) = make_state(&tmp).await;
+ let ws = store
+ .writer
+ .get_or_create_workspace("default")
+ .await
+ .unwrap();
+ let scratch = store
+ .writer
+ .get_or_create_project(ws, "scratch", None)
+ .await
+ .unwrap();
+ for dir in [
+ "/home/user/_global",
+ "/home/user/_profile",
+ "/home/user/gamma-repo",
+ ] {
+ store
+ .writer
+ .begin_session(NewSession {
+ occurred_at: None,
+ id: SessionId::new(),
+ workspace_id: ws,
+ project_id: scratch,
+ agent_kind: AgentKind::ClaudeCode,
+ cwd: Some(std::path::PathBuf::from(dir)),
+ actor_user: None,
+ })
+ .await
+ .unwrap();
+ }
+
+ let resp = post(state, "/admin/reorg", json!({ "dry_run": false })).await;
+ assert_eq!(resp.status(), StatusCode::OK);
+ let body = body_json(resp).await;
+ assert_eq!(
+ body["summary"]["sessions_moved"].as_u64().unwrap(),
+ 1,
+ "only the ordinary cwd moves: {body}"
+ );
+ let scopes = store.reader.list_all_scopes().await.unwrap();
+ assert!(
+ scopes
+ .iter()
+ .all(|s| s.project_name != "_profile" && s.project_name != "_global"),
+ "reorg must not create a reserved project: {scopes:?}"
+ );
+ assert!(scopes.iter().any(|s| s.project_name == "gamma-repo"));
+}
+
#[tokio::test]
async fn reorg_live_moves_sessions() {
let tmp = TempDir::new().unwrap();
diff --git a/docs/cross-project-profile.md b/docs/cross-project-profile.md
index 2cd30811..0fb1dcf4 100644
--- a/docs/cross-project-profile.md
+++ b/docs/cross-project-profile.md
@@ -341,7 +341,12 @@ them on the project, so they apply to every harness. Removing the key from the
marker turns the setting back on at the next session start. A session start
that sends no value at all (no marker found, an older hook bundle, a client not
yet regenerated) leaves the recorded setting as it is: an opt-out is never
-undone by a client that did not say anything. A marker that sets only `[profile]` keys is a settings boundary, like one
+undone by a client that did not say anything. The recorded value follows the
+marker of the most recent session start, so keep the setting in the marker every
+checkout of the project shares (two checkouts whose markers disagree flip it
+back and forth).
+
+A marker that sets only `[profile]` keys is a settings boundary, like one
that sets `[briefing]` keys: an outer marker's `workspace`/`project` do not
apply through it. `ai-memory profile status` lists the projects that opted out
of contributing.