{"record":{"id":"39276f27256eacdd","repo":"jdx/mise","slug":"local-saved-history-changed-since-planning-nothin","errorCode":null,"errorMessage":"local saved history changed since planning; nothing was applied; run pull again","messagePattern":"local saved history changed since planning; nothing was applied; run pull again","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/scope.rs","lineNumber":254,"sourceCode":"                warn!(\"history: could not persist the capture label: {err:#}\");\n            }\n        }\n    }\n\n    /// The protective checkpoint this operation took, if any.\n    pub(crate) fn before(&self) -> Option<(u64, String)> {\n        self.0\n            .as_ref()\n            .and_then(|shared| lock_unpoisoned(shared).before.clone())\n    }\n\n    pub(crate) fn validate_starting_head(&self, expected: Option<&str>) -> Result<()> {\n        let Some(shared) = &self.0 else {\n            eyre::bail!(\"incoming application requires an active recovery operation\");\n        };\n        let writer = lock_unpoisoned(shared);\n        if writer.starting_head.as_deref() != expected {\n            eyre::bail!(\n                \"local saved history changed since planning; nothing was applied; run pull again\"\n            );\n        }\n        Ok(())\n    }\n\n    /// Retakes the protective checkpoint, replacing the earlier one, when\n    /// files changed between it and the verified plan.\n    pub(crate) fn recapture_before(&self, paths: &[PathBuf]) -> Result<()> {\n        let Some(shared) = &self.0 else {\n            return Ok(());\n        };\n        let mut writer = lock_unpoisoned(shared);\n        // held across the reservation, the capture, and the removal: the\n        // capture writes the index and a checkpoint ref, which a concurrent\n        // `mise dot save` must not interleave with\n        let _store_lock = writer.store.lock()?;\n        let previous = writer.before.take();","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/scope.rs#L236-L272","documentation":"validate_starting_head compares the recorded starting_head of the active recovery operation with the head the caller planned against. If local saved history changed since the pull was planned, the expectation mismatches and nothing is applied, forcing a fresh pull.","triggerScenarios":"Calling validate_starting_head(expected) when writer.starting_head differs — e.g. new checkpoints/commits were written locally after the pull plan was computed, or a concurrent history operation advanced the head between plan and apply.","commonSituations":"Planning a pull, then running commands (or another mise instance) that write history before applying; two machines or processes racing on the same MISE_STATE_DIR; stale plan applied much later.","solutions":["Run pull again to recompute the plan against the current head, then apply immediately","Ensure no other mise operations run between plan and apply (single process, operation lock held)","Commit or settle local history changes before pulling"],"exampleFix":"// before: stale plan\napply(planned_pull);\n// after: fresh pull-then-apply\nlet pull = history.pull()?;\nhistory.apply(pull)?; // same locked session","handlingStrategy":"retry","validationCode":"if history.current_head() != planned_head {\n    eprintln!(\"head moved; re-pull before applying\");\n}","typeGuard":null,"tryCatchPattern":"match scope.validate_starting_head(expected) {\n    Err(e) if e.to_string().contains(\"run pull again\") => {\n        let fresh = history.pull()?;\n        scope.validate_starting_head(fresh.starting_head())?;\n        history.apply(fresh)?;\n    }\n    other => other?,\n}","preventionTips":["Apply immediately after pulling; don't persist plans across sessions","Hold the operation lock across plan and apply","Avoid running other mise commands between pull and apply"],"tags":["history","conflict","optimistic-concurrency"],"backgroundTag":"invalid-state-transition","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}