mastra-ai/mastra · error

Source-control installation not found

Error message

Source-control installation not found

What it means

Thrown by the in-memory storage upsertRepository when the referenced installation does not exist for the org. Repositories must be attached to an existing installation; the in-memory implementation validates this eagerly.

Source

Thrown at mastracode/factory/src/storage/domains/source-control/inmemory.ts:116

      installationId: string;
      externalId: string;
    }) => {
      const rows = await this.repositories.list({ orgId, installationId });
      return rows.find(row => row.externalId === externalId) ?? null;
    },
    findBySlug: async ({ orgId, installationId, slug }: { orgId: string; installationId: string; slug: string }) => {
      const rows = await this.repositories.list({ orgId, installationId });
      return rows.find(row => row.slug === slug) ?? null;
    },
    upsert: async ({
      orgId,
      input,
    }: {
      orgId: string;
      input: UpsertSourceControlRepositoryInput;
    }): Promise<SourceControlRepository> => {
      if (!(await this.installations.get({ orgId, id: input.installationId }))) {
        throw new Error('Source-control installation not found');
      }
      const existing = this.repositoriesRows.find(
        row => row.installationId === input.installationId && row.externalId === input.externalId,
      );
      const now = new Date();
      if (existing) {
        Object.assign(existing, {
          slug: input.slug,
          defaultBranch: input.defaultBranch,
          providerMetadata: input.providerMetadata ?? {},
          updatedAt: now,
        });
        return existing;
      }
      const created: SourceControlRepository = {
        id: randomUUID(),
        installationId: input.installationId,
        externalId: input.externalId,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Create the installation first (installations.create/upsert) before upserting repositories
  2. Pass the correct installationId from the created installation
  3. Verify orgId matches the installation's org

Example fix

// before
await storage.repositories.upsert({ orgId, input: { installationId, externalId, name } });
// after
if (!(await storage.installations.get({ orgId, id: installationId }))) {
  await storage.installations.create({ orgId, input: { externalId: 'ext-1' } });
}
await storage.repositories.upsert({ orgId, input: { installationId, externalId, name } });
Defensive patterns

Strategy: validation

Validate before calling

if (!(await storage.installations.get({ orgId, id: installationId }))) {
  throw new Error(`Installation ${installationId} must exist before upserting repositories`);
}

Type guard

function hasInstallation(i: unknown): i is { id: string; orgId: string } {
  return !!i && typeof i === 'object' && 'id' in i;
}

Try / catch

try {
  await storage.repositories.upsert({ orgId, input });
} catch (e) {
  if (e instanceof Error && e.message === 'Source-control installation not found') {
    const inst = await storage.installations.create({ orgId, input: { externalId: input.externalId } });
    await storage.repositories.upsert({ orgId, input: { ...input, installationId: inst.id } });
  } else throw e;
}

Prevention

When it happens

Trigger: Upserting a repository with input.installationId that was never registered via installations.create/upsert, or after the installation was deleted.

Common situations: Test fixtures creating repos before installations; resetting in-memory state and losing installations while repo IDs are reused; wrong orgId on the installation lookup.

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


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