{"record":{"id":"154aa992ca81a1c3","repo":"mastra-ai/mastra","slug":"source-control-provider-cannot-open-change-request","errorCode":null,"errorMessage":"Source control provider cannot open change requests","messagePattern":"Source control provider cannot open change requests","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/stored-agents.ts","lineNumber":443,"sourceCode":"  },\n});\n\nexport const OPEN_STORED_AGENT_CHANGE_REQUEST_ROUTE = createRoute({\n  method: 'POST',\n  path: '/stored/agents/:storedAgentId/change-request',\n  responseType: 'json',\n  pathParamSchema: storedAgentIdPathParams,\n  bodySchema: openStoredAgentChangeRequestBodySchema,\n  responseSchema: openStoredAgentChangeRequestResponseSchema,\n  summary: 'Open stored agent source change request',\n  description: 'Opens a source-provider change request for deterministic agent override JSON without mutating storage',\n  tags: ['Stored Agents'],\n  requiresAuth: true,\n  handler: async ({ mastra, requestContext, storedAgentId, ...body }) => {\n    try {\n      const provider = mastra.getEditor?.()?.getSourceControlProvider?.();\n      if (!provider?.openChangeRequest) {\n        throw new HTTPException(400, { message: 'Source control provider cannot open change requests' });\n      }\n\n      const openChangeRequest = provider.openChangeRequest.bind(provider);\n      const { changeMessage, userName, inspectOnly, ...exportBody } = body;\n      const headRef = sourceChangeRequestHeadRef(storedAgentId);\n      const title = `Update ${storedAgentId} agent override`;\n      const result = inspectOnly\n        ? await openChangeRequest({\n            title,\n            headRef,\n            files: [],\n          })\n        : await (async () => {\n            const response = await buildStoredAgentExport({ mastra, requestContext, storedAgentId, body: exportBody });\n            const message = sourceChangeRequestMessage(storedAgentId, userName, changeMessage);\n            return openChangeRequest({\n              title,\n              body: `Updates ${response.fileName} from Mastra Studio.`,","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-agents.ts#L425-L461","documentation":"POST /stored/agents/:storedAgentId/change-request requires an editor with a source control provider that supports openChangeRequest. If mastra.getEditor()?.getSourceControlProvider() is missing or its provider lacks openChangeRequest, the route throws HTTP 400: opening PRs/MRs against source control is not available in this deployment.","triggerScenarios":"Calling the change-request endpoint when no editor is configured (getEditor undefined), the editor has no source control provider, or the provider is a type without openChangeRequest (e.g. read-only/local provider without git integration).","commonSituations":"Running mastra dev/local playground without GitHub/Git integration configured; production deployment where the editor plugin is intentionally omitted; provider supports only basic operations but not change requests; inspectOnly mode attempted without any provider at all.","solutions":["Configure the Mastra editor with a source-control provider that implements openChangeRequest (e.g. GitHub-backed provider)","Check provider capability before calling: provider?.openChangeRequest exists","If change requests aren't needed, use the plain export endpoint POST /stored/agents/:id/export instead","Verify the editor plugin is registered via mastra.getEditor() in the running server"],"exampleFix":"// before\npost(`/stored/agents/${id}/change-request`, body); // 400 in bare server\n// after\nif (editor.getSourceControlProvider()?.openChangeRequest) {\n  await post(`/stored/agents/${id}/change-request`, body);\n} else {\n  await post(`/stored/agents/${id}/export`, body);\n}","handlingStrategy":"type-guard","validationCode":"const provider = mastra.getEditor?.()?.getSourceControlProvider?.();\nif (typeof provider?.openChangeRequest !== 'function') {\n  throw new Error('Source control provider unavailable; use export endpoint instead');\n}","typeGuard":"function canOpenChangeRequest(editor: unknown): editor is { getSourceControlProvider(): { openChangeRequest: Function } } {\n  const p = (editor as any)?.getSourceControlProvider?.();\n  return typeof p?.openChangeRequest === 'function';\n}","tryCatchPattern":"try {\n  return await post(`/stored/agents/${id}/change-request`, body);\n} catch (e) {\n  if ((e as any).status === 400 && /cannot open change requests/.test((e as any).message)) {\n    return post(`/stored/agents/${id}/export`, body); // degrade to export\n  }\n  throw e;\n}","preventionTips":["Configure a git-backed source control provider in the editor for deployments needing PRs","Capability-check provider.openChangeRequest before exposing change-request UI","Offer export as the fallback flow when provider support is absent","Document which deployments (local vs cloud) support change requests"],"tags":["http-400","source-control","feature-availability"],"backgroundTag":"capability-not-supported","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}