mastra-ai/mastra · error
Source-control installation not found for this organization.
Error message
Source-control installation not found for this organization.
What it means
resolveSessionTarget loads the GitHub App installation referenced by the connection's installationId. If no installation record exists for the organization, this error is thrown, blocking any authenticated API calls that require the installation's externalId.
Source
Thrown at mastracode/factory/src/integrations/github/session-subscriptions.ts:118
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,
projectRepositoryId: target.projectRepository.id,
repositoryExternalId: target.repository.externalId,View on GitHub (pinned to 75dd419e61)
Solutions
- Reinstall the GitHub App on the organization and re-link the connection
- Verify connection.installationId references a valid installations row
- Recreate the source-control connection after reinstalling
Defensive patterns
Strategy: validation
Validate before calling
const inst = await storage.installations.get({ orgId, id: connection.installationId });
if (!inst) throw new Error('installation missing — reinstall the GitHub App'); Try / catch
try {
await subscribe(...);
} catch (e) {
if (e.message.includes('installation not found')) {
// redirect user through the GitHub App install flow
}
} Prevention
- Listen for GitHub App uninstallation events and flag affected connections
- Verify installation presence before issuing installation octokits
- Recreate connections after reinstalling the GitHub App
When it happens
Trigger: installations.get({ orgId, id: connection.installationId }) returns undefined — installation uninstalled from GitHub and pruned, or connection pointing at a stale installation id.
Common situations: GitHub App uninstalled from the org; installation rows purged by a cleanup job while connections still reference them.
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.
- Repository 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/7b40d4673049d5ae.
Report an issue: GitHub.