mastra-ai/mastra · error
Source-control connection not found for this organization.
Error message
Source-control connection not found for this organization.
What it means
resolveSessionTarget loads the source-control connection referenced by the project repository's connectionId. If no connection record exists for the organization, this error is thrown — the project repository points to a deleted or foreign connection.
Source
Thrown at mastracode/factory/src/integrations/github/session-subscriptions.ts:114
);
}
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 {View on GitHub (pinned to 75dd419e61)
Solutions
- Reconnect the GitHub installation and create a fresh connection, then re-link the project repository
- Verify the connectionId on the project repository matches an existing connections row in the same org
- Remove the orphaned project repository and re-add it after reconnecting
Defensive patterns
Strategy: validation
Validate before calling
const conn = await storage.connections.get({ orgId, id: projectRepository.connectionId });
if (!conn) throw new Error('connection missing — reconnect the GitHub installation'); Try / catch
try {
await subscribe(...);
} catch (e) {
if (e.message.includes('connection not found')) {
// prompt user to reconnect the GitHub App
}
} Prevention
- Handle GitHub App uninstall webhooks by cleaning up dependent project repositories
- Check connection existence before linking repositories to it
- Cascade-delete project repositories when their connection is removed
When it happens
Trigger: connections.get({ orgId, id: projectRepository.connectionId }) returns undefined because the connection was deleted or was created under a different org.
Common situations: GitHub App connection uninstalled/removed while project repositories still reference it; dangling foreign keys after cleanup scripts; cross-org data access attempts.
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.
- Repository 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/17216c4794b6d4fa.
Report an issue: GitHub.