mastra-ai/mastra · error
Repository not found for this organization.
Error message
Repository not found for this organization.
What it means
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).
Source
Thrown at mastracode/factory/src/integrations/github/session-subscriptions.ts:116
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.');
}
async function subscriptionInput(target: SessionTarget, pullRequestNumber: number) {
return {
orgId: target.orgId,
installationExternalId: target.installation.externalId,View on GitHub (pinned to 75dd419e61)
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
Defensive patterns
Strategy: validation
Validate before calling
const repo = await storage.repositories.get({ orgId, id: projectRepository.repositoryId });
if (!repo) throw new Error('repository missing — re-sync repositories for this connection'); Try / catch
try {
await subscribe(...);
} catch (e) {
if (e.message.includes('Repository not found')) {
// trigger a repository re-sync then retry once
}
} Prevention
- 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
When it happens
Trigger: repositories.get({ orgId, id: projectRepository.repositoryId }) returns undefined — repo deleted from storage or org mismatch.
Common situations: Repository removed from the GitHub connection sync while a project repository still points at it; hard-deleted rows during migrations.
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
- Version-control repository not found.
- Project repository not found for this organization.
- Source-control connection not found for this organization.
- Source-control installation not found for this organization.
- Version-control repository not found.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/bd92440751033b12.
Report an issue: GitHub.