{"record":{"id":"4664a4688f632a57","repo":"eyaltoledano/claude-task-master","slug":"session-set-failed","errorCode":"SESSION_SET_FAILED","errorMessage":"Failed to set session: ${error.message}","messagePattern":"Failed to set session: (.+?)","errorType":"error_code","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/integration/clients/supabase-client.ts","lineNumber":353,"sourceCode":"\t\t} catch (error) {\n\t\t\tthis.logger.error('Error during sign out:', error);\n\t\t}\n\t}\n\n\t/**\n\t * Set session from external auth (e.g., from server callback)\n\t */\n\tasync setSession(session: Session): Promise<void> {\n\t\tconst client = this.getClient();\n\n\t\ttry {\n\t\t\tconst { error } = await client.auth.setSession({\n\t\t\t\taccess_token: session.access_token,\n\t\t\t\trefresh_token: session.refresh_token\n\t\t\t});\n\n\t\t\tif (error) {\n\t\t\t\tthrow new AuthenticationError(\n\t\t\t\t\t`Failed to set session: ${error.message}`,\n\t\t\t\t\t'SESSION_SET_FAILED'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.logger.info('Session set successfully');\n\t\t} catch (error) {\n\t\t\tif (error instanceof AuthenticationError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthrow new AuthenticationError(\n\t\t\t\t`Failed to set session: ${(error as Error).message}`,\n\t\t\t\t'SESSION_SET_FAILED'\n\t\t\t);\n\t\t}\n\t}\n","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/integration/clients/supabase-client.ts#L335-L371","documentation":"In SupabaseClient.setSession(), when `client.auth.setSession({access_token, refresh_token})` returns an error from Supabase, it is wrapped as AuthenticationError with code SESSION_SET_FAILED. This means Supabase rejected the token pair being installed as the current session — typically because the refresh token is invalid, expired, or already used.","triggerScenarios":"Calling setSession(session) with a Session whose access_token/refresh_token Supabase refuses: refresh_token_not_found, invalid refresh token, or a token from a different project/instance.","commonSituations":"Passing a session captured from another environment (staging vs prod project); reusing a refresh token after Supabase rotated/invalidated it (single-use refresh tokens enabled); server callback handing over a truncated or stale session; SUPABASE_URL/KEY pointing to a different project than the one that issued the tokens.","solutions":["Verify the tokens came from the same Supabase project configured in the client (URL and anon key match).","Check the refresh token is still valid and unused — with rotating refresh tokens, only the latest token works; re-authenticate if it was already consumed.","Ensure the session object passed in is complete (access_token and refresh_token both present and unmodified).","Read error.message in the thrown error for the Supabase code and act on it (e.g. refresh_token_not_found → new login)."],"exampleFix":"// before\nawait client.setSession(oldCapturedSession);\n// after\nif (!oldCapturedSession?.access_token || !oldCapturedSession?.refresh_token) {\n  throw new Error('Incomplete session; run login again');\n}\ntry {\n  await client.setSession(oldCapturedSession);\n} catch (e) {\n  // fall back to fresh login\n}","handlingStrategy":"validation","validationCode":"function canSetSession(s: unknown): s is Session {\n  const x = s as Partial<Session> | null;\n  return !!x && typeof x.access_token === 'string' && x.access_token.length > 0 &&\n         typeof x.refresh_token === 'string' && x.refresh_token.length > 0;\n}\nif (!canSetSession(incomingSession)) throw new Error('Incomplete session tokens');\nawait client.setSession(incomingSession);","typeGuard":"function isSession(s: unknown): s is Session {\n  const x = s as Record<string, unknown> | null;\n  return !!x && typeof x.access_token === 'string' && typeof x.refresh_token === 'string';\n}","tryCatchPattern":"try {\n  await client.setSession(session);\n} catch (e) {\n  if (e instanceof AuthenticationError && e.code === 'SESSION_SET_FAILED') {\n    // tokens rejected: clear state and force fresh login\n    await client.signOut();\n  } else throw e;\n}","preventionTips":["Only pass sessions issued by the same Supabase project the client is configured for.","Never reuse refresh tokens after they may have been rotated (single-use tokens).","Validate token fields exist and are strings before calling setSession.","Keep SUPABASE_URL/anon key aligned with the environment that minted the tokens."],"tags":["auth","session","supabase","token"],"backgroundTag":"refresh-token-invalid","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}