* Handles aborting the current task/inference without exiting the process. * This is the equivalent of Claude Code's abort - it stops what's currently * happening but keeps the session alive for new prompts.
()
| 427 | * happening but keeps the session alive for new prompts. |
| 428 | */ |
| 429 | async function handleAbort() { |
| 430 | if (abortInProgress) { |
| 431 | await abortInProgress; |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | logger.debug('[Codex] Abort requested - stopping current task'); |
| 436 | abortInProgress = (async () => { |
| 437 | try { |
| 438 | // Resolve any pending permission requests as 'abort' first. |
| 439 | if (permissionHandler) { |
| 440 | permissionHandler.abortAll(); |
| 441 | } |
| 442 | |
| 443 | // Request interruption, then force-restart Codex app-server if |
| 444 | // it doesn't settle quickly (long-running shell commands). |
| 445 | if (client) { |
| 446 | const abortResult = await client.abortTurnWithFallback({ |
| 447 | gracePeriodMs: 3000, |
| 448 | forceRestartOnTimeout: true, |
| 449 | }); |
| 450 | if (abortResult.forcedRestart) { |
| 451 | logger.warn('[Codex] Forced app-server restart after interrupt timeout'); |
| 452 | session.sendSessionEvent({ |
| 453 | type: 'message', |
| 454 | message: abortResult.resumedThread |
| 455 | ? 'Force-stopped active task after interrupt timeout. Codex backend was restarted and the previous thread was resumed.' |
| 456 | : 'Force-stopped active task after interrupt timeout. Codex backend was restarted, but the previous thread could not be resumed.', |
| 457 | }); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | if (reasoningProcessor) { |
| 462 | reasoningProcessor.abort(); |
| 463 | } |
| 464 | logger.debug('[Codex] Abort completed - session remains active'); |
| 465 | } catch (error) { |
| 466 | logger.debug('[Codex] Error during abort:', error); |
| 467 | } finally { |
| 468 | resetCurrentModeDefaults(); |
| 469 | // Wake up message queue wait if idle |
| 470 | abortController.abort(); |
| 471 | abortController = new AbortController(); |
| 472 | } |
| 473 | })(); |
| 474 | |
| 475 | await abortInProgress; |
| 476 | abortInProgress = null; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Handles session termination and process exit. |
no test coverage detected