Skip to content

Fix managed-mode relogin race + style topup CTA as amber button#101

Merged
DJJones66 merged 2 commits into
mainfrom
fix/managed-mode-relogin-and-topup-button
May 1, 2026
Merged

Fix managed-mode relogin race + style topup CTA as amber button#101
DJJones66 merged 2 commits into
mainfrom
fix/managed-mode-relogin-and-topup-button

Conversation

@navaneethkrishnansuresh
Copy link
Copy Markdown
Member

Summary

  • getConfig retries before defaulting to local mode — closes a race where managed-mode users land on BD Core's own login screen after a relogin (gateway already authed them, but the SPA boots faster
    than its own fastify routes, /api/config returns 502/timeout once, and the old code immediately fell through to mode: "local" → AuthFlow shows the password sign-in screen).
  • "Need more credits?" rendered as an amber pill button — was plain muted text, easy to miss next to the credits balance. Now uses the same bg-bd-amber token family as the existing "Buy Credits"
    submit button so the affordance matches the rest of the topup flow.

Context

Reproduced on the hosted gateway:

  1. Sign in to managed-mode BrainDrive → handoff completes → main app loads ✅
  2. Click logout → gateway stops the user's container, clears cookies, redirects to marketing
  3. Sign in again → gateway restarts the container → handoff redirects to /
  4. SPA boots, calls /api/config before fastify routes are ready → response 502 / network error
  5. getConfig() catches → returns hardcoded { mode: "local", ... }
  6. App.tsx sees mode !== "managed" → renders <AuthFlow> → user sees a BrainDrive login form they shouldn't ever see in managed mode ❌

Fix retries /api/config 5 times with exponential backoff (0, 500, 1000, 2000, 4000 ms — ~7.5s total) before falling through. After the retry budget is exhausted we still default to local because
that's the safe choice for genuine local installs where /api/config legitimately 404s.

The hosted gateway side has a paired change that also probes /api/config before redirecting from the auth-handoff page — defense in depth so any new entry path into BD Core (deep links, bookmarks) gets
the same protection without going through the handoff UI.

navaneethkrishnansuresh and others added 2 commits May 1, 2026 18:38
Defaulting to mode='local' on the first failed /api/config response
caused a confusing login screen for managed-mode users post-relogin:
the user was already authenticated via the gateway, but BD Core booted
faster than its own fastify routes responded, getConfig() failed open
to local, and App.tsx routed to the auth screen.

Retry budget: 5 attempts with exponential backoff (~7.5s total). After
that we still fall through to local — that's correct for genuine local
installs where /api/config legitimately 404s. The gateway side also
probes /api/config before redirecting (defense-in-depth), so reaching
the fallback at all should be rare in managed mode.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Was rendering as plain muted text — easy to miss next to the credits
balance. Match the existing Buy Credits button's golden accent theme
(bg-bd-amber + bg-bd-bg-primary text + amber-hover) so it reads as a
clear affordance to expand the topup form.

Same Tailwind tokens as the actual Buy Credits button (slightly less
prominent — no extra padding, just the inline + glyph) so visual
hierarchy still distinguishes "show form" from "complete purchase".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DJJones66 DJJones66 merged commit 101add6 into main May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants