{"record":{"id":"caf07b7a8bcb2129","repo":"mastra-ai/mastra","slug":"source-control-installation-not-found","errorCode":null,"errorMessage":"Source-control installation not found","messagePattern":"Source-control installation not found","errorType":"exception","errorClass":null,"httpStatus":404,"severity":"error","filePath":"mastracode/factory/src/storage/domains/source-control/inmemory.ts","lineNumber":116,"sourceCode":"      installationId: string;\n      externalId: string;\n    }) => {\n      const rows = await this.repositories.list({ orgId, installationId });\n      return rows.find(row => row.externalId === externalId) ?? null;\n    },\n    findBySlug: async ({ orgId, installationId, slug }: { orgId: string; installationId: string; slug: string }) => {\n      const rows = await this.repositories.list({ orgId, installationId });\n      return rows.find(row => row.slug === slug) ?? null;\n    },\n    upsert: async ({\n      orgId,\n      input,\n    }: {\n      orgId: string;\n      input: UpsertSourceControlRepositoryInput;\n    }): Promise<SourceControlRepository> => {\n      if (!(await this.installations.get({ orgId, id: input.installationId }))) {\n        throw new Error('Source-control installation not found');\n      }\n      const existing = this.repositoriesRows.find(\n        row => row.installationId === input.installationId && row.externalId === input.externalId,\n      );\n      const now = new Date();\n      if (existing) {\n        Object.assign(existing, {\n          slug: input.slug,\n          defaultBranch: input.defaultBranch,\n          providerMetadata: input.providerMetadata ?? {},\n          updatedAt: now,\n        });\n        return existing;\n      }\n      const created: SourceControlRepository = {\n        id: randomUUID(),\n        installationId: input.installationId,\n        externalId: input.externalId,","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/source-control/inmemory.ts#L98-L134","documentation":"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.","triggerScenarios":"Upserting a repository with input.installationId that was never registered via installations.create/upsert, or after the installation was deleted.","commonSituations":"Test fixtures creating repos before installations; resetting in-memory state and losing installations while repo IDs are reused; wrong orgId on the installation lookup.","solutions":["Create the installation first (installations.create/upsert) before upserting repositories","Pass the correct installationId from the created installation","Verify orgId matches the installation's org"],"exampleFix":"// before\nawait storage.repositories.upsert({ orgId, input: { installationId, externalId, name } });\n// after\nif (!(await storage.installations.get({ orgId, id: installationId }))) {\n  await storage.installations.create({ orgId, input: { externalId: 'ext-1' } });\n}\nawait storage.repositories.upsert({ orgId, input: { installationId, externalId, name } });","handlingStrategy":"validation","validationCode":"if (!(await storage.installations.get({ orgId, id: installationId }))) {\n  throw new Error(`Installation ${installationId} must exist before upserting repositories`);\n}","typeGuard":"function hasInstallation(i: unknown): i is { id: string; orgId: string } {\n  return !!i && typeof i === 'object' && 'id' in i;\n}","tryCatchPattern":"try {\n  await storage.repositories.upsert({ orgId, input });\n} catch (e) {\n  if (e instanceof Error && e.message === 'Source-control installation not found') {\n    const inst = await storage.installations.create({ orgId, input: { externalId: input.externalId } });\n    await storage.repositories.upsert({ orgId, input: { ...input, installationId: inst.id } });\n  } else throw e;\n}","preventionTips":["Seed installations before repositories in fixtures","Reuse installation ids returned from create, not literals","Reset fixtures atomically (installations + repos together)"],"tags":["source-control","not-found","installation","in-memory"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}