diff options
Diffstat (limited to 'makima/src/daemon/task/manager.rs')
| -rw-r--r-- | makima/src/daemon/task/manager.rs | 95 |
1 files changed, 71 insertions, 24 deletions
diff --git a/makima/src/daemon/task/manager.rs b/makima/src/daemon/task/manager.rs index b382507..addcd71 100644 --- a/makima/src/daemon/task/manager.rs +++ b/makima/src/daemon/task/manager.rs @@ -1886,6 +1886,66 @@ impl TaskManager { tracing::info!("Daemon restart: exiting process with code 42 (restart requested)"); std::process::exit(42); } + DaemonCommand::TriggerReauth { request_id } => { + tracing::info!(request_id = %request_id, "Received reauth trigger command from server"); + let claude_command = self.process_manager.claude_command().to_string(); + let ws_tx = self.ws_tx.clone(); + + // Spawn in a task so it doesn't block command handling + tokio::spawn(async move { + match get_oauth_login_url(&claude_command).await { + Some(login_url) => { + tracing::info!(request_id = %request_id, login_url = %login_url, "Got OAuth login URL for reauth"); + let msg = DaemonMessage::ReauthStatus { + request_id, + status: "url_ready".to_string(), + login_url: Some(login_url), + error: None, + }; + let _ = ws_tx.send(msg).await; + } + None => { + tracing::error!(request_id = %request_id, "Failed to get OAuth login URL for reauth"); + let msg = DaemonMessage::ReauthStatus { + request_id, + status: "failed".to_string(), + login_url: None, + error: Some("Failed to get OAuth login URL from setup-token".to_string()), + }; + let _ = ws_tx.send(msg).await; + } + } + }); + } + DaemonCommand::SubmitAuthCode { request_id, code } => { + tracing::info!(request_id = %request_id, "Received auth code submission from server"); + let ws_tx = self.ws_tx.clone(); + + if send_auth_code(&code) { + tracing::info!(request_id = %request_id, "Auth code forwarded to setup-token for reauth"); + // Wait a short time then report completion + // (the setup-token process takes a moment to complete) + tokio::spawn(async move { + tokio::time::sleep(std::time::Duration::from_secs(3)).await; + let msg = DaemonMessage::ReauthStatus { + request_id, + status: "completed".to_string(), + login_url: None, + error: None, + }; + let _ = ws_tx.send(msg).await; + }); + } else { + tracing::warn!(request_id = %request_id, "No pending auth flow to receive code for reauth"); + let msg = DaemonMessage::ReauthStatus { + request_id, + status: "failed".to_string(), + login_url: None, + error: Some("No pending auth flow to receive the code. Try triggering reauth again.".to_string()), + }; + let _ = self.ws_tx.send(msg).await; + } + } DaemonCommand::ApplyPatchToWorktree { target_task_id, source_task_id, @@ -5260,32 +5320,19 @@ impl TaskManagerInner { break; } - // Detect OAuth token expiration and trigger remote login flow + // Detect OAuth token expiration - log warning and let the task fail normally. + // Users can reauthorize via the Daemons page instead. if !auth_error_handled && is_oauth_auth_error(&content_for_auth_check, json_type_for_auth_check.as_deref(), is_stdout_for_auth_check) { auth_error_handled = true; - tracing::warn!(task_id = %task_id, "OAuth authentication error detected, initiating remote login flow"); - - // Spawn claude setup-token to get login URL - if let Some(login_url) = get_oauth_login_url(&claude_command).await { - tracing::info!(task_id = %task_id, login_url = %login_url, "Got OAuth login URL"); - let auth_msg = DaemonMessage::AuthenticationRequired { - task_id: Some(task_id), - login_url, - hostname: daemon_hostname.clone(), - }; - if ws_tx.send(auth_msg).await.is_err() { - tracing::warn!(task_id = %task_id, "Failed to send auth required message"); - } - } else { - tracing::error!(task_id = %task_id, "Failed to get OAuth login URL from setup-token"); - let fallback_msg = DaemonMessage::task_output( - task_id, - format!("Authentication required on daemon{}. Please run 'claude /login' on the daemon machine.\n", - daemon_hostname.as_ref().map(|h| format!(" ({})", h)).unwrap_or_default()), - false, - ); - let _ = ws_tx.send(fallback_msg).await; - } + tracing::warn!(task_id = %task_id, "OAuth authentication error detected - task will fail. Reauthorize via Daemons page."); + + let error_msg = DaemonMessage::task_output( + task_id, + format!("⚠ Authentication expired on daemon{}. Go to Daemons page to reauthorize, then retry this task.\n", + daemon_hostname.as_ref().map(|h| format!(" ({})", h)).unwrap_or_default()), + false, + ); + let _ = ws_tx.send(error_msg).await; } } None => { |
