fix: ESC key not interrupting during Working... state

Three related fixes:

1. google-gemini-cli: Handle abort signal in stream reading loop
   - Add abort event listener to cancel reader immediately when signal fires
   - Fix AbortError detection in retry catch block (fetch throws AbortError,
     not our custom message)
   - Swallow reader.cancel() rejection to avoid unhandled promise

2. agent-session: Fix retry attempt counter showing 0 on cancel
   - abortRetry() was resetting _retryAttempt before the catch block could
     read it for the error message

3. interactive-mode: Restore main escape handler on agent_start
   - When auto-retry starts, onEscape is replaced with retry-specific handler
   - auto_retry_end (which restores it) fires on turn_end, after streaming begins
   - Now restore immediately on agent_start if retry handler is still active

Amended: suppress reader.cancel() rejection on abort.
This commit is contained in:
Thomas Mustier 2026-01-08 09:35:53 +00:00
parent cfa63c255d
commit a65da1c14b
3 changed files with 161 additions and 133 deletions

View file

@ -1481,6 +1481,16 @@ export class InteractiveMode {
switch (event.type) {
case "agent_start":
// Restore main escape handler if retry handler is still active
// (retry success event fires later, but we need main handler now)
if (this.retryEscapeHandler) {
this.defaultEditor.onEscape = this.retryEscapeHandler;
this.retryEscapeHandler = undefined;
}
if (this.retryLoader) {
this.retryLoader.stop();
this.retryLoader = undefined;
}
if (this.loadingAnimation) {
this.loadingAnimation.stop();
}