{"record":{"id":"95be4c86e86d16b4","repo":"Hmbown/CodeWhale","slug":"skill-content-changed-since-audit-expected-expec","errorCode":null,"errorMessage":"skill content changed since audit (expected {expected}, found {current}); re-review before mutating","messagePattern":"skill content changed since audit \\(expected (.+?), found (.+?)\\); re-review before mutating","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/skills/mutation.rs","lineNumber":561,"sourceCode":"        _ => None,\n    }\n    .filter(|name| !name.is_empty())\n    .ok_or_else(|| {\n        anyhow::anyhow!(\n            \"invalid on-disk package directory for skill '{}'\",\n            skill_id.canonical_name\n        )\n    })?;\n    Ok(name)\n}\n\nfn verify_expected_digest(path: &Path, expected: Option<&str>) -> Result<Option<String>> {\n    let current = package_digest::compute_package_digest(path)\n        .with_context(|| format!(\"cannot digest {}\", path.display()))?;\n    if let Some(expected) = expected\n        && expected != current\n    {\n        bail!(\n            \"skill content changed since audit (expected {expected}, found {current}); \\\n             re-review before mutating\"\n        );\n    }\n    Ok(Some(current))\n}\n\nfn ensure_remote_updatable(skill_dir: &Path) -> Result<()> {\n    let marker_path = skill_dir.join(install::INSTALLED_FROM_MARKER);\n    let body = fs::read_to_string(&marker_path)\n        .with_context(|| format!(\"failed to read {}\", marker_path.display()))?;\n    let value: serde_json::Value = serde_json::from_str(&body)\n        .with_context(|| format!(\"malformed {}\", install::INSTALLED_FROM_MARKER))?;\n    let spec = value\n        .get(\"spec\")\n        .and_then(|v| v.as_str())\n        .unwrap_or_default();\n    if !install::is_registry_updatable_spec(spec) {","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/skills/mutation.rs#L543-L579","documentation":"Mutations accept an optional expected digest captured at audit/review time. verify_expected_digest recomputes the package digest and, if an expected digest was supplied and differs from the current content, refuses to mutate: the package changed after the user reviewed it, so the approval no longer applies. This is a TOCTOU/integrity guard against mutating content the user never saw.","triggerScenarios":"Calling import_external, update_skill, remove_skill, or trust_skill with an expected digest argument while the package on disk has been modified since the audit — files added/edited inside the package, an incomplete download, or a different package at the same path.","commonSituations":"A background process or editor rewrote skill files between review and mutation; the user reviewed one version and the updater fetched another; a partially completed update left the tree mixed; disk corruption or a merge/tool rewrote SKILL.md.","solutions":["Re-review the skill content at the path, compute the new digest, and pass the fresh digest as the expected value","Re-run the audit/review workflow (/skills review) and retry the mutation with the newly recorded digest","If the change was unintended, restore the package content to the audited state (e.g. from version control) and retry","If the package is corrupted, remove it and re-import/re-install from the source"],"exampleFix":"// before\ntrust_skill(resolved.id, Some(\"sha256:old\"), &ctx)?; // content already changed\n// after\nlet current = package_digest::compute_package_digest(&path)?; // re-review first\ntrust_skill(resolved.id, Some(current), &ctx)?;","handlingStrategy":"validation","validationCode":"fn content_matches_audit(path: &Path, expected: Option<&str>) -> Result<bool> {\n    let Some(expected) = expected else { return Ok(true) };\n    let current = package_digest::compute_package_digest(path)?;\n    Ok(expected == current)\n}","typeGuard":null,"tryCatchPattern":"match mutation::remove_skill(&audited, &path, &ctx) {\n    Err(e) if e.to_string().contains(\"skill content changed since audit\") => {\n        eprintln!(\"package changed after review; re-review and recompute the digest\");\n    }\n    other => other?,\n}","preventionTips":["Recompute the package digest immediately before each mutation and pass it as expected","Avoid editing skill files between review and mutation; pause watchers/sync tools during the window","Treat any digest mismatch as a review-required event, never auto-retry with the old digest"],"tags":["skills","integrity","digest","toctou","security"],"backgroundTag":"checksum-mismatch","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}