{"record":{"id":"5b98c38fe5877576","repo":"astrid-runtime/astrid","slug":"cannot-remove-capsule-authority-while-an-install-t","errorCode":null,"errorMessage":"cannot remove capsule authority while an install transaction is pending at {}","messagePattern":"cannot remove capsule authority while an install transaction is pending at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-capsule-install/src/authority.rs","lineNumber":326,"sourceCode":"    }\n    #[cfg(not(unix))]\n    {\n        std::fs::metadata(directory)\n            .with_context(|| format!(\"inspect authority directory {}\", directory.display()))?;\n    }\n    Ok(())\n}\n\n/// Remove the authority state for an uninstalled capsule.\n///\n/// # Errors\n///\n/// Returns an error when an install transaction is pending or receipt cleanup\n/// fails.\npub fn remove_installed_authority(home: &AstridHome, target_dir: &Path) -> anyhow::Result<()> {\n    let paths = authority_paths(home, target_dir)?;\n    if paths.pending.exists() {\n        bail!(\n            \"cannot remove capsule authority while an install transaction is pending at {}\",\n            paths.pending.display()\n        );\n    }\n    for path in [paths.active, paths.previous] {\n        match std::fs::remove_file(&path) {\n            Ok(()) => {},\n            Err(error) if error.kind() == std::io::ErrorKind::NotFound => {},\n            Err(error) => {\n                return Err(error).with_context(|| {\n                    format!(\"failed to remove authority receipt {}\", path.display())\n                });\n            },\n        }\n    }\n    Ok(())\n}\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-capsule-install/src/authority.rs#L308-L344","documentation":"remove_installed_authority refuses to delete the active/previous authority receipt files while a pending install transaction marker exists. The library treats the pending marker as proof an install (stage->commit) may be interrupted, so removing authority files first could leave the capsule without a recoverable authority record. It is a deliberate safety interlock against destructive cleanup during an in-flight update.","triggerScenarios":"Calling remove_installed_authority(home, target_dir) when the authority_paths(home, target_dir)?.pending file exists — i.e. AuthorityReceiptTransaction::stage was run but commit/receipt cleanup did not finish.","commonSituations":"A previous capsule install or update was interrupted (crash, kill, power loss) leaving the pending marker; automated cleanup scripts run concurrently with an in-progress install; stale pending files after a failed commit.","solutions":["Inspect and finish or roll back the interrupted install transaction (call commit or resolve the pending receipt) before removing authority","Verify the capsule is not currently being installed by another process, then delete the pending file at the path shown in the message and retry","If the pending marker is confirmed stale, remove it manually with fs::remove_file and re-run remove_installed_authority"],"exampleFix":"// before\nremove_installed_authority(&home, &target_dir)?;\n// after\nlet pending = target_dir.join(\"authority\").join(\"pending\");\nif pending.exists() {\n    AuthorityReceiptTransaction::inspect(&home, &target_dir)?; // resolve/commit first\n}\nremove_installed_authority(&home, &target_dir)?;","handlingStrategy":"validation","validationCode":"let pending = authority_pending_path(&home, &target_dir);\nif pending.exists() {\n    return Err(anyhow!(\"resolve pending install transaction at {} first\", pending.display()));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check for a pending transaction file before any authority cleanup","Run installs and cleanup from a single serialized process per capsule directory","Treat pending markers as state to resolve, not garbage to delete blindly"],"tags":["capsule","install-transaction","state-conflict","rust"],"backgroundTag":"invalid-state-transition","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"}