From d56d8039d0190b8b32ece6565126ef8bb5d55a3a Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 12 Jan 2026 15:04:41 -0800 Subject: [PATCH] fix: await token persistence to prevent authentication loop (#524) Co-authored-by: Cameron --- src/auth/setup-ui.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/auth/setup-ui.tsx b/src/auth/setup-ui.tsx index 444f733..79f6e00 100644 --- a/src/auth/setup-ui.tsx +++ b/src/auth/setup-ui.tsx @@ -100,6 +100,10 @@ export function SetupUI({ onComplete }: SetupUIProps) { tokenExpiresAt: now + tokens.expires_in * 1000, }); + // Wait for all pending writes (keychain, disk) to complete before continuing + // This prevents a race condition where main() validation runs before tokens are persisted + await settingsManager.flush(); + setMode("done"); setTimeout(() => onComplete(), 1000); } catch (err) {