mastra-ai/mastra · error

Pull request repository does not match the active project re

Error message

Pull request repository does not match the active project repository.

What it means

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.

Source

Thrown at mastracode/factory/src/integrations/github/session-subscriptions.ts:128

    id: projectRepositoryId,
  });
  if (!projectRepository) throw new Error('Project repository not found for this organization.');
  const connection = await github.sourceControlStorage.connections.get({ orgId, id: projectRepository.connectionId });
  if (!connection) throw new Error('Source-control connection not found for this organization.');
  const repository = await github.sourceControlStorage.repositories.get({ orgId, id: projectRepository.repositoryId });
  if (!repository) throw new Error('Repository not found for this organization.');
  const installation = await github.sourceControlStorage.installations.get({ orgId, id: connection.installationId });
  if (!installation) throw new Error('Source-control installation not found for this organization.');
  return { context, projectRepository, connection, installation, repository, orgId, userId };
}

async function verifyPullRequest(target: SessionTarget, pullRequest: number, github: GithubIntegration) {
  const [owner, repo] = target.repository.slug.split('/');
  if (!owner || !repo) throw new Error('GitHub repository is invalid.');
  const octokit = github.getInstallationOctokit(Number(target.installation.externalId));
  const { data } = await octokit.pulls.get({ owner, repo, pull_number: pullRequest });
  if (String(data.base.repo.id) !== target.repository.externalId)
    throw new Error('Pull request repository does not match the active project repository.');
}

async function subscriptionInput(target: SessionTarget, pullRequestNumber: number) {
  return {
    orgId: target.orgId,
    installationExternalId: target.installation.externalId,
    projectRepositoryId: target.projectRepository.id,
    repositoryExternalId: target.repository.externalId,
    repositorySlug: target.repository.slug,
    changeRequestId: String(pullRequestNumber),
    sessionId: target.context.session.id,
    ownerId: target.context.session.ownerId,
    resourceId: target.connection.factoryProjectId,
    threadId: target.context.threadId!,
    sessionScope: target.context.scope,
    source: 'explicit-tool' as const,
    subscribedByUserId: target.userId,
  };

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Use a PR number that exists in the active project repository, not a fork
  2. Verify the project repository's externalId matches the GitHub repo containing the PR
  3. Switch the session's project repository to the one the PR actually belongs to

Example fix

// before
subscribeCurrentSessionToPullRequest(12); // PR from a fork
// after
subscribeCurrentSessionToPullRequest(34); // PR in the active project repository
Defensive patterns

Strategy: validation

Validate before calling

const pr = await octokit.pulls.get({ owner, repo, pull_number: n });
if (String(pr.data.base.repo.id) !== repository.externalId) {
  throw new Error(`PR ${n} belongs to ${pr.data.base.repo.full_name}, not the active repository`);
}

Try / catch

try {
  await subscribeCurrentSessionToPullRequest(n);
} catch (e) {
  if (e.message.includes('does not match the active project repository')) {
    // ask the user to pick a PR from the active repository
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/f65d3fcd7bbc01d3. Report an issue: GitHub.