{"record":{"id":"7ae0a91bc4b65ced","repo":"paperclipai/paperclip","slug":"target-paperclip-instance-does-not-match-the-regis","errorCode":null,"errorMessage":"Target Paperclip instance does not match the registered worktree instance.","messagePattern":"Target Paperclip instance does not match the registered worktree instance\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/src/worktree-seed-source.ts","lineNumber":177,"sourceCode":"  if (explicitSource) {\n    const canonicalExplicitSource = canonicalRegularFile(explicitSource, \"Explicit source Paperclip config\");\n    if (canonicalExplicitSource !== canonicalSourceConfigPath) {\n      throw new Error(\"Explicit source Paperclip config does not match the registered base project workspace.\");\n    }\n  }\n\n  const canonicalTargetConfigPath = canonicalRegularFile(\n    input.targetConfigPath,\n    \"Target worktree Paperclip config\",\n  );\n  if (canonicalSourceConfigPath === canonicalTargetConfigPath) {\n    throw new Error(\"Source and target Paperclip configs are the same canonical file.\");\n  }\n\n  const sourceInstanceId = readInstanceId(canonicalSourceConfigPath, \"source\");\n  const targetInstanceId = readInstanceId(canonicalTargetConfigPath, \"target\");\n  if (targetInstanceId !== input.expectedTargetInstanceId) {\n    throw new Error(\"Target Paperclip instance does not match the registered worktree instance.\");\n  }\n  if (sourceInstanceId === targetInstanceId) {\n    throw new Error(\"Source and target Paperclip configs name the same instance.\");\n  }\n\n  return {\n    baseWorkspaceCwd: canonicalBaseCwd,\n    configPath: canonicalSourceConfigPath,\n    instanceId: sourceInstanceId,\n    targetConfigPath: canonicalTargetConfigPath,\n    targetInstanceId,\n  };\n}\n\n/**\n * Resolve a worktree seed source without granting authority to the seed manifest.\n *\n * A managed caller supplies the project-workspace cwd from its server-owned row.","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/packages/shared/src/worktree-seed-source.ts#L159-L195","documentation":"Each config's instance id is read from the `.env` beside it (PAPERCLIP_INSTANCE_ID, or the instances/<id> directory name). The target worktree config's instance id must equal expectedTargetInstanceId — the instance the worktree is registered under. A mismatch means the worktree's config belongs to a different instance than the one performing the seed.","triggerScenarios":"resolveRegisteredWorktreeSeedSource where the target worktree's `.paperclip/.env` has a PAPERCLIP_INSTANCE_ID different from the instance id passed in expectedTargetInstanceId; worktree registered under instance A but its config carries instance B's id.","commonSituations":"Worktree directory copied from another instance's worktree (bringing its .env); hand-edited .env; worktree moved between instances; seeding an old worktree after the instance was recreated with a new id.","solutions":["Print both ids: `grep PAPERCLIP_INSTANCE_ID <target>/.paperclip/.env` vs the registered worktree instance id.","Correct the target worktree's `.paperclip/.env` to the registered instance id (or re-create the worktree through the normal flow so it is registered consistently).","If the worktree was intentionally migrated, update its registration to the instance the config names."],"exampleFix":"# before: worktree .env still names the old instance\ncat worktrees/issue-42/.paperclip/.env   # PAPERCLIP_INSTANCE_ID=old-id\n\n# after\nsed -i 's/^PAPERCLIP_INSTANCE_ID=.*/PAPERCLIP_INSTANCE_ID=<registered-id>/' worktrees/issue-42/.paperclip/.env","handlingStrategy":"validation","validationCode":"import { readFileSync } from \"node:fs\";\n\nfunction instanceIdFromEnv(configPath: string): string | null {\n  const env = readFileSync(`${configPath.replace(/config\\.json$/, \"\")}.env`, \"utf8\");\n  return env.match(/PAPERCLIP_INSTANCE_ID\\s*=\\s*[\"']?([^\"'\\s#]+)/)?.[1] ?? null;\n}\n\nconst targetId = instanceIdFromEnv(targetConfigPath);\nif (targetId !== expectedTargetInstanceId) throw new Error(\"worktree .env names another instance\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never copy `.paperclip/.env` between worktrees; let the tooling issue it.","Verify PAPERCLIP_INSTANCE_ID matches the registration before seeding.","After recreating an instance, audit worktrees for stale .env ids."],"tags":["worktree-seed","instance-id","env-file","config"],"backgroundTag":"instance-id-mismatch","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-21T17:58:32.592Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}