{"record":{"id":"8521df6cbd408cfa","repo":"eyaltoledano/claude-task-master","slug":"internal-error","errorCode":"INTERNAL_ERROR","errorMessage":"Keypair not generated before starting flow","messagePattern":"Keypair not generated before starting flow","errorType":"error_code","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/auth/services/oauth-service.ts","lineNumber":257,"sourceCode":"\t\t// Check if MFA is required\n\t\tawait this.checkAndThrowIfMFARequired();\n\n\t\t// Notify success\n\t\tif (onSuccess) {\n\t\t\tonSuccess(credentials);\n\t\t}\n\n\t\treturn credentials;\n\t}\n\n\t/**\n\t * Start a new authentication flow on the backend\n\t */\n\tprivate async startBackendFlow(): Promise<StartFlowResponse> {\n\t\tconst startUrl = `${this.baseUrl}/api/auth/cli/start`;\n\n\t\tif (!this.keyPair) {\n\t\t\tthrow new AuthenticationError(\n\t\t\t\t'Keypair not generated before starting flow',\n\t\t\t\t'INTERNAL_ERROR'\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tconst response = await fetch(startUrl, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': `TaskMasterCLI/${this.getCliVersion()}`\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tname: 'Task Master CLI',\n\t\t\t\t\tversion: this.getCliVersion(),\n\t\t\t\t\tdevice: os.hostname(),\n\t\t\t\t\tuser: os.userInfo().username,\n\t\t\t\t\tplatform: os.platform(),","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/auth/services/oauth-service.ts#L239-L275","documentation":"startBackendFlow requires the RSA keypair to have been generated before contacting the backend, because the public key must be sent for E2E encryption. If this internal preconditions fails, it throws AuthenticationError with code INTERNAL_ERROR. It is a private method, so this indicates an internal sequencing bug rather than user error.","triggerScenarios":"startBackendFlow invoked without a prior successful keyPair generation step in authenticateWithBackendPKCE — e.g. refactored call ordering, keygen silently skipped, or a subclass overriding the flow incorrectly.","commonSituations":"Appears after library upgrades that changed internal auth sequencing; custom code calling into oauth-service internals; keypair generation previously throwing and being swallowed upstream.","solutions":["Report/fix the internal bug: ensure generateKeypair() runs before startBackendFlow in the auth flow","Update to the latest package version in case this was a sequencing regression","If extending OAuthService, call the standard authenticateWithBackendPKCE entry point instead of private methods"],"exampleFix":"// before\n// internal: startBackendFlow() called before keygen\nawait this.startBackendFlow();\nawait this.generateKeypair();\n// after\nawait this.generateKeypair(); // must precede flow start\nawait this.startBackendFlow();","handlingStrategy":"try-catch","validationCode":"// N/A for users — internal invariant; do not invoke private flow methods directly\n// always enter auth via: oauthService.authenticate()","typeGuard":"function isInternalAuthError(e: unknown): e is AuthenticationError {\n  return e instanceof AuthenticationError && e.code === 'INTERNAL_ERROR';\n}","tryCatchPattern":"try {\n  await auth.authenticate();\n} catch (e) {\n  if (isInternalAuthError(e)) {\n    console.error('Internal auth error — please report this bug with logs:', e.message);\n  } else throw e;\n}","preventionTips":["Only call public entry points (authenticate/authenticateWithBackendPKCE), never private methods","Keep the package updated; this indicates an internal sequencing regression","If subclassing OAuthService, preserve keypair-generation-before-flow-start ordering","Report occurrences with stack trace and version to the maintainers"],"tags":["auth","internal-error","pkce"],"backgroundTag":"internal-state-error","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}