Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(scope): name the workspace when a write hits an ambiguous project
Rudy Celekli57933cce51e0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0736de97..33174162 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,6 +19,12 @@ version in [`docs/changelog/`](docs/changelog/):nothing here calls, and the `cargo-deny` gate failed on every pull requestfrom the moment the advisory was assigned (#1658).+- A write that names an ambiguous project now reports the workspace it was+ resolved in. The refusal read "project 'api' is ambiguous in workspace 'the+ resolved workspace'" on the write path (`ai-memory run`, explicit MCP+ writes, profile writes), while the read path already named the workspace+ (#1657).+- `ai-memory user list` and `ai-memory api-key list` now size their columnsby terminal display width rather than bytes, as `list-projects` and thegrants tables already do. An accented username, display name or key labeldiff --git a/crates/ai-memory-store/src/scope.rs b/crates/ai-memory-store/src/scope.rsindex 3bf741bf..ee885d8a 100644--- a/crates/ai-memory-store/src/scope.rs+++ b/crates/ai-memory-store/src/scope.rs@@ -555,7 +555,8 @@ pub async fn create_explicit_scope_guarded(let _ = reader;refuse_foreign_profile_name(Some(workspace), project, viewer)?;let workspace_id = writer.get_or_create_workspace(workspace.to_owned()).await?;- create_project_in_workspace_guarded(writer, workspace_id, project, viewer, true).await+ create_project_in_workspace_guarded(writer, workspace_id, workspace, project, viewer, true)+ .await}/// Refusal for an explicit write that names a profile project it does not own.@@ -594,9 +595,11 @@ fn refuse_foreign_profile_name(}/// [`create_explicit_scope_guarded`] for a workspace already resolved by id.+/// `workspace` is that workspace's name, used only in error messages.async fn create_project_in_workspace_guarded(writer: &WriterHandle,workspace_id: WorkspaceId,+ workspace: &str,project: &str,viewer: Option<UserId>,promote: bool,@@ -621,7 +624,7 @@ async fn create_project_in_workspace_guarded().await}- .map_err(|error| project_lookup_error(error, "the resolved workspace", project))?;+ .map_err(|error| project_lookup_error(error, workspace, project))?;let scope = ResolvedScope {workspace_id,project_id: resolved.project_id,@@ -713,7 +716,7 @@ pub async fn lookup_profile_scope(/// private profile is requested without a database user; store failures/// otherwise.pub async fn create_profile_scope(- _reader: &ReaderPool,+ reader: &ReaderPool,writer: &WriterHandle,share: ai_memory_core::profile::EffectiveProfileShare,workspace_id: WorkspaceId,@@ -728,6 +731,7 @@ pub async fn create_profile_scope(create_project_in_workspace_guarded(writer,workspace_id,+ ai_memory_core::DEFAULT_WORKSPACE_NAME,ai_memory_core::GLOBAL_SCOPE_PROJECT,viewer,false,@@ -735,15 +739,22 @@ pub async fn create_profile_scope(.await.map(|resolved| resolved.scope)}- EffectiveProfileShare::Workspace => create_project_in_workspace_guarded(- writer,- workspace_id,- WORKSPACE_PROFILE_PROJECT,- viewer,- false,- )- .await- .map(|resolved| resolved.scope),+ EffectiveProfileShare::Workspace => {+ let workspace = reader+ .workspace_name_by_id(workspace_id)+ .await?+ .unwrap_or_else(|| workspace_id.to_string());+ create_project_in_workspace_guarded(+ writer,+ workspace_id,+ &workspace,+ WORKSPACE_PROFILE_PROJECT,+ viewer,+ false,+ )+ .await+ .map(|resolved| resolved.scope)+ }EffectiveProfileShare::User => {let Some(viewer) = viewer else {return Err(ScopeResolutionError::Forbidden(@@ -756,6 +767,7 @@ pub async fn create_profile_scope(create_project_in_workspace_guarded(writer,workspace_id,+ ai_memory_core::DEFAULT_WORKSPACE_NAME,&ai_memory_core::profile::user_profile_project(viewer),Some(viewer),false,diff --git a/crates/ai-memory-store/tests/suite/identity_resolution.rs b/crates/ai-memory-store/tests/suite/identity_resolution.rsindex e2f75ded..86068aca 100644--- a/crates/ai-memory-store/tests/suite/identity_resolution.rs+++ b/crates/ai-memory-store/tests/suite/identity_resolution.rs@@ -1646,6 +1646,37 @@ async fn an_ambiguous_name_names_its_holders_but_not_a_restricted_one() {assert!(!error.to_string().contains("acme-widget"));}+#[tokio::test]+async fn an_ambiguous_name_on_the_write_path_names_the_workspace() {+ let tmp = tempfile::TempDir::new().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let ws = workspace(&store).await;+ store+ .writer+ .get_or_create_project(ws, "widget", None)+ .await+ .unwrap();+ resolve_capture(+ &store,+ ws,+ &remote("github.com/acme/widget"),+ IdentityStyle::Path,+ "acme-widget",+ None,+ )+ .await;++ let error =+ create_explicit_scope_guarded(&store.reader, &store.writer, "default", "widget", None)+ .await+ .unwrap_err();+ assert_eq!(+ error.to_string(),+ "project 'widget' is ambiguous in workspace 'default': it is the name of \+ project 'widget' and the legacy key of project 'acme-widget'"+ );+}+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]async fn concurrent_legacy_and_canonical_resolve_or_create_converge_on_one_uuid() {let tmp = tempfile::TempDir::new().unwrap();