{"record":{"id":"1ee5f27e540dc596","repo":"farion1231/cc-switch","slug":"skill-changed-during-update","errorCode":null,"errorMessage":"Skill changed during update: {}","messagePattern":"Skill changed during update: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/src/services/skill.rs","lineNumber":1474,"sourceCode":"            })?;\n\n        // Downloads do not mutate local state, so acquire only now and hold the\n        // guard through the SSOT replacement, DB metadata update, and app sync.\n        let _state_guard = skill_state_write_guard();\n\n        // 下载和扫描期间用户可能已经卸载了该 Skill。必须在任何备份、删除或\n        // 复制之前重新确认记录仍存在；否则即使最终的 metadata UPDATE 能发现\n        // 缺行，这里也会先把已卸载的 SSOT 目录重新创建出来。\n        let mut current_skill = db\n            .get_installed_skill(&skill.id)?\n            .ok_or_else(|| anyhow!(\"Skill no longer installed: {}\", skill.id))?;\n        if current_skill.directory != skill.directory\n            || current_skill.repo_owner != skill.repo_owner\n            || current_skill.repo_name != skill.repo_name\n            || current_skill.repo_branch != skill.repo_branch\n            || current_skill.installed_at != skill.installed_at\n        {\n            return Err(anyhow!(\"Skill changed during update: {}\", skill.id));\n        }\n        Self::require_valid_directory(&current_skill.directory)?;\n        current_skill.apps.pi = Self::skill_exists_in_app(&current_skill.directory, &AppType::Pi);\n        let skill = current_skill;\n\n        let dest = ssot_dir.join(&skill.directory);\n        let mut deployments = Vec::new();\n        for app in [AppType::Pi, AppType::Mcode] {\n            if skill.apps.is_enabled_for(&app) {\n                let destination =\n                    Self::get_distinct_app_skills_dir(&ssot_dir, &app)?.join(&skill.directory);\n                if let Some(deployment) =\n                    Self::inspect_pi_skill_destination(&dest, &destination, &skill.directory)?\n                {\n                    deployments.push((destination, deployment));\n                }\n            }\n        }","sourceCodeStart":1456,"sourceCodeEnd":1492,"githubUrl":"https://github.com/farion1231/cc-switch/blob/06082e189d65e6d6dbadc35dacdac1ce6c79d89a/src-tauri/src/services/skill.rs#L1456-L1492","documentation":"The row still exists after the download, but directory, repo_owner, repo_name, repo_branch, or installed_at differs from the snapshot taken before the download. Another update/reinstall replaced the record during the await window, and acting on the mixed identity (old snapshot paths + new row) would be unsafe, so the operation aborts.","triggerScenarios":"Two concurrent update_skill calls for the same id; uninstall followed by reinstall racing an in-flight update; profile sync overwriting the row with a different generation (installed_at is the generation marker).","commonSituations":"Double-clicking Update; 'update all' racing a manual update of the same skill; switching profiles while an update runs.","solutions":["Retry the update once from a freshly loaded skill record — the new snapshot will match the new generation","Serialize update/uninstall/reinstall per skill id in the UI","Avoid switching profiles or triggering syncs while batch updates are running"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await invoke('update_skill', { id });\n} catch (e) {\n  if (String(e).includes('Skill changed during update')) {\n    await refreshSkillList(); // load the new generation\n    return invoke('update_skill', { id }); // retry once from fresh snapshot\n  }\n  throw e;\n}","preventionTips":["Serialize update/reinstall per skill id — one operation at a time","Debounce double-clicked Update buttons","Do not switch profiles or trigger syncs while updates are running"],"tags":["update","race-condition","consistency","skill-manager"],"backgroundTag":"optimistic-concurrency-conflict","analyzedSha":"06082e189d65e6d6dbadc35dacdac1ce6c79d89a","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}