{"record":{"id":"7b40d4673049d5ae","repo":"mastra-ai/mastra","slug":"source-control-installation-not-found-for-this-org","errorCode":null,"errorMessage":"Source-control installation not found for this organization.","messagePattern":"Source-control installation not found for this organization\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/session-subscriptions.ts","lineNumber":118,"sourceCode":"  const context = requestContext.get('controller') as AgentControllerRequestContext<RepositorySessionState> | undefined;\n  const orgId = sessionOrgId(requestContext);\n  const userId = sessionUserId(requestContext);\n  const projectRepositoryId = context?.getState().projectRepositoryId;\n  if (!context || !context.threadId || !projectRepositoryId || !orgId || !userId) {\n    throw new Error('GitHub subscriptions require an authenticated repository session with an active thread.');\n  }\n\n  const projectRepository = await github.sourceControlStorage.projectRepositories.get({\n    orgId,\n    id: projectRepositoryId,\n  });\n  if (!projectRepository) throw new Error('Project repository not found for this organization.');\n  const connection = await github.sourceControlStorage.connections.get({ orgId, id: projectRepository.connectionId });\n  if (!connection) throw new Error('Source-control connection not found for this organization.');\n  const repository = await github.sourceControlStorage.repositories.get({ orgId, id: projectRepository.repositoryId });\n  if (!repository) throw new Error('Repository not found for this organization.');\n  const installation = await github.sourceControlStorage.installations.get({ orgId, id: connection.installationId });\n  if (!installation) throw new Error('Source-control installation not found for this organization.');\n  return { context, projectRepository, connection, installation, repository, orgId, userId };\n}\n\nasync function verifyPullRequest(target: SessionTarget, pullRequest: number, github: GithubIntegration) {\n  const [owner, repo] = target.repository.slug.split('/');\n  if (!owner || !repo) throw new Error('GitHub repository is invalid.');\n  const octokit = github.getInstallationOctokit(Number(target.installation.externalId));\n  const { data } = await octokit.pulls.get({ owner, repo, pull_number: pullRequest });\n  if (String(data.base.repo.id) !== target.repository.externalId)\n    throw new Error('Pull request repository does not match the active project repository.');\n}\n\nasync function subscriptionInput(target: SessionTarget, pullRequestNumber: number) {\n  return {\n    orgId: target.orgId,\n    installationExternalId: target.installation.externalId,\n    projectRepositoryId: target.projectRepository.id,\n    repositoryExternalId: target.repository.externalId,","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/session-subscriptions.ts#L100-L136","documentation":"resolveSessionTarget loads the GitHub App installation referenced by the connection's installationId. If no installation record exists for the organization, this error is thrown, blocking any authenticated API calls that require the installation's externalId.","triggerScenarios":"installations.get({ orgId, id: connection.installationId }) returns undefined — installation uninstalled from GitHub and pruned, or connection pointing at a stale installation id.","commonSituations":"GitHub App uninstalled from the org; installation rows purged by a cleanup job while connections still reference them.","solutions":["Reinstall the GitHub App on the organization and re-link the connection","Verify connection.installationId references a valid installations row","Recreate the source-control connection after reinstalling"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const inst = await storage.installations.get({ orgId, id: connection.installationId });\nif (!inst) throw new Error('installation missing — reinstall the GitHub App');","typeGuard":null,"tryCatchPattern":"try {\n  await subscribe(...);\n} catch (e) {\n  if (e.message.includes('installation not found')) {\n    // redirect user through the GitHub App install flow\n  }\n}","preventionTips":["Listen for GitHub App uninstallation events and flag affected connections","Verify installation presence before issuing installation octokits","Recreate connections after reinstalling the GitHub App"],"tags":["storage","not-found","github","installation"],"backgroundTag":"record-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}