{"record":{"id":"c4fbe2414787710c","repo":"astrid-runtime/astrid","slug":"resolve-durable-owner-for-principal-error","errorCode":null,"errorMessage":"resolve durable owner for {principal}: {error}","messagePattern":"resolve durable owner for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/lib.rs","lineNumber":3256,"sourceCode":"    ///\n    /// # Errors\n    ///\n    /// Returns an error when the durable store or owner mapping is unavailable,\n    /// the registry mutation fails, or the live view cannot be unloaded.\n    #[cfg(not(target_family = \"wasm\"))]\n    pub(crate) async fn remove_one_capsule(\n        &self,\n        id: &astrid_capsule_types::CapsuleId,\n        principal: &PrincipalId,\n    ) -> Result<bool, anyhow::Error> {\n        let store = self\n            .principal_store\n            .clone()\n            .ok_or_else(|| anyhow::anyhow!(\"authoritative principal store is unavailable\"))?;\n        let uid = self\n            .principal_directory\n            .uid_for(principal)\n            .map_err(|error| anyhow::anyhow!(\"resolve durable owner for {principal}: {error}\"))?;\n        let owner = astrid_storage::StateOwner::Principal(uid);\n        let snapshot = store\n            .capsules()\n            .get_snapshot(&owner, id.as_str())\n            .map_err(|error| anyhow::anyhow!(\"read durable capsule package '{id}': {error}\"))?;\n        if snapshot.is_none() {\n            return Ok(false);\n        }\n        // Quiesce and unload before deleting the durable package. If unload\n        // fails, the package remains authoritative and can be retried on the\n        // next request; no live runtime is left without its registry source.\n        let _ = self.unload_one_capsule(id, principal).await?;\n        let removed = match store.capsules().remove(&owner, id.as_str()) {\n            Ok(removed) => removed,\n            Err(error) => {\n                self.ensure_principal_loaded(principal).await;\n                return Err(anyhow::anyhow!(\n                    \"remove durable capsule package '{id}': {error}\"","sourceCodeStart":3238,"sourceCodeEnd":3274,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/lib.rs#L3238-L3274","documentation":"Thrown in `remove_one_capsule` when `principal_directory.uid_for(principal)` fails, i.e. the principal cannot be mapped to a durable owner UID. The kernel needs this mapping to locate the capsule package under the right `StateOwner::Principal(uid)` in the store; without it removal cannot proceed safely.","triggerScenarios":"`principal_directory.uid_for()` returns an error for the given `PrincipalId` — the principal is unknown to the directory, the directory backend is unavailable, or the identity mapping is stale after a re-provisioning.","commonSituations":"Deleting a capsule for a principal whose account was just deleted or rotated; a directory service outage mid-admin-operation; identity migration leaving old PrincipalIds unresolvable.","solutions":["Verify the principal exists and is registered in the principal directory before attempting removal.","Check directory backend connectivity/health; retry once connectivity is restored.","Re-sync or rebuild the principal directory mapping if identities were migrated."],"exampleFix":"// before: assume principal resolvable\nkernel.remove_one_capsule(&id, &principal).await?;\n// after: verify mapping first\nif principal_directory.uid_for(&principal).is_err() {\n    anyhow::bail!(\"principal {principal} is not registered; cannot remove capsule\");\n}\nkernel.remove_one_capsule(&id, &principal).await?;","handlingStrategy":"validation","validationCode":"fn principal_is_known(dir: &PrincipalDirectory, p: &PrincipalId) -> bool { dir.uid_for(p).is_ok() }","typeGuard":null,"tryCatchPattern":"match kernel.remove_one_capsule(&id, &principal).await {\n    Err(e) if e.to_string().starts_with(\"resolve durable owner\") => {\n        error!(\"principal {principal} not in directory; re-register before delete\");\n    },\n    other => other?,\n}","preventionTips":["Verify the principal is registered in the directory before admin operations.","Monitor directory backend health and alert on resolution failures.","Re-sync directory mappings after identity migrations."],"tags":["rust","identity","storage","kernel"],"backgroundTag":"entity-not-found","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}