@@ -242,10 +242,7 @@ export async function runCodex(opts: {
242242 }
243243
244244 abortController . abort ( ) ;
245- messageQueue . reset ( ) ;
246- permissionHandler . reset ( ) ;
247245 reasoningProcessor . abort ( ) ;
248- diffProcessor . reset ( ) ;
249246 logger . debug ( '[Codex] Abort completed - session remains active' ) ;
250247 } catch ( error ) {
251248 logger . debug ( '[Codex] Error during abort:' , error ) ;
@@ -282,6 +279,13 @@ export async function runCodex(opts: {
282279 await session . close ( ) ;
283280 }
284281
282+ // Force close Codex transport (best-effort) so we don't leave stray processes
283+ try {
284+ await client . forceCloseSession ( ) ;
285+ } catch ( e ) {
286+ logger . debug ( '[Codex] Error while force closing Codex session during termination' , e ) ;
287+ }
288+
285289 // Stop caffeinate
286290 stopCaffeinate ( ) ;
287291
@@ -691,11 +695,9 @@ export async function runCodex(opts: {
691695 if ( isAbortError ) {
692696 messageBuffer . addMessage ( 'Aborted by user' , 'status' ) ;
693697 session . sendSessionEvent ( { type : 'message' , message : 'Aborted by user' } ) ;
694- // Session was already stored in handleAbort(), no need to store again
695- // Mark session as not created to force proper resume on next message
696- wasCreated = false ;
697- currentModeHash = null ;
698- logger . debug ( '[Codex] Marked session as not created after abort for proper resume' ) ;
698+ // Abort cancels the current task/inference but keeps the Codex session alive.
699+ // Do not clear session state here; the next user message should continue on the
700+ // existing session if possible.
699701 } else {
700702 messageBuffer . addMessage ( 'Process exited unexpectedly' , 'status' ) ;
701703 session . sendSessionEvent ( { type : 'message' , message : 'Process exited unexpectedly' } ) ;
@@ -738,9 +740,9 @@ export async function runCodex(opts: {
738740 } catch ( e ) {
739741 logger . debug ( '[codex]: Error while closing session' , e ) ;
740742 }
741- logger . debug ( '[codex]: client.disconnect begin' ) ;
742- await client . disconnect ( ) ;
743- logger . debug ( '[codex]: client.disconnect done' ) ;
743+ logger . debug ( '[codex]: client.forceCloseSession begin' ) ;
744+ await client . forceCloseSession ( ) ;
745+ logger . debug ( '[codex]: client.forceCloseSession done' ) ;
744746 // Stop Happy MCP server
745747 logger . debug ( '[codex]: happyServer.stop' ) ;
746748 happyServer . stop ( ) ;
0 commit comments