{"record":{"id":"b3c835e3e0c3092a","repo":"mastra-ai/mastra","slug":"repository-id-not-found-in-organization-orgid","errorCode":null,"errorMessage":"Repository ${id} not found in organization ${orgId}","messagePattern":"Repository (.+?) not found in organization (.+?)","errorType":"exception","errorClass":null,"httpStatus":404,"severity":"error","filePath":"mastracode/factory/src/storage/domains/source-control/base.ts","lineNumber":698,"sourceCode":"        },\n        upsert: async ({ orgId, input }) => {\n          await requireInstallation({ orgId, id: input.installationId });\n          const now = new Date();\n          const row = await db().upsertOne<RepositoryDbRow>(REPOSITORIES, ['installation_id', 'external_id'], {\n            installation_id: input.installationId,\n            external_id: input.externalId,\n            slug: input.slug,\n            default_branch: input.defaultBranch,\n            provider_metadata: input.providerMetadata ?? {},\n            created_at: now,\n            updated_at: now,\n          });\n          return toRepository(row);\n        },\n        migrateInstallation: async ({ orgId, id, newInstallationId }) => {\n          const existing = await getRepository({ orgId, id });\n          if (!existing) {\n            throw new Error(`Repository ${id} not found in organization ${orgId}`);\n          }\n          await requireInstallation({ orgId, id: newInstallationId });\n          try {\n            await db().updateMany(REPOSITORIES, { id }, { installation_id: newInstallationId, updated_at: new Date() });\n            // Migrate dependent connections to the new installation\n            await db().updateMany(\n              CONNECTIONS,\n              { installation_id: existing.installationId },\n              { installation_id: newInstallationId },\n            );\n            // Return the updated repository\n            const updated = await getRepository({ orgId, id });\n            if (!updated) throw new Error('Repository disappeared after update');\n            return updated;\n          } catch (error) {\n            // Unique constraint violation: repository already exists under the new installation\n            if (!(error instanceof UniqueViolationError)) throw error;\n            // Find and return the existing repository under the new installation","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/source-control/base.ts#L680-L716","documentation":"Thrown inside migrateInstallation when the repository identified by { orgId, id } does not exist. Migration of a repository to a new installation is only valid for an existing repository row.","triggerScenarios":"Calling migrateInstallation with a repository id that was never created, was deleted, or belongs to another org.","commonSituations":"Rotating a GitHub App installation with a stale repository id; migrating repos across orgs; referencing a repo created under a different integration.","solutions":["Verify the repository exists via repository.get before migrating","Create/upsert the repository first if missing","Confirm orgId matches the org the repository was created under"],"exampleFix":"// before\nawait api.migrateInstallation({ orgId, id: repoId, newInstallationId });\n// after\nif (!(await api.getRepository({ orgId, id: repoId }))) {\n  throw new Error(`Repository ${repoId} missing; cannot migrate`);\n}\nawait api.migrateInstallation({ orgId, id: repoId, newInstallationId });","handlingStrategy":"validation","validationCode":"const existing = await getRepository({ orgId, id });\nif (!existing) throw new Error(`Cannot migrate: repository ${id} not found`);","typeGuard":"function isMigratable(v: SourceControlRepository | null): v is SourceControlRepository {\n  return v !== null && typeof v.installationId === 'string';\n}","tryCatchPattern":"try {\n  await migrateInstallation({ orgId, id, newInstallationId });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Repository')) {\n    await upsertRepository({ orgId, installationId: oldInstallationId, externalId, name });\n    await migrateInstallation({ orgId, id, newInstallationId });\n  } else throw e;\n}","preventionTips":["Look up the repository before migrating","Migrate repositories and connections together during installation rotation","Validate orgId against stored records"],"tags":["source-control","not-found","migration","repository"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}