{"record":{"id":"4c76ba3d6a4cbd13","repo":"mastra-ai/mastra","slug":"project-repository-not-found-for-this-organization","errorCode":null,"errorMessage":"Project repository not found for this organization.","messagePattern":"Project repository not found for this organization\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/session-subscriptions.ts","lineNumber":112,"sourceCode":"    sessionOrgId(requestContext) &&\n    sessionUserId(requestContext),\n  );\n}\n\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","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/session-subscriptions.ts#L94-L130","documentation":"After resolving session identifiers, resolveSessionTarget loads the project repository record from sourceControlStorage using orgId and projectRepositoryId. If no record exists for that organization, this error is thrown. It indicates the session references a project repository that has been deleted or belongs to another org.","triggerScenarios":"Session state holds a stale projectRepositoryId while the underlying projectRepositories record was removed, or the id belongs to a different org than the session's orgId.","commonSituations":"Repository removed by an admin while an old browser session still referenced it; cross-org session replay; data migration dropping projectRepositories rows.","solutions":["Re-select the project repository in the session so projectRepositoryId points to an existing row","Verify the record exists in projectRepositories storage for the session's orgId","Clear/reset the stale session state and re-initialize the repository session"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const pr = await storage.projectRepositories.get({ orgId, id: projectRepositoryId });\nif (!pr) throw new Error('stale projectRepositoryId — reselect the project repository');","typeGuard":null,"tryCatchPattern":"try {\n  await subscribe(...);\n} catch (e) {\n  if (e.message.includes('Project repository not found')) {\n    // refresh session state: re-select a project repository\n  }\n}","preventionTips":["Validate projectRepositoryId against storage when initializing session state","Invalidate sessions when their project repository is deleted","Use onDelete hooks to clear references to removed project repositories"],"tags":["storage","not-found","github","session"],"backgroundTag":"record-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}