{"record":{"id":"2cf9b132821a115d","repo":"mastra-ai/mastra","slug":"source-control-installation-not-found-for-this-org-2cf9b1","errorCode":null,"errorMessage":"Source-control installation not found for this organization and integration.","messagePattern":"Source-control installation not found for this organization and integration\\.","errorType":"exception","errorClass":null,"httpStatus":404,"severity":"error","filePath":"mastracode/factory/src/storage/domains/source-control/base.ts","lineNumber":560,"sourceCode":"  }\n\n  forIntegration(integrationId: string): SourceControlStorageHandle {\n    if (!integrationId.trim()) throw new Error('[SourceControlStorage] integrationId must not be empty.');\n    const db = (): FactoryStorageOps => this.ops;\n\n    const getInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation | null> => {\n      const row = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n        id: args.id,\n        integration_id: integrationId,\n        org_id: args.orgId,\n      });\n      return row ? toInstallation(row) : null;\n    };\n\n    const requireInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation> => {\n      const installation = await getInstallation(args);\n      if (!installation)\n        throw new Error('Source-control installation not found for this organization and integration.');\n      return installation;\n    };\n\n    const getRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {\n      const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: args.id });\n      if (!row || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n      return toRepository(row);\n    };\n\n    const requireRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository> => {\n      const repository = await getRepository(args);\n      if (!repository) throw new Error('Source-control repository not found for this organization and integration.');\n      return repository;\n    };\n\n    const getConnection = async (args: {\n      orgId: string;\n      id: string;","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/source-control/base.ts#L542-L578","documentation":"requireInstallation loads a source-control installation by orgId and id via getInstallation and throws a plain Error ('Source-control installation not found...') when no row matches. forIntegration depends on it, so any read of repositories/config under an installation first asserts the installation exists for that org.","triggerScenarios":"Calling forIntegration (or another method that routes through requireInstallation) with an installation id that doesn't exist, or an installation belonging to a different orgId than the one passed.","commonSituations":"Using an installation ID from a deleted/uninstalled GitHub app; hardcoding an ID from another environment; orgId mismatch after tenant/organization switch; DB wipe or migration leaving orphaned repository rows.","solutions":["Verify the installation id is correct and still exists for the given orgId","Re-authorize/reinstall the source-control app to recreate the installation if it was revoked","List installations for the org to get the current valid id","Ensure the orgId used matches the installation's organization"],"exampleFix":"// before\nawait sourceControl.forIntegration({ orgId, id: staleInstallationId });\n// after\nconst existing = await sourceControl.getInstallation?.({ orgId, id: staleInstallationId });\nif (!existing) throw new Error('Reinstall the source-control app to recreate the installation');\nawait sourceControl.forIntegration({ orgId, id: staleInstallationId });","handlingStrategy":"try-catch","validationCode":"const installation = await sourceControl.getInstallation?.({ orgId, id });\nif (!installation) throw new Error(`Installation ${id} not found for org ${orgId}; reinstall the source-control app.`);","typeGuard":"function hasInstallation<T extends SourceControlInstallation | null>(x: T): x is Exclude<T, null> {\n  return x !== null;\n}","tryCatchPattern":"try {\n  const integration = await sourceControl.forIntegration({ orgId, id });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('installation not found')) {\n    // trigger re-auth / app reinstall flow for the org\n    await promptSourceControlReconnect(orgId);\n  } else throw e;\n}","preventionTips":["Resolve installation IDs dynamically by listing installations for the org, never hardcode","Handle app uninstall webhooks to clean up local references","Scope the orgId together with the installation id in one typed lookup","Add a health check that flags installations missing from the DB"],"tags":["source-control","installation","not-found","storage"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}