{"record":{"id":"6865eca206cadc3b","repo":"mastra-ai/mastra","slug":"version-control-repository-not-found","errorCode":null,"errorMessage":"Version-control repository not found.","messagePattern":"Version-control repository not found\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/integration.ts","lineNumber":293,"sourceCode":"      }),\n    registerRepositories: ({ orgId, installationId, repositories }) =>\n      Promise.all(\n        repositories.map(repository =>\n          this.sourceControlStorage.repositories.upsert({\n            orgId,\n            input: {\n              installationId,\n              externalId: repository.externalId,\n              slug: repository.slug,\n              defaultBranch: repository.defaultBranch,\n              providerMetadata: repository.metadata,\n            },\n          }),\n        ),\n      ),\n    getRepositoryAccess: async ({ orgId, repositoryId }) => {\n      const repository = await this.sourceControlStorage.repositories.get({ orgId, id: repositoryId });\n      if (!repository) throw new Error('Version-control repository not found.');\n      const installation = await this.sourceControlStorage.installations.get({\n        orgId,\n        id: repository.installationId,\n      });\n      if (!installation) throw new Error('Version-control installation not found.');\n      const installationId = Number.parseInt(installation.externalId, 10);\n      if (!Number.isSafeInteger(installationId)) throw new Error('GitHub installation id is invalid.');\n      return {\n        cloneUrl: `https://github.com/${repository.slug}.git`,\n        authorization: { scheme: 'bearer', token: await this.mintInstallationToken(installationId) },\n      };\n    },\n    listPullRequests: input => this.#listPullRequests(input),\n    getPullRequest: input => this.#getPullRequest(input),\n    createPullRequest: input => this.#createPullRequest(input),\n    updatePullRequest: input => this.#updatePullRequest(input),\n    closePullRequest: input => this.#closePullRequest(input),\n    mergePullRequest: input => this.#mergePullRequest(input),","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/integration.ts#L275-L311","documentation":"getRepositoryAccess resolves a repository by orgId and repositoryId from the source-control storage; if no repository record exists for that pair, it throws 'Version-control repository not found.' This is a runtime existence check (deliberately kept in execute logic, not schema validation) that also guards the follow-up installation lookup, since the repository record carries the installationId needed to resolve GitHub App installation access.","triggerScenarios":"Calling getRepositoryAccess({ orgId, repositoryId }) where the repositories table has no row with that orgId/id — e.g. a stale repositoryId after the repo was deleted or re-synced, a wrong org, or a repository stored under a different orgId than the one passed.","commonSituations":"Referencing a repository id from another environment's database; repository removed by a sync/prune job while cached references remain; passing the GitHub repo's external numeric id instead of the internal repository record id; cross-tenant lookup where orgId doesn't match the stored row.","solutions":["Verify the orgId/repositoryId pair exists: query sourceControlStorage.repositories.get({ orgId, id: repositoryId }) or list repositories for the org and confirm the id.","Re-sync the org's repositories so deleted/renamed repos are refreshed, then retry with the current id.","Use the internal repository record id, not the GitHub external id — the lookup is by the stored record's id field.","Ensure the caller is using the correct orgId (the storage tenant key), not just any org the user belongs to.","Handle the error upstream by returning a 404-style response to the requester instead of crashing."],"exampleFix":"// before\nawait github.getRepositoryAccess({ orgId, repositoryId: githubRepoNumberId });\n\n// after\nconst repos = await github.listRepositories({ orgId });\nconst repo = repos.find(r => r.externalId === String(githubRepoNumberId));\nif (!repo) throw new NotFoundError('Repository not synced');\nawait github.getRepositoryAccess({ orgId, repositoryId: repo.id });","handlingStrategy":"try-catch","validationCode":"const repo = await sourceControlStorage.repositories.get({ orgId, id: repositoryId });\nif (!repo) {\n  throw new ObjectNotFoundError(`Repository ${repositoryId} not found in org ${orgId}; re-sync repositories first`);\n}","typeGuard":"function repoExists(repo, orgId, repositoryId) {\n  return repo != null && repo.orgId === orgId && repo.id === repositoryId;\n}","tryCatchPattern":"try {\n  await github.getRepositoryAccess({ orgId, repositoryId });\n} catch (err) {\n  if (err.message === 'Version-control repository not found.') {\n    await github.syncRepositories({ orgId }); // refresh, then retry once\n    return github.getRepositoryAccess({ orgId, repositoryId });\n  }\n  throw err;\n}","preventionTips":["Always resolve repositoryId via the internal record id, not GitHub's external id","Re-sync repositories after upstream renames/deletes before resolving access","Verify orgId matches the storage tenant for the requesting user","Return 404-style responses to callers instead of letting the throw propagate"],"tags":["github","storage","not-found","integration"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}