Fix login blocked by transient FalkorDB unavailability#495
Conversation
Co-authored-by: gkorland <753206+gkorland@users.noreply.github.com>
|
Superseded by #719, which takes a different approach to the same issue (#494). This PR keeps FalkorDB as the primary check and falls back to the session only when the token query raises. That leaves a gap: if the token is simply absent from the graph — because the login-time write failed during the outage, or because FalkorDB restarted without its data — the query succeeds and returns nothing, so the fallback never fires and the user stays stuck. Every request also still pays a graph round trip just to stay logged in. #719 inverts it. The browser login becomes a signed session cookie that is never checked against the database, API tokens stay database-backed but are only consulted when a caller supplies one deliberately, and an unreachable store is reported as 503 rather than 401 so clients retry instead of re-authenticating. Closing in favour of #719. Thanks — the |
|
Superseded by #719, which takes the approach described in this PR's discussion: the blocker is auth-status token validation reaching into the Organizations graph, not the external DB connect step. Linking for traceability — no action needed here. |
When FalkorDB is temporarily down, OAuth login enters a broken loop: the
api_tokencookie is set after OAuth completes, but every/auth-statuscheck fails because the token was never persisted to FalkorDB — causing the login modal to reappear indefinitely.Approach
Use the existing Starlette signed session cookie as a secure auth fallback when FalkorDB is unreachable. Session data is written at login time and validated against the request's
api_tokencookie on each request — token mismatch returns unauthenticated, preventing stale-session abuse.Changes
api/auth/user_management.pyDatabaseUnavailableErrorto distinguish "DB unreachable" from "token not found" (both previously returnedNone)_get_user_inforaisesDatabaseUnavailableErrorinstead of swallowing the exception_validate_from_session(request, api_token)— authenticates from session only whensession["api_token"] == api_tokenvalidate_usercatchesDatabaseUnavailableErrorand delegates to_validate_from_sessionapi/routes/auth.py_store_session_backup(request, user_data, api_token)helpergoogle_authorized,github_authorized,email_login) after the handler stores credentialslogout(both GET and POST) to invalidate the fallback on explicit logouttests/test_session_auth_fallback.pyOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.