@@ -4,6 +4,7 @@ use crate::fuzzy_file_search::run_fuzzy_file_search;
44use crate :: models:: supported_models;
55use crate :: outgoing_message:: OutgoingMessageSender ;
66use crate :: outgoing_message:: OutgoingNotification ;
7+ use codex_app_server_protocol:: AccountUpdatedNotification ;
78use codex_app_server_protocol:: AddConversationListenerParams ;
89use codex_app_server_protocol:: AddConversationSubscriptionResponse ;
910use codex_app_server_protocol:: ApplyPatchApprovalParams ;
@@ -200,8 +201,7 @@ impl CodexMessageProcessor {
200201 request_id,
201202 params : _,
202203 } => {
203- self . send_unimplemented_error ( request_id, "account/logout" )
204- . await ;
204+ self . logout_v2 ( request_id) . await ;
205205 }
206206 ClientRequest :: GetAccount {
207207 request_id,
@@ -250,7 +250,7 @@ impl CodexMessageProcessor {
250250 request_id,
251251 params : _,
252252 } => {
253- self . logout_chatgpt ( request_id) . await ;
253+ self . logout_v1 ( request_id) . await ;
254254 }
255255 ClientRequest :: GetAuthStatus { request_id, params } => {
256256 self . get_auth_status ( request_id, params) . await ;
@@ -494,41 +494,71 @@ impl CodexMessageProcessor {
494494 }
495495 }
496496
497- async fn logout_chatgpt ( & mut self , request_id : RequestId ) {
497+ async fn logout_common ( & mut self ) -> std:: result:: Result < Option < AuthMode > , JSONRPCErrorError > {
498+ // Cancel any active login attempt.
498499 {
499- // Cancel any active login attempt.
500500 let mut guard = self . active_login . lock ( ) . await ;
501501 if let Some ( active) = guard. take ( ) {
502502 active. drop ( ) ;
503503 }
504504 }
505505
506506 if let Err ( err) = self . auth_manager . logout ( ) {
507- let error = JSONRPCErrorError {
507+ return Err ( JSONRPCErrorError {
508508 code : INTERNAL_ERROR_CODE ,
509509 message : format ! ( "logout failed: {err}" ) ,
510510 data : None ,
511- } ;
512- self . outgoing . send_error ( request_id, error) . await ;
513- return ;
511+ } ) ;
514512 }
515513
516- self . outgoing
517- . send_response (
518- request_id,
519- codex_app_server_protocol:: LogoutChatGptResponse { } ,
520- )
521- . await ;
514+ // Reflect the current auth method after logout (likely None).
515+ Ok ( self . auth_manager . auth ( ) . map ( |auth| auth. mode ) )
516+ }
522517
523- // Send auth status change notification reflecting the current auth mode
524- // after logout.
525- let current_auth_method = self . auth_manager . auth ( ) . map ( |auth| auth. mode ) ;
526- let payload = AuthStatusChangeNotification {
527- auth_method : current_auth_method,
528- } ;
529- self . outgoing
530- . send_server_notification ( ServerNotification :: AuthStatusChange ( payload) )
531- . await ;
518+ async fn logout_v1 ( & mut self , request_id : RequestId ) {
519+ match self . logout_common ( ) . await {
520+ Ok ( current_auth_method) => {
521+ self . outgoing
522+ . send_response (
523+ request_id,
524+ codex_app_server_protocol:: LogoutChatGptResponse { } ,
525+ )
526+ . await ;
527+
528+ let payload = AuthStatusChangeNotification {
529+ auth_method : current_auth_method,
530+ } ;
531+ self . outgoing
532+ . send_server_notification ( ServerNotification :: AuthStatusChange ( payload) )
533+ . await ;
534+ }
535+ Err ( error) => {
536+ self . outgoing . send_error ( request_id, error) . await ;
537+ }
538+ }
539+ }
540+
541+ async fn logout_v2 ( & mut self , request_id : RequestId ) {
542+ match self . logout_common ( ) . await {
543+ Ok ( current_auth_method) => {
544+ self . outgoing
545+ . send_response (
546+ request_id,
547+ codex_app_server_protocol:: LogoutAccountResponse { } ,
548+ )
549+ . await ;
550+
551+ let payload_v2 = AccountUpdatedNotification {
552+ auth_method : current_auth_method,
553+ } ;
554+ self . outgoing
555+ . send_server_notification ( ServerNotification :: AccountUpdated ( payload_v2) )
556+ . await ;
557+ }
558+ Err ( error) => {
559+ self . outgoing . send_error ( request_id, error) . await ;
560+ }
561+ }
532562 }
533563
534564 async fn get_auth_status (
0 commit comments