{"record":{"id":"bcf3aa85d4622bea","repo":"astrid-runtime/astrid","slug":"remove-durable-capsule-package-id-error","errorCode":null,"errorMessage":"remove durable capsule package '{id}': {error}","messagePattern":"remove durable capsule package '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/lib.rs","lineNumber":3273,"sourceCode":"            .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}\"\n                ));\n            },\n        };\n        if !removed {\n            // A concurrent administrative writer won the generation race. The\n            // durable package is still authoritative; restore the just-closed\n            // runtime view before surfacing the conflict.\n            self.ensure_principal_loaded(principal).await;\n            return Err(anyhow::anyhow!(\n                \"durable capsule package '{id}' disappeared during removal\"\n            ));\n        }\n        Ok(true)\n    }\n\n    #[cfg(target_family = \"wasm\")]\n    pub(crate) async fn remove_one_capsule(","sourceCodeStart":3255,"sourceCodeEnd":3291,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/lib.rs#L3255-L3291","documentation":"Thrown in `remove_one_capsule` when `store.capsules().remove(&owner, id)` returns an `Err` after the live view was already unloaded. Before returning the error the kernel calls `ensure_principal_loaded(principal)` to restore the runtime view, since the durable package is still authoritative and must not be left unloaded.","triggerScenarios":"The durable delete mutation fails: storage backend write error, generation check rejects the delete, lock contention, or the record changed state between the snapshot read and the remove call.","commonSituations":"Concurrent administrative operations on the same capsule; storage backend transient failure during write; read-only or degraded replica receiving the delete.","solutions":["Read the wrapped backend error to identify the write failure; fix storage health/permissions and retry.","Avoid concurrent admin mutations of the same capsule; serialize removals per principal.","Verify the live view was restored (ensure_principal_loaded ran) before retrying, to avoid a runtime without its registry source."],"exampleFix":"// before: remove while another admin task mutates the same capsule\njoin!(admin.remove(id), other.remove(id));\n// after: serialize per principal\nlet _guard = removal_lock_for(&principal).lock().await;\nadmin.remove_one_capsule(&id, &principal).await?;","handlingStrategy":"retry","validationCode":"fn store_writable(store: &Store) -> bool { !store.is_read_only() && store.health_check().is_ok() }","typeGuard":null,"tryCatchPattern":"match kernel.remove_one_capsule(&id, &principal).await {\n    Err(e) if is_transient_write_error(&e) => {\n        // live view was restored by the kernel; safe to retry after backoff\n        tokio::time::sleep(BACKOFF).await;\n    },\n    other => other?,\n}","preventionTips":["Serialize administrative mutations per principal/capsule with a lock.","Confirm storage replicas accept writes before scheduling deletes.","After a failure, verify the live view is reloaded before retrying."],"tags":["rust","storage","concurrency","kernel"],"backgroundTag":"database-write-failed","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"}