fix(cli): clear stale retry/loading state after cancellation (#21096)#21960
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a set of issues where the CLI's UI could display incorrect or stale loading and retry information after a user cancelled an ongoing operation. The changes ensure that the system's state, particularly related to retries and loading indicators, is accurately reflected and cleared upon cancellation, preventing confusing visual cues and improving the overall user experience during interactive sessions. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a race condition where stale retry/loading UI could be displayed after a user cancels a request. The fix is implemented robustly at multiple levels: the core retry logic now prevents onRetry callbacks from firing on aborted operations, and the UI has been hardened to ignore retry events unless in an active Responding state. Additionally, the retry status is now explicitly cleared upon cancellation. The changes are well-tested with specific regression tests for the race conditions. The implementation is clean and follows best practices. I have no further feedback.
Note: Security Review did not run due to the size of the PR.
|
@jacob314 This should fix the issue. |
|
/assign |
|
Thank you for fixing this UI loading-state race condition! The fix successfully clears stale retry statuses during cancellations and accurately guards the I have a couple of suggestions to clean up the implementation and reduce boilerplate: 1. Simplify
|
@devr0306 Thanks again for the review.
I also reran the targeted tests for the retry/cancel/loading paths after making those changes. One scope question before I do anything further: the issue thread for #21096 has grown pretty broad, and a number of comments now seem to mix the original cancel-related stale UI bug with longer-running backend/capacity/429-related "This is taking a bit longer..." cases. Given the current scope of this PR, would you prefer that I keep it focused on the UI loading-state race condition during cancellation, or should I expand/update this PR to try to cover the broader "taking a bit longer" reports from the issue thread as well? If the latter would be better handled as a separate follow-up issue/PR, I’m happy to keep this one narrowly scoped and work with you to get this merged first, and then I can immediately move on to investigating any broader follow-up issues in a separate PR if needed. Waiting for your call, and thanks for your appreciation, always happy to contribute. EDIT: Rebased this branch onto the latest upstream While doing that, I also aligned a few related tests with the current upstream test helper behavior so the rebased branch stays green after conflict resolution. Re-ran the targeted validation on the rebased branch:
All of the above passed on the rebased branch. |
9eed249 to
ee1ae79
Compare
|
Addressed both follow-up review points in the latest update. Changes:
Re-ran the targeted validation on this updated branch:
All of the above passed on the updated branch. Waiting for your call, and happy to make any adjustments if needed. |
Thank you for the approval. I see that the Lint is failing, so I'm currently working on committing one final change to address the failing lint check, and once that is pushed this should turn green. EDIT: |
|
Thanks again for the approval, and sorry for the extra churn here. I spent the last 4 hours digging into the remaining CI failures locally before pushing this follow-up. The issue turned out not to be the core cancel/retry fix itself, but the test/formatting side around it:
What I updated in the latest commit:
I did not change the core product logic of the PR in this follow-up; this was focused on getting the PR-specific CI failures under control. Before pushing, I reran:
I’m much more confident in this update, and I believe it should pass the checks this time. When you get a chance, could you please re-approve the workflows so CI can run again on the latest commit? Thank you. |
|
Thanks again for the review. At this point, I’ve fixed the PR-specific CI/lint/test issues, and the regular checks are now passing. The only remaining failure is From the logs, I’m not fully convinced that this remaining E2E failure is caused by the actual logic in this PR. From my understanding, what I found is that the remaining failures are all in the same interactive file-system test:
What makes me unsure this is caused by this PR is that the non-interactive sibling file-system test later completes the same read-then-write flow successfully in those runs, including updating Since this PR is scoped to the cancel/retry/loading-state race condition, and the remaining failure appears isolated to the interactive E2E path, I wanted to ask for guidance before making more changes here. Im not sure, if you want me to go ahead and try to patch this E2E issue as part of this PR, or treat it as separate? Happy to keep digging either way. |
|
Thanks for the update! Just needed to sync the branch with main and all the checks pass now. Look forward to more contributions from you in the future! |
Sweet, glad that fixed it! Thanks for the patient code review and merge, really appreciate it. |
…gemini#21096) (google-gemini#21960) Co-authored-by: Aashir Javed <Aaxhirrr@users.noreply.github.com> Co-authored-by: Dev Randalpura <devrandalpura@google.com>
…gemini#21096) (google-gemini#21960) Co-authored-by: Aashir Javed <Aaxhirrr@users.noreply.github.com> Co-authored-by: Dev Randalpura <devrandalpura@google.com>
…gemini#21096) (google-gemini#21960) Co-authored-by: Aashir Javed <Aaxhirrr@users.noreply.github.com> Co-authored-by: Dev Randalpura <devrandalpura@google.com>
Summary
Fixes the stuck loading-state bug after cancel (
Esc) for issue #21096.The root cause was a race: canceling a request could still allow a late retry event to update UI state, so the app kept showing
"This is taking a bit longer, we're still on it."even when the turn was already canceled/idle.Details
onRetry(...)callback inretryWithBackoff.AbortErroris thrown immediately.useGeminiStream,RetryAttemptevents are ignored when the turn is canceled or not actively responding.retryStatusis cleared immediately duringcancelOngoingRequest(instead of only waiting forisRespondingeffects).StreamingState.Responding.(esc to cancel, ...)timer/help text now renders only inStreamingState.Responding.This keeps cancellation behavior clean and prevents stale retry/loading text from leaking into the next turn.
Regression coverage
Related Issues
How to Validate
Repro manually:
Start a prompt on a model likely to retry/back off.
Wait until loading/retry text appears.
Press
Escto cancel.Send another prompt.
Confirm old retry/loading text is gone and UI is reset.
Run tests:
npm run test --workspace @google/gemini-cli-core -- src/utils/retry.test.tsnpm run test --workspace @google/gemini-cli -- src/ui/hooks/useGeminiStream.test.tsx -t "Retry Handling"npm run test --workspace @google/gemini-cli -- src/ui/hooks/useLoadingIndicator.test.tsx src/ui/components/LoadingIndicator.test.tsxSpecific validation update (macOS smoke test, March 10, 2026):
Ran 5 iterations of the repro flow:
Result: PASS (5/5). No stuck
"This is taking a bit longer..."line after cancel; follow-up prompts executed normally without restart.Pre-Merge Checklist