{"record":{"id":"14eb7572652892cf","repo":"stablyai/orca","slug":"imported-folder-does-not-match-the-selected-projec","errorCode":null,"errorMessage":"Imported folder does not match the selected project identity.","messagePattern":"Imported folder does not match the selected project identity\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ipc/repos.ts","lineNumber":259,"sourceCode":"    throw new Error(`Project setup was created without a project record: ${setup.projectId}`)\n  }\n  return { project, setup, repo }\n}\n\nfunction alignRepoWithRequestedProject(\n  store: Store,\n  repo: Repo,\n  projectId: string,\n  setupMethod: ProjectHostSetupExistingFolderArgs['setupMethod'] = 'imported-existing-folder',\n  requestedProviderIdentity?: ProjectHostSetupExistingFolderArgs['projectProviderIdentity']\n): ProjectHostSetupResult {\n  let setup = getProjectHostSetupForRepo(store.getProjectHostSetups(), repo)\n  if (setup.projectId !== projectId) {\n    const project = store.getProjects().find((entry) => entry.id === projectId)\n    // Why: the selected project can exist only on the source host, so its structured identity travels with the request.\n    const identity = project?.providerIdentity ?? requestedProviderIdentity\n    if (!identity || getProjectIdForProviderIdentity(identity) !== projectId) {\n      throw new Error('Imported folder does not match the selected project identity.')\n    }\n    // Why: stamp the selected project's provider identity when the folder lacks upstream, so projection can merge it.\n    const updated = store.updateRepo(repo.id, {\n      upstream: {\n        owner: identity.owner,\n        repo: identity.repo,\n        ...(identity.host ? { host: identity.host } : {})\n      }\n    })\n    if (!updated) {\n      throw new Error(`Project setup repo disappeared before it could be linked: ${repo.id}`)\n    }\n    repo = updated\n    setup = getProjectHostSetupForRepo(store.getProjectHostSetups(), repo)\n  }\n  const updated = store.updateRepo(repo.id, { projectHostSetupMethod: setupMethod })\n  if (!updated) {\n    throw new Error(","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/repos.ts#L241-L277","documentation":"Thrown by alignRepoWithRequestedProject when the existing project-host setup's projectId differs from the requested projectId AND there is no provider identity that hashes to the requested project. getProjectIdForProviderIdentity(identity) must equal projectId — it formats as `github:<owner>/<repo>` (lowercased, normalized host). The check uses the project's stored providerIdentity or a caller-supplied requestedProviderIdentity as fallback.","triggerScenarios":"Importing/linking an existing folder whose recorded setup points at project A, while the caller requests it be linked to project B, and neither the stored project record nor the request supplies an identity that hashes to B's id. Concretely: setup.projectId !== projectId AND (!identity || getProjectIdForProviderIdentity(identity) !== projectId).","commonSituations":"Folder was previously linked to a different GitHub project; project record deleted from the source host so providerIdentity is undefined; requestedProviderIdentity owner/repo typo that hashes to a different id; host/owner/repo case mismatch in the identity vs the projectId encoding.","solutions":["Pass a requestedProviderIdentity whose owner/repo/host hash to the requested projectId (verify with getProjectIdForProviderIdentity).","Re-add the project record on the source host so the stored providerIdentity resolves, then retry the folder link.","Confirm the projectId encoding matches: it must be `github:<lowercased-owner>/<lowercased-repo>` with ssh.github.com normalized to github.com.","If the folder was mis-linked, clear its existing projectHostSetup before retrying so setup.projectId === projectId on entry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { getProjectIdForProviderIdentity } from '../../shared/project-host-setup-projection'\nimport type { ProjectProviderIdentity } from '../../shared/types'\n\nfunction folderIdentityMatchesRequestedProject(\n  identity: ProjectProviderIdentity | undefined,\n  projectId: string\n): boolean {\n  return !!identity && getProjectIdForProviderIdentity(identity) === projectId\n}","typeGuard":"function isFolderProjectIdentityMismatch(err: unknown): boolean {\n  return err instanceof Error && err.message === 'Imported folder does not match the selected project identity.'\n}","tryCatchPattern":"try {\n  await linkFolderToProject(store, repo, projectId, setupMethod, requestedProviderIdentity)\n} catch (err) {\n  if (isFolderProjectIdentityMismatch(err)) {\n    surfaceUserAction('The folder is linked to a different project. Re-add it under that project, or supply a provider identity matching the selected one.')\n    return\n  }\n  throw err\n}","preventionTips":["Before linking a folder, verify the requested provider identity hashes (via getProjectIdForProviderIdentity) to the target projectId.","Use consistent owner/repo case in identities; getProjectIdForProviderIdentity lower-cases them, so mixed-case mismatches are silent at the source but visible here.","normalizeGitHubRemoteHost maps ssh.github.com to github.com — keep that in mind when constructing identities."],"tags":["project","identity","import-folder","provider-identity","validation"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}