bug: mid-stream retry backoff is not abort-aware and retries content errors after cancellation
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start at packages/core/src/core/geminiChat.ts around lines 668 and 707, then read the abort-aware delay helper in packages/core/src/utils/delay.ts and its use in retry.ts. Verify the retry loop checks cancellation for both error types, aborts its backoff promptly, and produces no post-cancellation retry calls, events, or telemetry.
Written by the indexing model from the issue text.
Description
What happened?
The mid-stream retry loop in GeminiChat has two abort-handling gaps:
- The backoff sleep uses a raw
setTimeoutpromise that is not abort-aware — after the user cancels, the sleep still runs to completion (up toinitialDelayMs * 2^n), and the retrycontinues before the next attempt's entry check finally notices the abort. - For content errors (
isRetryableContentError), the gating condition omits thesignal.abortedcheck entirely, so an already-aborted stream consumes retry slots, emitsRETRYstream events andcoreEvents.emitRetryAttempttelemetry after cancellation, and re-entersmakeApiCallAndProcessStream()(re-running hooks/model selection) before eventually throwing.
Affected code
packages/core/src/core/geminiChat.ts:668:
if (isRetryableContentError || (isRetryable && !signal.aborted)) {
packages/core/src/core/geminiChat.ts:707:
await new Promise((res) => setTimeout(res, delayMs));
continue;
Note the repo already has an abort-aware helper used everywhere else, including retry.ts: delay(ms, signal) (packages/core/src/utils/delay.ts).
How can this be reproduced?
- Start a streaming request; make the first stream chunk fail with a retryable content error (or network error).
- Abort the signal immediately (user presses ESC).
- Observe:
emitRetryAttemptfires post-abort, the raw timer keeps the loop alive for the full backoff delay, and another API call is attempted before unwinding.
What did you expect to happen?
Cancellation should short-circuit immediately: no further retries, no retry telemetry/events after abort, no lingering timer.
Impact
Cancellation lags seconds behind ESC in the failure window; spurious retry telemetry pollutes diagnostics; wasted model calls after the user gave up.
Suggested direction
- Use
await delay(delayMs, signal)instead of the raw promise. - Gate both retry branches on
!signal.aborted(i.e.,!signal.aborted && (isRetryable || isRetryableContentError)).
Found by source audit on current main (commit 5411f113c); platform-independent. No open issue/PR covering this was found (searched: stream retry abort).
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 43
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google-gemini/gemini-cli
-
bug(core): explicit `--model gemini-3-pro-preview` silently rewritten to `gemini-3.1-pro-preview` Openarea/agent effort/medium kind/bug priority/p2 status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
google-gemini/gemini-cli#29417 · 1 comment ·
-
area/enterprise kind/bug priority/p2 status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
google-gemini/gemini-cli#29406 ·
-
area/agent status/need-triage
Difficulty 2/5 Half a day Newbie friendliness 78/100
google-gemini/gemini-cli#29360 ·
-
area/agent kind/bug priority/p2 status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
google-gemini/gemini-cli#29315 ·
-
area/non-interactive effort/small kind/bug priority/p2 status/bot-triaged status/need-information
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
google-gemini/gemini-cli#29308 · 2 comments ·
All issues in google-gemini/gemini-cli
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100