{"record":{"id":"cdae627986f8d40b","repo":"affaan-m/ECC","slug":"refusing-to-trust-managed-install-state-at-plan-cdae62","errorCode":null,"errorMessage":"Refusing to trust managed install-state at ${plan.installStatePath}: recorded root does not match the current install root.","messagePattern":"Refusing to trust managed install-state at (.+?): recorded root does not match the current install root\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"scripts/lib/multi-harness-setup.js","lineNumber":161,"sourceCode":"    );\n  }\n}\n\nfunction assertPriorInstallStateMatchesPlan(state, plan) {\n  const target = state.target || {};\n  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 });","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/multi-harness-setup.js#L143-L179","documentation":"assertPriorInstallStateMatchesPlan verifies that the root directory recorded in the existing install-state matches plan.targetRoot (via pathsMatch). A mismatch means the state file's owned-destination list is rooted elsewhere, so applying the new plan could clobber files outside the current install root. The installer refuses to trust the recorded state.","triggerScenarios":"Re-running a guided Kimi install after the target root moved (different install directory, renamed home, changed XDG dir) while the old install-state file still records the previous root.","commonSituations":"Migrating the install to a new directory without uninstalling first; moving a checkout or changing targetRoot config; restoring a state file from another machine with a different absolute path.","solutions":["Uninstall using the original root/state, then run a fresh preview and apply with the new target root","Delete the stale install-state file only after confirming the old install is gone","Set plan.targetRoot back to the recorded root if you intended to keep installing there"],"exampleFix":"// before: state records /home/alice/.kimi, plan targets /opt/kimi\napplySetup(planWithNewRoot) // throws root mismatch\n// after\n// clean up old install & its state, then:\nconst plan = previewSetup({ targetRoot: '/opt/kimi', ... })\napplySetup(plan)","handlingStrategy":"try-catch","validationCode":"const state = readInstallState(plan.installStatePath)\nif (state && !pathsMatch(state.target.root, plan.targetRoot)) {\n  throw new Error('Install root changed since last install; clean up old install first')\n}","typeGuard":"const rootMatchesPlan = (state, plan) => pathsMatch(state?.target?.root, plan?.targetRoot)","tryCatchPattern":"try {\n  applySetup(plan)\n} catch (err) {\n  if (err.message.includes('recorded root does not match')) {\n    uninstallAt(oldRecordedRoot) // remove old install using its recorded root\n    const fresh = previewSetup(plan.request)\n    applySetup(fresh.plan)\n  } else throw err\n}","preventionTips":["After moving the install directory, uninstall from the old location before installing at the new one","Keep targetRoot stable in config; change it only through a clean uninstall/reinstall cycle","Never copy install-state files between machines or paths"],"tags":["install-state","safety","path-mismatch"],"backgroundTag":"checksum-mismatch","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"}