{"record":{"id":"0c81ea3cc1ab3009","repo":"slopus/happy","slug":"happy-session-lookup-authentication-expired-for-le","errorCode":null,"errorMessage":"Happy session lookup authentication expired for legacy account credentials.","messagePattern":"Happy session lookup authentication expired for legacy account credentials\\.","errorType":"exception","errorClass":null,"httpStatus":401,"severity":"error","filePath":"packages/happy-cli/src/resume/resolveHappySession.ts","lineNumber":144,"sourceCode":"        throw new Error(`Failed to decrypt metadata for Happy session ${session.id}`);\n    }\n\n    return parseResumableMetadata(session.id, metadata);\n}\n\nasync function fetchSessions(credentials: LocalHappyAgentCredentials): Promise<RawSession[]> {\n    try {\n        const response = await axios.get(`${configuration.serverUrl}/v1/sessions`, {\n            headers: {\n                Authorization: `Bearer ${credentials.token}`,\n                'X-Happy-Client': `cli-coding-session/${configuration.currentCliVersion}`,\n            },\n        });\n        return (response.data as { sessions: RawSession[] }).sessions;\n    } catch (error) {\n        if (error instanceof AxiosError) {\n            if (error.response?.status === 401) {\n                throw new Error('Happy session lookup authentication expired for legacy account credentials.');\n            }\n            throw new Error(`Failed to load Happy sessions: ${error.message}`);\n        }\n        throw error;\n    }\n}\n\nexport async function resolveHappySession(sessionId: string): Promise<ResumableHappySession> {\n    const credentials = readAgentCredentials();\n    const sessions = await fetchSessions(credentials);\n    const matched = resolveSessionRecordByPrefix(sessions, sessionId);\n    return {\n        id: matched.id,\n        active: matched.active,\n        metadata: decryptSessionMetadata(matched, credentials),\n    };\n}\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/resume/resolveHappySession.ts#L126-L162","documentation":"fetchSessions lists the account's sessions from the Happy API using legacy account credentials. When the API responds with HTTP 401 (the auth token is expired or rejected), it throws this dedicated error instead of the generic network message, signaling that the stored legacy credentials are no longer valid and the user must re-authenticate.","triggerScenarios":"Calling fetchSessions (via resolveHappySession / happy resume) when the bearer token in the legacy agent credentials has expired or been revoked and the server returns 401.","commonSituations":"Long-lived machine/credentials not used for weeks; server-side token rotation or session invalidation; password change or account deauthorization on another device; clock skew invalidating JWTs.","solutions":["Re-authenticate (happy auth / login) to obtain fresh credentials, then retry the resume.","Delete stale local credentials if re-login caches oddly, then log in again.","Check system clock sync (NTP) if tokens expire immediately after refresh.","Verify the account hasn't been deauthorized/rotated server-side."],"exampleFix":"// before\n$ happy resume <session-id>   // Happy session lookup authentication expired\n// after\n$ happy auth                  # refresh legacy credentials\n$ happy resume <session-id>","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const session = await resolveHappySession(id);\n} catch (err) {\n  if ((err as Error).message.includes('authentication expired')) {\n    await runAuthFlow();        // refresh credentials\n    return resolveHappySession(id); // single retry after re-auth\n  }\n  throw err;\n}","preventionTips":["Refresh credentials proactively before long-running automations.","Keep system clock synchronized (NTP) to avoid premature JWT expiry.","Detect 401 centrally and trigger re-auth instead of failing the whole command."],"tags":["auth","token-expired","network","api"],"backgroundTag":"jwt-token-expired","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}