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
This commit is contained in:
vicrodh committed 2026-02-15 03:54:27 -06:00
1 parent 8a844612ff
commit 854088c3de
3 files changed
+36 -9

No files matched your search

+24 -6
View File
@@ -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 {
+6 -3
View File
@@ -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) => {
+6
View File
@@ -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),
}
}