{"record":{"id":"ce375379b856fb4a","repo":"affaan-m/ECC","slug":"refusing-to-trust-managed-install-state-at-plan","errorCode":null,"errorMessage":"Refusing to trust managed install-state at ${plan.installStatePath}: target identity does not match the current Kimi install plan.","messagePattern":"Refusing to trust managed install-state at (.+?): target identity does not match the current Kimi install plan\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/multi-harness-setup.js","lineNumber":106,"sourceCode":"    currentFingerprint.exists !== expectedFingerprint.exists\n    || currentFingerprint.sha256 !== expectedFingerprint.sha256\n  ) {\n    throw new Error(\n      `Refusing to overwrite an unowned or changed install-state at ${plan.installStatePath}. `\n      + 'Re-run the guided preview and review the existing state before retrying.'\n    );\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","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/multi-harness-setup.js#L88-L124","documentation":"Thrown by assertPriorInstallStateMatchesPlan when the install-state's recorded target identity ({id, target, kind}) does not equal plan.adapter's {id, target, kind}. The installer will only trust an install-state that was written by the same adapter (target type + id + kind) as the current plan; a mismatch means the state belongs to a different harness/install kind and its ownership claims do not apply. This prevents a Kimi plan from inheriting ownership recorded by an unrelated adapter.","triggerScenarios":"Reached via readOwnedDestinations -> assertPriorInstallStateMatchesPlan when plan.installStatePath exists and parses. Fires when state.target.id !== plan.adapter.id, state.target.target !== plan.adapter.target, or state.target.kind !== plan.adapter.kind. Common when reusing an install-state path across adapter types, after an adapter migration, or when plan.adapter was constructed with a different id/kind than what wrote the state.","commonSituations":"Switching the managed install target kind while pointing at the same install-state path; a stale state left by an older ECC version that used different adapter identifiers; manually copying a project directory that contains another adapter's install-state; running a Kimi profile install over a state file authored by a different target.","solutions":["Remove the install-state at plan.installStatePath and re-run the guided preview so it is recreated by the current adapter.","Verify plan.adapter.id, plan.adapter.target, and plan.adapter.kind match the target that originally authored the state (inspect state.target in the JSON).","If migrating adapters intentionally, discard the old state rather than trying to reuse it.","Confirm you are running the intended harness/profile; an accidental target switch produces this mismatch."],"exampleFix":"// before: state authored by adapter A, now applying adapter B's plan\n// state.target = { id:'kimi-cli', target:'kimi', kind:'managed' }\n// plan.adapter = { id:'kimi-editor', target:'kimi', kind:'managed' }\nawait applyMultiHarnessPlan(plan); // throws [281]\n\n// after: discard mismatched state and regenerate\nfs.rmSync(plan.installStatePath, { force: true });\nconst fresh = await createMultiHarnessPlan(req);\nawait applyMultiHarnessPlan(fresh);","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertStateAdapterMatches(statePath, adapter) {\n  if (!fs.existsSync(statePath)) return; // nothing to mismatch\n  const state = JSON.parse(fs.readFileSync(statePath, 'utf8'));\n  const t = state.target || {};\n  if (t.id !== adapter.id || t.target !== adapter.target || t.kind !== adapter.kind) {\n    throw new Error(`Existing install-state was authored by a different adapter (${t.id}/${t.target}/${t.kind}); remove it or change plan.adapter.`);\n  }\n}\n// before applying:\nassertStateAdapterMatches(plan.installStatePath, plan.adapter);","typeGuard":"function isAdapterConsistent(plan) {\n  return plan && plan.adapter\n    && typeof plan.adapter.id === 'string'\n    && typeof plan.adapter.target === 'string'\n    && typeof plan.adapter.kind === 'string';\n}","tryCatchPattern":"try {\n  await applyMultiHarnessPlan(plan);\n} catch (err) {\n  if (/target identity does not match the current Kimi install plan/.test(err.message)) {\n    fs.rmSync(plan.installStatePath, { force: true });\n    const fresh = await createMultiHarnessPlan(plan.request);\n    await applyMultiHarnessPlan(fresh);\n  } else throw err;\n}","preventionTips":["Never reuse an install-state across adapter types; delete and regenerate on adapter change.","Pin the ECC version when you need stable adapter identifiers across runs.","Inspect state.target before applying if the project was cloned from elsewhere.","Keep plan.adapter construction in one place so id/target/kind are consistent."],"tags":["install-state","adapter-identity","ownership","kimi","multi-harness"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}