mastra-ai/mastra · error · HTTPException
Source control provider cannot open change requests
Error message
Source control provider cannot open change requests
What it means
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.
Source
Thrown at packages/server/src/server/handlers/stored-agents.ts:443
},
});
export const OPEN_STORED_AGENT_CHANGE_REQUEST_ROUTE = createRoute({
method: 'POST',
path: '/stored/agents/:storedAgentId/change-request',
responseType: 'json',
pathParamSchema: storedAgentIdPathParams,
bodySchema: openStoredAgentChangeRequestBodySchema,
responseSchema: openStoredAgentChangeRequestResponseSchema,
summary: 'Open stored agent source change request',
description: 'Opens a source-provider change request for deterministic agent override JSON without mutating storage',
tags: ['Stored Agents'],
requiresAuth: true,
handler: async ({ mastra, requestContext, storedAgentId, ...body }) => {
try {
const provider = mastra.getEditor?.()?.getSourceControlProvider?.();
if (!provider?.openChangeRequest) {
throw new HTTPException(400, { message: 'Source control provider cannot open change requests' });
}
const openChangeRequest = provider.openChangeRequest.bind(provider);
const { changeMessage, userName, inspectOnly, ...exportBody } = body;
const headRef = sourceChangeRequestHeadRef(storedAgentId);
const title = `Update ${storedAgentId} agent override`;
const result = inspectOnly
? await openChangeRequest({
title,
headRef,
files: [],
})
: await (async () => {
const response = await buildStoredAgentExport({ mastra, requestContext, storedAgentId, body: exportBody });
const message = sourceChangeRequestMessage(storedAgentId, userName, changeMessage);
return openChangeRequest({
title,
body: `Updates ${response.fileName} from Mastra Studio.`,View on GitHub (pinned to 75dd419e61)
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
Example fix
// before
post(`/stored/agents/${id}/change-request`, body); // 400 in bare server
// after
if (editor.getSourceControlProvider()?.openChangeRequest) {
await post(`/stored/agents/${id}/change-request`, body);
} else {
await post(`/stored/agents/${id}/export`, body);
} Defensive patterns
Strategy: type-guard
Validate before calling
const provider = mastra.getEditor?.()?.getSourceControlProvider?.();
if (typeof provider?.openChangeRequest !== 'function') {
throw new Error('Source control provider unavailable; use export endpoint instead');
} Type guard
function canOpenChangeRequest(editor: unknown): editor is { getSourceControlProvider(): { openChangeRequest: Function } } {
const p = (editor as any)?.getSourceControlProvider?.();
return typeof p?.openChangeRequest === 'function';
} Try / catch
try {
return await post(`/stored/agents/${id}/change-request`, body);
} catch (e) {
if ((e as any).status === 400 && /cannot open change requests/.test((e as any).message)) {
return post(`/stored/agents/${id}/export`, body); // degrade to export
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- bad request: ${responseText}
- source_control_missing_or_source_repository_missing
- source_control_missing
- ${resolved.reason}
- Source-control installation not found for this organization
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/154aa992ca81a1c3.
Report an issue: GitHub.