{"record":{"id":"61bebb7d736505da","repo":"astrid-runtime/astrid","slug":"workspace-commit-for-capsule-id-failed-e","errorCode":null,"errorMessage":"workspace commit for capsule '{id}' failed: {e}","messagePattern":"workspace commit for capsule '(.+?)' failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/lib.rs","lineNumber":3354,"sourceCode":"    /// (git-managed or No-CoW — nothing to do).\n    pub(crate) async fn commit_workspace_for(\n        &self,\n        id: &astrid_capsule_types::CapsuleId,\n        principal: &PrincipalId,\n        commit: bool,\n    ) -> Result<Option<bool>, anyhow::Error> {\n        let capsule = { self.capsules.read().await.get_for(principal, id) };\n        let Some(capsule) = capsule else {\n            return Ok(None);\n        };\n        let outcome = if commit {\n            capsule.promote_workspace(principal).await\n        } else {\n            capsule.rollback_workspace(principal).await\n        };\n        outcome\n            .map(Some)\n            .map_err(|e| anyhow::anyhow!(\"workspace commit for capsule '{id}' failed: {e}\"))\n    }\n\n    /// Record that a new client connection for `principal` has been established.\n    pub fn connection_opened(&self, principal: &PrincipalId) {\n        self.active_connections\n            .entry(principal.clone())\n            .or_insert_with(|| AtomicUsize::new(0))\n            .fetch_add(1, Ordering::Relaxed);\n        metrics::counter!(METRIC_CONNECTIONS_OPENED_TOTAL).increment(1);\n        metrics::gauge!(METRIC_ACTIVE_CONNECTIONS).increment(1.0);\n    }\n\n    /// Record that a client connection for `principal` has been closed.\n    ///\n    /// Uses `fetch_update` for atomic saturating decrement - avoids the\n    /// TOCTOU window where `fetch_sub` wraps to `usize::MAX` before a\n    /// corrective store.\n    ///","sourceCodeStart":3336,"sourceCodeEnd":3372,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/lib.rs#L3336-L3372","documentation":"Thrown in `commit_workspace_for` when the capsule's copy-on-write workspace promote (commit) or rollback fails. The kernel wraps the underlying workspace error with the capsule id; `Ok(None)` means the capsule was not loaded, so this error only fires for a loaded capsule whose OS-level CoW workspace operation failed.","triggerScenarios":"Gate approve/reject invokes `commit_workspace_for` and `capsule.promote_workspace` or `capsule.rollback_workspace` errors: filesystem failure during the copy-on-write merge/discard (permissions, missing paths, files held open), or the workspace snapshot is in an inconsistent state.","commonSituations":"Files inside the capsule workspace locked by another process at promote time; read-only volume; workspace directory manually altered or deleted between snapshot and commit; disk exhaustion during copy-on-write materialization.","solutions":["Inspect the wrapped source error for the filesystem-level cause (permissions, missing path, busy files).","Close processes holding files in the capsule workspace, then retry the promote/rollback.","If the workspace is inconsistent, reset the workspace (or re-load the capsule) and re-run the gate decision."],"exampleFix":"// before: lose the capsule id context\noutcome?;\n// after: ensure workspace paths are writable and processes closed before commit\nfor path in workspace_paths(&capsule) {\n    let meta = std::fs::metadata(&path)\n        .expect(\"workspace path must exist before commit\");\n    assert!(!meta.permissions().readonly(), \"workspace must be writable\");\n}\nkernel.commit_workspace_for(&id, &principal, true).await?;","handlingStrategy":"try-catch","validationCode":"fn workspace_ready(capsule: &Capsule) -> bool {\n    capsule.workspace_paths().iter().all(|p| p.exists() && !p.metadata().unwrap().permissions().readonly())\n}","typeGuard":null,"tryCatchPattern":"match kernel.commit_workspace_for(&id, &principal, true).await {\n    Ok(None) => info!(\"capsule not loaded; nothing to commit\"),\n    Ok(Some(_)) => info!(\"workspace committed\"),\n    Err(e) if e.to_string().contains(\"workspace commit\") => {\n        error!(\"CoW workspace op failed: {e:#}; reload capsule and retry\");\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Ensure no external process holds files open in capsule workspaces during gate approval.","Keep workspace volumes writable and monitored for space.","Reset/re-load capsules whose workspace state may be inconsistent."],"tags":["rust","filesystem","cow","kernel"],"backgroundTag":"file-write-failed","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}