{"record":{"id":"2cd1afa6a79822c8","repo":"paperclipai/paperclip","slug":"connector-profile-invalid","errorCode":"connector_profile_invalid","errorMessage":"Managed authorization has an invalid connector profile","messagePattern":"Managed authorization has an invalid connector profile","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":422,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":3579,"sourceCode":"    session: ToolGatewaySession,\n    connection: typeof toolConnections.$inferSelect,\n    grant: typeof connectionGrants.$inferSelect,\n    forceRefresh = false,\n  ): Promise<typeof connectionGrants.$inferSelect> {\n    const oauth = asRecord(asRecord(connection.config)?.oauth);\n    if (!oauth || !isPaperclipCloudConnectorStrategy(oauth.strategy))\n      return grant;\n    const configuredProfile = oauth.connectorProfile;\n    const connectorProfile:\n      GoogleWorkspaceConnectorProfileId | GitHubConnectorProfileId =\n      configuredProfile === undefined\n        ? \"gmail.draft\"\n        : typeof configuredProfile === \"string\" &&\n            (isGoogleWorkspaceConnectorProfileId(configuredProfile) ||\n              isGitHubConnectorProfileId(configuredProfile))\n          ? configuredProfile\n          : (() => {\n              throw new ToolGatewayHttpError(\n                422,\n                \"Managed authorization has an invalid connector profile\",\n                \"connector_profile_invalid\",\n                {\n                  connectionId: connection.id,\n                  grantId: grant.id,\n                },\n              );\n            })();\n    const connectorSubject =\n      typeof oauth.connectorSubjectAgentId === \"string\"\n        ? `agent:${oauth.connectorSubjectAgentId}`\n        : typeof oauth.connectorSubjectUserId === \"string\"\n          ? oauth.connectorSubjectUserId\n          : grant.kind === \"agent\" && grant.subjectAgentId\n            ? `agent:${grant.subjectAgentId}`\n            : grant.subjectUserId;\n    const grantOauth = asRecord(asRecord(grant.providerTenant)?.oauth);","sourceCodeStart":3561,"sourceCodeEnd":3597,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/server/src/services/tool-gateway.ts#L3561-L3597","documentation":"Managed authorization (managed OAuth) requires a valid connector profile id. The code accepts specific well-known profiles (e.g. \"gmail.draft\") or any profile passing isGoogleWorkspaceConnectorProfileId / isGitHubConnectorProfileId; otherwise it throws HTTP 422 'Managed authorization has an invalid connector profile' (code connector_profile_invalid) with connectionId and grantId context.","triggerScenarios":"A connection/grant's configuredProfile is neither a recognized literal nor a valid Google Workspace or GitHub connector profile id — e.g. malformed string, profile id from an unsupported provider, empty/whitespace value, or a renamed profile id no longer matching the validators.","commonSituations":"Typo in a managed-authorization profile setting (\"gmai.draft\"); profile id copied from another integration (e.g. generic OAuth profile) that isn't in the Google/GitHub validator sets; schema/config drift after a version bump renamed profile ids.","solutions":["Set the connector profile to a supported value (e.g. \"gmail.draft\") or a profile id accepted by isGoogleWorkspaceConnectorProfileId/isGitHubConnectorProfileId.","Log/inspect the connection's configuredProfile and fix the typo or casing.","Migrate old profile ids to the current naming if a version changed the validator.","Add the new provider/profile to the validators only if it is genuinely a supported managed profile."],"exampleFix":"// before\nconst configuredProfile = connection.config.profile; // \"gmai.draft\"\n// after\nconst configuredProfile = isGoogleWorkspaceConnectorProfileId(connection.config.profile) || isGitHubConnectorProfileId(connection.config.profile)\n  ? connection.config.profile\n  : \"gmail.draft\"; // fallback to a known-valid managed profile","handlingStrategy":"validation","validationCode":"import { isGoogleWorkspaceConnectorProfileId, isGitHubConnectorProfileId } from \"@paperclipai/shared\";\nif (!(configuredProfile === \"gmail.draft\" || isGoogleWorkspaceConnectorProfileId(configuredProfile) || isGitHubConnectorProfileId(configuredProfile))) {\n  throw new Error(`Invalid connector profile: ${configuredProfile}`);\n}","typeGuard":"function isValidConnectorProfile(p: unknown): p is string {\n  return typeof p === \"string\" && (p === \"gmail.draft\" || isGoogleWorkspaceConnectorProfileId(p) || isGitHubConnectorProfileId(p));\n}","tryCatchPattern":"try {\n  await gateway.call(session, toolName, args);\n} catch (e) {\n  if (e instanceof ToolGatewayHttpError && e.code === \"connector_profile_invalid\") {\n    // fix connection.config.profile to a supported managed profile and retry\n  }\n  throw e;\n}","preventionTips":["Validate connector profile ids at connection save time, not only at dispatch.","Keep profile-id constants in shared packages so all surfaces use the same validators.","Add integration tests covering each supported managed profile id.","Reject unknown profiles in admin/UI forms with inline validation."],"tags":["validation","oauth","connector","config"],"backgroundTag":"invalid-config-value","analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-09-18T08:03:59.046Z","contentChangedAt":"2026-09-18T08:03:59.046Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}