mastra-ai/mastra · error
Source-control repository not found for this organization an
Error message
Source-control repository not found for this organization and integration.
What it means
Thrown by requireRepository when no repository row exists for the given orgId and id, or when its parent installation no longer exists (getRepository returns null if the installation lookup fails). The factory refuses to hand back a repository object that is not backed by both a row and a live installation.
Source
Thrown at mastracode/factory/src/storage/domains/source-control/base.ts:572
return row ? toInstallation(row) : null;
};
const requireInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation> => {
const installation = await getInstallation(args);
if (!installation)
throw new Error('Source-control installation not found for this organization and integration.');
return installation;
};
const getRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {
const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: args.id });
if (!row || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;
return toRepository(row);
};
const requireRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository> => {
const repository = await getRepository(args);
if (!repository) throw new Error('Source-control repository not found for this organization and integration.');
return repository;
};
const getConnection = async (args: {
orgId: string;
id: string;
}): Promise<ProjectSourceControlConnection | null> => {
const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, { id: args.id, integration_id: integrationId });
if (!row) return null;
const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {
id: row.factory_project_id,
org_id: args.orgId,
});
if (!project || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;
return toConnection(row);
};
const requireConnection = async (args: { orgId: string; id: string }): Promise<ProjectSourceControlConnection> => {View on GitHub (pinned to 75dd419e61)
Solutions
- Verify the repository id and orgId are correct and the repository exists under this integration
- Re-create the repository (upsertRepository) or re-link it before calling requireRepository
- Check that the GitHub/App installation still exists (getInstallation) and reinstall if it was revoked
- Ensure you are not mixing repositories across organizations
Example fix
// before
const repo = await sourceControl.repository.require({ orgId, id: maybeStaleId });
// after
const existing = await sourceControl.repository.get({ orgId, id: maybeStaleId });
if (!existing) {
const created = await sourceControl.repository.upsert({ orgId, installationId, externalId, name });
} Defensive patterns
Strategy: try-catch
Validate before calling
const repo = await integration.repositories?.get?.({ orgId, id });
if (!repo) throw new Error(`Repository ${id} missing; upsert it first`); Type guard
function isRepository(v: unknown): v is SourceControlRepository {
return !!v && typeof v === 'object' && 'id' in v && 'installationId' in v;
} Try / catch
try {
repo = await requireRepository({ orgId, id });
} catch (e) {
if (e instanceof Error && e.message.includes('repository not found')) {
repo = await upsertRepository({ orgId, installationId, externalId, name });
} else throw e;
} Prevention
- Always call get before require for optional lookups
- Keep installation and repository lifecycles in sync (reinstall cascades)
- Cache repository ids per org, never across orgs
- Re-fetch ids after any integration reset
When it happens
Trigger: Calling repository require via requireRepository/repository with an id that was never created, a repository belonging to a different org, or a repository whose installation was deleted (so getInstallation returns falsy).
Common situations: Stale repository IDs cached by callers after an installation was uninstalled/revoked; referencing a repo across orgs; typos in repository IDs; repositories created under a different source-control integration.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Repository ${id} not found in organization ${orgId}
- Version-control repository not found.
- source_control_missing_or_source_repository_missing
- Factory session repository not found
- Source-control installation not found for this organization
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/5078ef83a8bb13da.
Report an issue: GitHub.