{"record":{"id":"6c53c5d7f3900108","repo":"jdx/mise","slug":"task-cache-manifest-contains-duplicate-or-nested-r","errorCode":null,"errorMessage":"task cache manifest contains duplicate or nested roots","messagePattern":"task cache manifest contains duplicate or nested roots","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/task_cache.rs","lineNumber":566,"sourceCode":"            if let Err(err) = self\n                .store\n                .remove_local(&self.key, self.action.len() as u64)\n                .await\n            {\n                warn!(\n                    \"failed to remove expired local task cache entry {}: {err}\",\n                    self.key\n                );\n            }\n            return Ok(TaskCacheRestore::Miss(TaskCacheMissReason::Expired));\n        }\n        let restore = || -> Result<TaskCacheHit> {\n            let manifest = self.read_manifest(&entry.manifest)?;\n            for root in &manifest.roots {\n                ensure_safe_relative(root)?;\n            }\n            if remove_nested_roots(manifest.roots.clone()) != manifest.roots {\n                bail!(\"task cache manifest contains duplicate or nested roots\");\n            }\n            verify_artifact_checksum(\n                &manifest,\n                entry.artifact.as_ref().map(|artifact| artifact.path()),\n            )?;\n            if manifest.roots.is_empty() {\n                self.store.touch(&self.key);\n                return Ok(TaskCacheHit {\n                    output: manifest.output,\n                    restored_bytes: manifest.restored_bytes,\n                    saved_duration: std::time::Duration::from_nanos(manifest.execution_duration_ns),\n                });\n            }\n            // Serialize restores targeting the same working directory across\n            // mise processes so validation and renames form one cooperative\n            // critical section. Result-only entries never mutate the task root.\n            let _output_lock = crate::lock_file::LockFile::new(\n                &self.root.join(\".mise-task-artifact-cache-output\"),","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/task_cache.rs#L548-L584","documentation":"A cache-hit manifest lists the root directories (relative paths) that the archived artifact should restore. Before restoring, mise verifies the manifest's roots contain no duplicates and no path that is nested inside another root; if remove_nested_roots changes the list, the manifest is rejected. This guards against ambiguous or malicious manifests extracting into overlapping locations.","triggerScenarios":"Restoring from a task cache entry (read_manifest + roots validation during cache hit resolution) when manifest.roots contains the same path twice or a path that is a strict descendant of another listed root — i.e. a hand-edited, corrupted, or wrongly generated manifest JSON.","commonSituations":"Manually editing or scripting cache manifests; a corrupted/partial manifest from an interrupted write; shared remote caches written by tooling that doesn't deduplicate roots.","solutions":["Delete the offending cache entry (manifest + artifact) so the task re-executes and writes a fresh manifest.","Clear the whole task-artifacts cache directory if many entries are suspect.","Do not hand-edit cache manifests; let mise generate them from the task's outputs config.","If produced by custom remote-cache tooling, deduplicate/nest-filter roots before upload."],"exampleFix":"// before (corrupt manifest.json)\n{\"roots\": [\"dist\", \"dist/subdir\"], ...}\n// after\nrm <cache-dir>/<entry>/manifest.json && mise run build  # task re-runs, writes {\"roots\": [\"dist\"]}","handlingStrategy":"validation","validationCode":"const roots = JSON.parse(fs.readFileSync(manifestPath, 'utf8')).roots;\nconst sorted = [...roots].sort();\nif (new Set(sorted).size !== sorted.length) throw new Error('duplicate roots');\nif (roots.some(r => roots.some(o => o !== r && (r.startsWith(o + '/'))))) throw new Error('nested roots');","typeGuard":"function hasCleanRoots(m: { roots: string[] }): boolean {\n  return m.roots.every((r, i) => m.roots.every((o, j) => i === j || !(r === o || r.startsWith(o + '/') || o.startsWith(r + '/'))));\n}","tryCatchPattern":"// treat manifest rejection as cache miss\ntry { restoreFromManifest(entry) } catch (e) {\n  if (String(e).includes('duplicate or nested roots')) { deleteEntry(entry); runTask(); }\n  else throw e;\n}","preventionTips":["Never hand-edit cache manifest JSON files","Ensure any custom cache-writing tooling deduplicates roots before upload","Clear entries after interrupted cache writes"],"tags":["task-cache","manifest","cache-corruption"],"backgroundTag":"internal-invariant-violation","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"}