{"record":{"id":"40ffd609a3392aba","repo":"affaan-m/ECC","slug":"refusing-to-trust-managed-install-state-at-plan-40ffd6","errorCode":null,"errorMessage":"Refusing to trust managed install-state at ${plan.installStatePath}: recorded install-state path does not match the current install-state path.","messagePattern":"Refusing to trust managed install-state at (.+?): recorded install-state path does not match the current install-state path\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/multi-harness-setup.js","lineNumber":167,"sourceCode":"  const adapter = plan.adapter || {};\n  if (\n    target.id !== adapter.id\n    || target.target !== adapter.target\n    || target.kind !== adapter.kind\n  ) {\n    throw new Error(\n      `Refusing to trust managed install-state at ${plan.installStatePath}: `\n      + 'target identity does not match the current Kimi install plan.'\n    );\n  }\n  if (!pathsMatch(target.root, plan.targetRoot)) {\n    throw new Error(\n      `Refusing to trust managed install-state at ${plan.installStatePath}: `\n      + 'recorded root does not match the current install root.'\n    );\n  }\n  if (!pathsMatch(target.installStatePath, plan.installStatePath)) {\n    throw new Error(\n      `Refusing to trust managed install-state at ${plan.installStatePath}: `\n      + 'recorded install-state path does not match the current install-state path.'\n    );\n  }\n}\n\nfunction readOwnedDestinations(plan, dependencies) {\n  if (!plan.installStatePath) {\n    return { destinations: new Set(), stateFingerprint: { exists: false, sha256: null } };\n  }\n  try {\n    assertSafeInstallOperation(plan, { destinationPath: plan.installStatePath });\n  } catch (error) {\n    throw new Error(`Refusing to trust managed install-state path: ${error.message}`);\n  }\n  const initialFingerprint = fingerprintFile(plan.installStatePath);\n  if (!initialFingerprint.exists) {\n    return { destinations: new Set(), stateFingerprint: { exists: false, sha256: null } };","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/multi-harness-setup.js#L149-L185","documentation":"readOwnedDestinations validates a previously recorded install-state file before trusting it to define which destinations ECC 'owns'. This error is thrown by assertPriorInstallStateMatchesPlan when the installStatePath recorded inside the state file does not match (after path canonicalization) the plan.installStatePath currently being read. It guards against a state file being copied, moved, or symlinked to a different location, which would make its recorded ownership claims untrustworthy.","triggerScenarios":"Calling readOwnedDestinations (via the ownership step of a managed install) where state.target.installStatePath differs from plan.installStatePath — e.g. the state file was copied to a new path, the repo/package was relocated so the state path changed, or the plan was built with a different install-state location than the recorded one.","commonSituations":"Developer clones a project including .ecc install-state and runs an install from a different working directory; user moves the ECC install directory; a harness migration script renames the state file; a symlinked setup causes canonical path mismatch.","solutions":["Delete the stale install-state file at plan.installStatePath and re-run the guided install so a fresh state is recorded.","Ensure the install is run from the same install root/path that produced the state file (check the installStatePath recorded inside the state JSON).","If the location legitimately changed, remove the old state and regenerate the plan rather than hand-editing the state file."],"exampleFix":"// before: reusing copied state\nconst plan = buildPlan({ targetRoot: '/new/location' }); // state copied from /old/location\n// after: start clean at the new location\nfs.rmSync('/new/location/.ecc/install-state.json');\nconst plan = buildPlan({ targetRoot: '/new/location' });","handlingStrategy":"validation","validationCode":"const state = JSON.parse(fs.readFileSync(plan.installStatePath, 'utf8'));\nif (state.target && !pathMatches(state.target.installStatePath, plan.installStatePath)) {\n  throw new Error(`Stale install-state at ${plan.installStatePath}; delete it and re-run the guided install.`);\n}","typeGuard":"function isStatePathCurrent(state, plan) {\n  return Boolean(state?.target?.installStatePath) && pathsMatch(state.target.installStatePath, plan.installStatePath);\n}","tryCatchPattern":"try {\n  const { destinations } = readOwnedDestinations(plan, deps);\n} catch (err) {\n  if (String(err.message).includes('install-state path does not match')) {\n    fs.rmSync(plan.installStatePath); // reset stale state, then re-run guided install\n  } else throw err;\n}","preventionTips":["Never copy or move install-state files between install roots.","Re-run the guided install after relocating a project instead of carrying state over.","Keep the install-state path at the adapter default unless you also regenerate the state.","Check recorded target.installStatePath before building a plan against an existing state."],"tags":["install-state","validation","safety"],"backgroundTag":"invalid-argument-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}