{"record":{"id":"f65d3fcd7bbc01d3","repo":"mastra-ai/mastra","slug":"pull-request-repository-does-not-match-the-active","errorCode":null,"errorMessage":"Pull request repository does not match the active project repository.","messagePattern":"Pull request repository does not match the active project repository\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/session-subscriptions.ts","lineNumber":128,"sourceCode":"    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,\n    repositorySlug: target.repository.slug,\n    changeRequestId: String(pullRequestNumber),\n    sessionId: target.context.session.id,\n    ownerId: target.context.session.ownerId,\n    resourceId: target.connection.factoryProjectId,\n    threadId: target.context.threadId!,\n    sessionScope: target.context.scope,\n    source: 'explicit-tool' as const,\n    subscribedByUserId: target.userId,\n  };","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/session-subscriptions.ts#L110-L146","documentation":"verifyPullRequest fetches the PR via the installation Octokit and compares the PR's base repository id (data.base.repo.id) with the active project repository's externalId. A mismatch means the subscription targets a PR living in a different repository than the one linked to the session, so the error is thrown.","triggerScenarios":"Subscribing with a PR number that exists on GitHub but belongs to another repository (or a fork) than the active project repository, after parsePullRequest allowed a bare number without repo context.","commonSituations":"Users passing a PR number from a fork rather than the upstream repo; copying a PR number from another repository; repository re-pointed to a different GitHub repo with the same numeric PR ids.","solutions":["Use a PR number that exists in the active project repository, not a fork","Verify the project repository's externalId matches the GitHub repo containing the PR","Switch the session's project repository to the one the PR actually belongs to"],"exampleFix":"// before\nsubscribeCurrentSessionToPullRequest(12); // PR from a fork\n// after\nsubscribeCurrentSessionToPullRequest(34); // PR in the active project repository","handlingStrategy":"validation","validationCode":"const pr = await octokit.pulls.get({ owner, repo, pull_number: n });\nif (String(pr.data.base.repo.id) !== repository.externalId) {\n  throw new Error(`PR ${n} belongs to ${pr.data.base.repo.full_name}, not the active repository`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await subscribeCurrentSessionToPullRequest(n);\n} catch (e) {\n  if (e.message.includes('does not match the active project repository')) {\n    // ask the user to pick a PR from the active repository\n  }\n}","preventionTips":["Pass the full PR URL (not a bare number) so the repo can be checked upfront","List the active repository's PRs and let users pick from them","Verify PR repository id before subscribing, not after"],"tags":["github","pull-request","validation","mismatch"],"backgroundTag":"repository-mismatch","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}