From 6f0dbbe935ec315f96cdc25485c497dca119139f Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 25 Nov 2026 11:00:38 -0800 Subject: [PATCH 1/3] fix(server): keep unrelated profiles from superseding provider waits Signed-off-by: Matthew Grossman --- crates/openshell-server/src/grpc/policy.rs | 63 +++++++++++++++++++ .../src/provider_profile_sources.rs | 6 +- docs/how-it-works/providers/profiles.mdx | 2 +- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/crates/openshell-server/src/grpc/policy.rs b/crates/openshell-server/src/grpc/policy.rs index bbf15c92dd..2cbe0a4af0 100644 --- a/crates/openshell-server/src/grpc/policy.rs +++ b/crates/openshell-server/src/grpc/policy.rs @@ -16284,6 +16284,69 @@ mod tests { ); } + #[tokio::test] + async fn provider_env_revision_ignores_unrelated_profile_import_and_delete() { + use crate::grpc::provider::{ + handle_delete_provider_profile, handle_import_provider_profiles, + }; + use openshell_core::proto::{ + DeleteProviderProfileRequest, ImportProviderProfilesRequest, ProviderProfile, + ProviderProfileImportItem, workspace_selector, + }; + + let state = test_server_state().await; + let workspace_scope = Some(workspace_selector("default".to_string())); + let import_profile = async |id: &str| { + let response = handle_import_provider_profiles( + &state, + with_user(Request::new(ImportProviderProfilesRequest { + profiles: vec![ProviderProfileImportItem { + profile: Some(ProviderProfile { + id: id.to_string(), + display_name: id.to_string(), + ..Default::default() + }), + source: format!("{id}.yaml"), + }], + workspace_scope: workspace_scope.clone(), + ..Default::default() + })), + ) + .await + .unwrap() + .into_inner(); + assert!(response.imported, "{:?}", response.diagnostics); + }; + + import_profile("used-profile").await; + state + .store + .put_message(&test_provider("work-provider", "used-profile")) + .await + .unwrap(); + let provider_names = ["work-provider".to_string()]; + let revision = + || compute_provider_env_revision(state.store.as_ref(), "default", &provider_names); + let before = revision().await.unwrap(); + + import_profile("unrelated-profile").await; + let after_import = revision().await.unwrap(); + handle_delete_provider_profile( + &state, + with_user(Request::new(DeleteProviderProfileRequest { + id: "unrelated-profile".to_string(), + workspace_scope, + ..Default::default() + })), + ) + .await + .unwrap(); + let after_delete = revision().await.unwrap(); + + assert_eq!(before, after_import, "unrelated profile import"); + assert_eq!(after_import, after_delete, "unrelated profile delete"); + } + #[tokio::test] async fn provider_env_revision_changes_when_custom_profile_token_grant_changes() { use crate::grpc::provider::handle_update_provider_profiles; diff --git a/crates/openshell-server/src/provider_profile_sources.rs b/crates/openshell-server/src/provider_profile_sources.rs index ab97884e59..7fcf64c4d2 100644 --- a/crates/openshell-server/src/provider_profile_sources.rs +++ b/crates/openshell-server/src/provider_profile_sources.rs @@ -803,7 +803,11 @@ impl EffectiveProviderProfileCatalog { fn hash_scoped_profile_revision(entry: &ScopedProfileEntry, hasher: &mut Sha256) { hasher.update(b"provider-profile-source-entry"); hasher.update(entry.source_id.as_bytes()); - hasher.update(entry.source_revision.as_bytes()); + // Stored profile revisions already live in the entry payload. Hashing the + // whole source snapshot would make unrelated imports supersede waits. + if !entry.user_managed { + hasher.update(entry.source_revision.as_bytes()); + } let scope_tag: &[u8] = match entry.scope { ProfileScope::Static => b"static", ProfileScope::Platform => b"platform", diff --git a/docs/how-it-works/providers/profiles.mdx b/docs/how-it-works/providers/profiles.mdx index 9b083fe05e..a3995a15bf 100644 --- a/docs/how-it-works/providers/profiles.mdx +++ b/docs/how-it-works/providers/profiles.mdx @@ -1364,7 +1364,7 @@ openshell sandbox provider status provider-demo work-github --output json openshell sandbox provider status provider-demo work-github --receipt RECEIPT_ID --wait --timeout 30 ``` -Replace `RECEIPT_ID` with the `receipt_id` returned by attach, detach, or update. The ID always refers to the original change. If a later change replaces it, the status is `superseded` and the wait ends without reporting success. +Replace `RECEIPT_ID` with the `receipt_id` returned by attach, detach, or update. The ID always refers to the original change. If a later change replaces it, the status is `superseded` and the wait ends without reporting success. Importing or deleting an unrelated profile does not supersede the change. If attach, detach, or update reports `CONFIG_OPERATION_STORAGE_UNCERTAIN`, the change may already be saved even though the gateway could not record its readiness receipt. Do not blindly retry the mutation: inspect the provider and sandbox state and reconcile the saved change first. A receipt may be unavailable, so an error does not establish that the mutation was rolled back or that the sandbox is ready. From 659e9be942cadd33b54b8adaa3dfc60723ea5450 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 25 Nov 2026 11:07:18 -0800 Subject: [PATCH 2/3] test(server): simplify provider profile revision regression Signed-off-by: Matthew Grossman --- crates/openshell-server/src/grpc/policy.rs | 86 ++++++++-------------- 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/crates/openshell-server/src/grpc/policy.rs b/crates/openshell-server/src/grpc/policy.rs index 2cbe0a4af0..b9d5fa8fff 100644 --- a/crates/openshell-server/src/grpc/policy.rs +++ b/crates/openshell-server/src/grpc/policy.rs @@ -16286,65 +16286,41 @@ mod tests { #[tokio::test] async fn provider_env_revision_ignores_unrelated_profile_import_and_delete() { - use crate::grpc::provider::{ - handle_delete_provider_profile, handle_import_provider_profiles, - }; - use openshell_core::proto::{ - DeleteProviderProfileRequest, ImportProviderProfilesRequest, ProviderProfile, - ProviderProfileImportItem, workspace_selector, - }; - - let state = test_server_state().await; - let workspace_scope = Some(workspace_selector("default".to_string())); - let import_profile = async |id: &str| { - let response = handle_import_provider_profiles( - &state, - with_user(Request::new(ImportProviderProfilesRequest { - profiles: vec![ProviderProfileImportItem { - profile: Some(ProviderProfile { - id: id.to_string(), - display_name: id.to_string(), - ..Default::default() - }), - source: format!("{id}.yaml"), - }], - workspace_scope: workspace_scope.clone(), - ..Default::default() - })), - ) - .await - .unwrap() - .into_inner(); - assert!(response.imported, "{:?}", response.diagnostics); - }; + use crate::provider_profile_sources::stored_provider_profile; + use openshell_core::proto::ProviderProfile; - import_profile("used-profile").await; - state - .store - .put_message(&test_provider("work-provider", "used-profile")) - .await - .unwrap(); - let provider_names = ["work-provider".to_string()]; - let revision = - || compute_provider_env_revision(state.store.as_ref(), "default", &provider_names); + let store = test_store().await; + let mut provider = test_provider("work-github", "github"); + provider.profile_workspace.clear(); + store.put_message(&provider).await.unwrap(); + let providers = ["work-github".to_string()]; + let revision = || compute_provider_env_revision(&store, "default", &providers); let before = revision().await.unwrap(); - import_profile("unrelated-profile").await; - let after_import = revision().await.unwrap(); - handle_delete_provider_profile( - &state, - with_user(Request::new(DeleteProviderProfileRequest { - id: "unrelated-profile".to_string(), - workspace_scope, - ..Default::default() - })), - ) - .await - .unwrap(); - let after_delete = revision().await.unwrap(); + let mut unrelated = stored_provider_profile(ProviderProfile { + id: "unrelated".to_string(), + display_name: "Unrelated".to_string(), + ..Default::default() + }); + unrelated.metadata.as_mut().unwrap().workspace = "default".to_string(); + store.put_message(&unrelated).await.unwrap(); + assert_eq!( + before, + revision().await.unwrap(), + "unrelated profile import" + ); - assert_eq!(before, after_import, "unrelated profile import"); - assert_eq!(after_import, after_delete, "unrelated profile delete"); + assert!( + store + .delete(StoredProviderProfile::object_type(), unrelated.object_id()) + .await + .unwrap() + ); + assert_eq!( + before, + revision().await.unwrap(), + "unrelated profile delete" + ); } #[tokio::test] From 6c05a294576fd0e1a03ec9053a0a18a368ed0fc0 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 25 Nov 2026 11:14:11 -0800 Subject: [PATCH 3/3] docs(providers): leave wait semantics unchanged Signed-off-by: Matthew Grossman --- docs/how-it-works/providers/profiles.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/how-it-works/providers/profiles.mdx b/docs/how-it-works/providers/profiles.mdx index a3995a15bf..9b083fe05e 100644 --- a/docs/how-it-works/providers/profiles.mdx +++ b/docs/how-it-works/providers/profiles.mdx @@ -1364,7 +1364,7 @@ openshell sandbox provider status provider-demo work-github --output json openshell sandbox provider status provider-demo work-github --receipt RECEIPT_ID --wait --timeout 30 ``` -Replace `RECEIPT_ID` with the `receipt_id` returned by attach, detach, or update. The ID always refers to the original change. If a later change replaces it, the status is `superseded` and the wait ends without reporting success. Importing or deleting an unrelated profile does not supersede the change. +Replace `RECEIPT_ID` with the `receipt_id` returned by attach, detach, or update. The ID always refers to the original change. If a later change replaces it, the status is `superseded` and the wait ends without reporting success. If attach, detach, or update reports `CONFIG_OPERATION_STORAGE_UNCERTAIN`, the change may already be saved even though the gateway could not record its readiness receipt. Do not blindly retry the mutation: inspect the provider and sandbox state and reconcile the saved change first. A receipt may be unavailable, so an error does not establish that the mutation was rolled back or that the sandbox is ready.