{"record":{"id":"bd92440751033b12","repo":"mastra-ai/mastra","slug":"repository-not-found-for-this-organization","errorCode":null,"errorMessage":"Repository not found for this organization.","messagePattern":"Repository not found for this organization\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/session-subscriptions.ts","lineNumber":116,"sourceCode":"\nasync function resolveSessionTarget(requestContext: RequestContext, github: GithubIntegration): Promise<SessionTarget> {\n  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,","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/session-subscriptions.ts#L98-L134","documentation":"resolveSessionTarget loads the repository record referenced by the project repository's repositoryId. If missing for the organization, this error is thrown, meaning the project repository references a repository record that no longer exists (or belongs to another org).","triggerScenarios":"repositories.get({ orgId, id: projectRepository.repositoryId }) returns undefined — repo deleted from storage or org mismatch.","commonSituations":"Repository removed from the GitHub connection sync while a project repository still points at it; hard-deleted rows during migrations.","solutions":["Re-sync repositories for the connection so the repository record is restored","Verify the repositoryId on the project repository references an existing repositories row","Delete and recreate the project repository selection"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const repo = await storage.repositories.get({ orgId, id: projectRepository.repositoryId });\nif (!repo) throw new Error('repository missing — re-sync repositories for this connection');","typeGuard":null,"tryCatchPattern":"try {\n  await subscribe(...);\n} catch (e) {\n  if (e.message.includes('Repository not found')) {\n    // trigger a repository re-sync then retry once\n  }\n}","preventionTips":["Keep repository records in sync with the GitHub connection","Validate repositoryId references at project-repository creation time","Avoid hard-deleting repository rows that project repositories still reference"],"tags":["storage","not-found","github"],"backgroundTag":"record-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}