{"record":{"id":"24327f8298b29cb4","repo":"mastra-ai/mastra","slug":"source-control-missing","errorCode":"source_control_missing","errorMessage":"error.message (dynamic; SourceControlConnectionNotFoundError)","messagePattern":"error\\.message \\(dynamic; SourceControlConnectionNotFoundError\\)","errorType":"error_code","errorClass":"FactoryDispatchError","httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/routes/surface.ts","lineNumber":233,"sourceCode":"        role: input.role,\n        input: {\n          externalSource: input.item.externalSource,\n          parentWorkItemId: input.item.parentWorkItemId,\n          title: input.item.title,\n          stages: ['intake'],\n          sessions: input.item.sessions,\n          metadata: input.item.metadata,\n        },\n      },\n    });\n  } catch (error) {\n    if (error instanceof FactoryDispatchError) throw error;\n    if (error instanceof FactorySourceSessionResolutionError) {\n      const code = error.reason === 'connection' ? 'source_control_missing' : 'source_repository_missing';\n      throw new FactoryDispatchError(code, error.message, { cause: error });\n    }\n    if (error instanceof SourceControlConnectionNotFoundError) {\n      throw new FactoryDispatchError('source_control_missing', error.message, { cause: error });\n    }\n    if (error instanceof MaterializeError) {\n      throw new FactoryDispatchError(MATERIALIZE_FAILURE_CODE[error.code], error.message, { cause: error });\n    }\n    throw error;\n  }\n}\n\n/**\n * Build the {@link IntegrationContext} handed to an integration when the\n * factory collects its capabilities (routes, workers). One shape everywhere:\n * `assembleFactoryApiRoutes` uses it per registration, and `MastraFactory` uses it\n * when collecting integration workers at finalize.\n */\nexport function buildIntegrationContext(\n  deps: Pick<\n    FactoryApiRoutesDeps,\n    | 'controller'","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/routes/surface.ts#L215-L251","documentation":"If resolving the source-control session fails because no matching source-control connection exists (SourceControlConnectionNotFoundError), prepareFactoryRuleBinding rethrows it as FactoryDispatchError with code 'source_control_missing'. The dynamic message comes from the underlying error describing which connection id/tenant was not found.","triggerScenarios":"A factory rule references a source-control connection id that was deleted, was never registered, or belongs to another tenant; the connection registry lookup returns nothing for the session resolution request.","commonSituations":"Rotated or removed integration credentials without updating rules; environment mismatch (rule created in staging, run in prod with different connections); typo'd connection identifier in the rule configuration; connections not yet installed for a newly onboarded tenant.","solutions":["Register/reconnect the source-control connection referenced by the rule before dispatching.","Verify the connection id in the rule matches an existing connection for the correct tenant/environment.","Check the underlying error message (kept as `cause`) for the missing connection identifier.","Migrate or recreate board rules after connection rotation so they point at the new connection."],"exampleFix":"// before\nawait dispatchFactoryRule({ ruleId, connectionId: 'github-old' }); // deleted connection\n// after\nconst connection = await findConnection('github-acme');\nif (!connection) throw new Error('Connect the GitHub integration first');\nawait dispatchFactoryRule({ ruleId, connectionId: connection.id });","handlingStrategy":"try-catch","validationCode":"const connection = await findSourceControlConnection(connectionId, tenant);\nif (!connection) throw new Error(`Source control connection ${connectionId} is not registered for this tenant`);","typeGuard":null,"tryCatchPattern":"try {\n  await prepareFactoryRuleBinding(input);\n} catch (e) {\n  if (e instanceof FactoryDispatchError && e.code === 'source_control_missing') {\n    logger.error('Source control connection missing; reconnect the integration', { cause: e.cause });\n    return Response.json({ error: 'source control not connected', code: 'source_control_missing' }, { status: 409 });\n  }\n  throw e;\n}","preventionTips":["Register and verify source-control connections before enabling factory rules for a tenant.","Re-point rules at new connections after credential rotation or integration removal.","Validate connection ids in rule configs against the tenant's connection registry at rule-creation time."],"tags":["source-control","connection","dispatch","error-mapping"],"backgroundTag":"source-control-missing","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}