mastra-ai/mastra · error

Project repository not found for this organization.

Error message

Project repository not found for this organization.

What it means

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.

Source

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

    sessionOrgId(requestContext) &&
    sessionUserId(requestContext),
  );
}

async function resolveSessionTarget(requestContext: RequestContext, github: GithubIntegration): Promise<SessionTarget> {
  const context = requestContext.get('controller') as AgentControllerRequestContext<RepositorySessionState> | undefined;
  const orgId = sessionOrgId(requestContext);
  const userId = sessionUserId(requestContext);
  const projectRepositoryId = context?.getState().projectRepositoryId;
  if (!context || !context.threadId || !projectRepositoryId || !orgId || !userId) {
    throw new Error('GitHub subscriptions require an authenticated repository session with an active thread.');
  }

  const projectRepository = await github.sourceControlStorage.projectRepositories.get({
    orgId,
    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.');
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Re-select the project repository in the session so projectRepositoryId points to an existing row
  2. Verify the record exists in projectRepositories storage for the session's orgId
  3. Clear/reset the stale session state and re-initialize the repository session
Defensive patterns

Strategy: validation

Validate before calling

const pr = await storage.projectRepositories.get({ orgId, id: projectRepositoryId });
if (!pr) throw new Error('stale projectRepositoryId — reselect the project repository');

Try / catch

try {
  await subscribe(...);
} catch (e) {
  if (e.message.includes('Project repository not found')) {
    // refresh session state: re-select a project repository
  }
}

Prevention

When it happens

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

Common situations: Repository removed by an admin while an old browser session still referenced it; cross-org session replay; data migration dropping projectRepositories rows.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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