{"record":{"id":"222f9380c5e4dcfe","repo":"mastra-ai/mastra","slug":"repository-id-not-found-in-organization-orgid-222f93","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/inmemory.ts","lineNumber":155,"sourceCode":"        providerMetadata: input.providerMetadata ?? {},\n        createdAt: now,\n        updatedAt: now,\n      };\n      this.repositoriesRows.push(created);\n      return created;\n    },\n    migrateInstallation: async ({\n      orgId,\n      id,\n      newInstallationId,\n    }: {\n      orgId: string;\n      id: string;\n      newInstallationId: string;\n    }) => {\n      const existing = await this.repositories.get({ orgId, id });\n      if (!existing) {\n        throw new Error(`Repository ${id} not found in organization ${orgId}`);\n      }\n      if (!(await this.installations.get({ orgId, id: newInstallationId }))) {\n        throw new Error('Source-control installation not found');\n      }\n      // Check if a repository with the same external_id exists under the new installation\n      const conflict = this.repositoriesRows.find(\n        row => row.installationId === newInstallationId && row.externalId === existing.externalId,\n      );\n      if (conflict) {\n        // Return the existing repository under the new installation\n        return conflict;\n      }\n      // Update the repository's installation\n      existing.installationId = newInstallationId;\n      existing.updatedAt = new Date();\n      // Migrate dependent connections to the new installation\n      for (const conn of this.connectionsRows) {\n        if (conn.installationId === existing.installationId) {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/source-control/inmemory.ts#L137-L173","documentation":"Thrown by the in-memory migrateInstallation when the repository identified by { orgId, id } does not exist. Migration requires an existing repository row before moving it to a new installation.","triggerScenarios":"Calling migrateInstallation on the in-memory storage with a deleted or never-created repository id, or with a mismatched orgId.","commonSituations":"Test state reset between cases; ids fabricated in tests; orgId typo so the lookup misses.","solutions":["Ensure the repository is created in the in-memory store before migrating","Use the id returned by repositories.upsert/get","Confirm orgId matches the repository's org"],"exampleFix":"// before\nawait storage.migrateInstallation({ orgId, id: repoId, newInstallationId });\n// after\nif (!(await storage.repositories.get({ orgId, id: repoId }))) {\n  await storage.repositories.upsert({ orgId, input: { installationId: oldInstId, externalId, name } });\n}\nawait storage.migrateInstallation({ orgId, id: repoId, newInstallationId });","handlingStrategy":"validation","validationCode":"if (!(await storage.repositories.get({ orgId, id }))) {\n  throw new Error(`Repository ${id} must exist before migration`);\n}","typeGuard":"function isExistingRepo(r: SourceControlRepository | null): r is SourceControlRepository {\n  return r !== null && typeof r.externalId === 'string';\n}","tryCatchPattern":"try {\n  await storage.migrateInstallation({ orgId, id, newInstallationId });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Repository')) {\n    throw new Error(`Seed repository ${id} in the in-memory store first`);\n  } else throw e;\n}","preventionTips":["Create the repository in the same test setup as the migration call","Use ids returned by upsert, not invented ones","Keep orgId consistent across fixture helpers"],"tags":["source-control","not-found","migration","in-memory"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}