{"record":{"id":"8302a1e8967c532e","repo":"affaan-m/ECC","slug":"refusing-to-trust-non-managed-ownership-from-insta","errorCode":null,"errorMessage":"Refusing to trust non-managed ownership from install-state at ${plan.installStatePath}.","messagePattern":"Refusing to trust non-managed ownership from install-state at (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/multi-harness-setup.js","lineNumber":157,"sourceCode":"  const state = readState(plan.installStatePath);\n  const validatedFingerprint = fingerprintFile(plan.installStatePath);\n  if (\n    initialFingerprint.exists !== validatedFingerprint.exists\n    || initialFingerprint.sha256 !== validatedFingerprint.sha256\n  ) {\n    throw new Error(\n      `Refusing to trust install-state that changed during validation: ${plan.installStatePath}.`\n    );\n  }\n  assertPriorInstallStateMatchesPlan(state, plan);\n  const plannedByDestination = new Map(plan.operations.map(operation => [\n    canonicalPath(operation.destinationPath),\n    operation,\n  ]));\n  const destinations = new Set();\n  for (const operation of state.operations || []) {\n    if (operation.ownership !== 'managed') {\n      throw new Error(\n        `Refusing to trust non-managed ownership from install-state at ${plan.installStatePath}.`\n      );\n    }\n    const destinationPath = operation.destinationPath;\n    assertWithinTrustedRoot(destinationPath, plan.targetRoot, 'trust install-state ownership');\n    const canonicalDestination = canonicalPath(destinationPath);\n    const plannedOperation = plannedByDestination.get(canonicalDestination);\n    if (!plannedOperation) continue;\n    if (!operationIdentityMatches(operation, plannedOperation)) {\n      throw new Error(\n        `Refusing unverified ownership from install-state at ${plan.installStatePath}: `\n        + `operation identity does not match the current plan for ${destinationPath}.`\n      );\n    }\n    const currentFingerprint = fingerprintFile(destinationPath);\n    if (\n      !currentFingerprint.exists\n      || !/^[a-f0-9]{64}$/i.test(operation.contentSha256 || '')","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/multi-harness-setup.js#L139-L175","documentation":"Thrown while iterating state.operations in readOwnedDestinations when an operation's ownership field is not the string 'managed'. ECC only trusts install-state entries it itself marked as managed (i.e., files ECC created and controls); unmanaged/preserved entries represent user-owned or externally-owned files and cannot grant ECC permission to overwrite them. Any non-managed entry in a state we are about to trust is treated as corruption or tampering.","triggerScenarios":"Fires inside the for-loop over state.operations when operation.ownership !== 'managed'. Occurs if the install-state was hand-edited to change ownership values, if an older/different ECC variant wrote entries with a different ownership vocabulary, or if the JSON schema drifted (e.g., ownership renamed or set to 'user'/'external').","commonSituations":"Manual edits to install-state.json that changed ownership; a state file produced by a fork or older schema; partial merge of two state files; downstream tooling that 'normalizes' JSON and rewrote ownership values.","solutions":["Delete plan.installStatePath and re-run the preview so all operations are recorded as managed by the current ECC.","If you edited the state intentionally, stop — ownership is an internal contract; restore from ECC's own writes.","Audit how the state acquired a non-managed value (diff against a known-good state from a fresh preview).","Confirm you are not running two ECC variants with different ownership schemas against the same state."],"exampleFix":"// before: state contains { destinationPath:'/x', ownership:'user' }\nfor (const op of state.operations) { /* throws [286] on first non-managed */ }\n\n// after: regenerate state so every op is ownership:'managed'\nfs.rmSync(plan.installStatePath, { force: true });\nconst plan2 = await createMultiHarnessPlan(req);\nawait applyMultiHarnessPlan(plan2);","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertAllOperationsManaged(statePath) {\n  if (!fs.existsSync(statePath)) return;\n  const state = JSON.parse(fs.readFileSync(statePath, 'utf8'));\n  const bad = (state.operations || []).filter(op => op.ownership !== 'managed');\n  if (bad.length) {\n    throw new Error(`Install-state has ${bad.length} non-managed operation(s); delete the state and re-install.`);\n  }\n}\nassertAllOperationsManaged(plan.installStatePath);","typeGuard":"function stateOperationsAllManaged(state) {\n  return Array.isArray(state && state.operations)\n    && state.operations.every(op => op && op.ownership === 'managed');\n}","tryCatchPattern":"try {\n  await applyMultiHarnessPlan(plan);\n} catch (err) {\n  if (/non-managed ownership/.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 edit install-state.json by hand; ownership is an internal contract.","Do not merge install-state files from different ECC versions or forks.","If you suspect schema drift, delete the state and regenerate.","Run only one ECC variant per project to avoid ownership-vocabulary mismatches."],"tags":["install-state","ownership","schema-validation","kimi","tamper-detection"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}