From 854088c3dedda3058b9368b047418f4e07fb1365 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sun, 15 Feb 2026 03:54:27 -0600 Subject: [PATCH] fix(v2): make CoreBridge auth blocking per ADR - auto_login now fails if V2 CoreBridge auth fails - runtime_bootstrap now fails if V2 CoreBridge auth fails - Add V2AuthFailed and V2NotInitialized runtime error variants - Consistent with login command which was already blocking --- src-tauri/src/commands/auth.rs | 30 ++++++++++++++++++++++++------ src-tauri/src/commands_v2.rs | 9 ++++++--- src-tauri/src/runtime.rs | 6 ++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/commands/auth.rs b/src-tauri/src/commands/auth.rs index e60fc500c..350049804 100644 --- a/src-tauri/src/commands/auth.rs +++ b/src-tauri/src/commands/auth.rs @@ -296,16 +296,34 @@ pub async fn auto_login( } } - // Also authenticate V2 CoreBridge client for the new architecture - // Use try_get() to gracefully handle case where CoreBridge init is still in progress + // V2 CoreBridge authentication - REQUIRED per ADR Runtime Session Contract + // If V2 auth fails, return typed failure and do not report full success if let Some(bridge) = core_bridge.try_get().await { if let Err(e) = bridge.login(&creds.email, &creds.password).await { - log::warn!("[Auth/Auto] V2 CoreBridge login failed (non-blocking): {}", e); - } else { - log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully"); + log::error!("[Auth/Auto] V2 CoreBridge login failed: {}", e); + // V2 auth failed - report failure per ADR + return Ok(LoginResponse { + success: false, + user_name: Some(session.display_name.clone()), + user_id: Some(session.user_id), + subscription: Some(session.subscription_label.clone()), + subscription_valid_until: session.subscription_valid_until.clone(), + error: Some(format!("V2 authentication failed: {}", e)), + error_code: Some("v2_auth_failed".to_string()), + }); } + log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully"); } else { - log::warn!("[Auth/Auto] V2 CoreBridge not yet initialized, skipping V2 auth"); + log::error!("[Auth/Auto] V2 CoreBridge not initialized - cannot complete auth"); + return Ok(LoginResponse { + success: false, + user_name: Some(session.display_name.clone()), + user_id: Some(session.user_id), + subscription: Some(session.subscription_label.clone()), + subscription_valid_until: session.subscription_valid_until.clone(), + error: Some("V2 CoreBridge not initialized".to_string()), + error_code: Some("v2_not_initialized".to_string()), + }); } Ok(LoginResponse { diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index 3e625ff76..915139a82 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -180,7 +180,7 @@ pub async fn runtime_bootstrap( // For now, we just mark the user_id and let the frontend handle it // In a full implementation, we'd activate here directly - // Step 4: Authenticate CoreBridge/V2 + // Step 4: Authenticate CoreBridge/V2 - REQUIRED per ADR if let Some(bridge) = core_bridge.try_get().await { match bridge.login(&creds.email, &creds.password).await { Ok(_) => { @@ -192,11 +192,14 @@ pub async fn runtime_bootstrap( let _ = app.emit("runtime:event", RuntimeEvent::CoreBridgeAuthFailed { error: e.to_string(), }); - // Don't fail bootstrap - V2 auth failure is recoverable + manager.set_bootstrap_in_progress(false).await; + return Err(RuntimeError::V2AuthFailed(e)); } } } else { - log::warn!("[Runtime] CoreBridge not yet initialized, V2 auth deferred"); + log::error!("[Runtime] CoreBridge not initialized - cannot complete bootstrap"); + manager.set_bootstrap_in_progress(false).await; + return Err(RuntimeError::V2NotInitialized); } } Err(e) => { diff --git a/src-tauri/src/runtime.rs b/src-tauri/src/runtime.rs index 22447abaa..13f5dfa7b 100644 --- a/src-tauri/src/runtime.rs +++ b/src-tauri/src/runtime.rs @@ -100,6 +100,10 @@ pub enum RuntimeError { InvalidUserId, /// Bootstrap already in progress BootstrapInProgress, + /// V2 CoreBridge authentication failed + V2AuthFailed(String), + /// V2 CoreBridge not initialized + V2NotInitialized, /// Internal error Internal(String), } @@ -114,6 +118,8 @@ impl std::fmt::Display for RuntimeError { Self::RuntimeDegraded(reason) => write!(f, "Runtime degraded: {:?}", reason), Self::InvalidUserId => write!(f, "Invalid user ID"), Self::BootstrapInProgress => write!(f, "Bootstrap already in progress"), + Self::V2AuthFailed(msg) => write!(f, "V2 authentication failed: {}", msg), + Self::V2NotInitialized => write!(f, "V2 CoreBridge not initialized"), Self::Internal(msg) => write!(f, "Internal error: {}", msg), } }