gemini-cli - ✅(Solved) Fix Cross-boundary cancellation errors surface as unhandled errors [2 pull requests, 2 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25457Fetched 2026-04-16 07:06:13
View on GitHub
Comments
2
Participants
1
Timeline
9
Reactions
0
Author
Participants
Timeline (top)
commented ×2cross-referenced ×2labeled ×2closed ×1

Error Message

When a request is aborted, the original AbortError type is lost when errors cross system boundaries (e.g. subagent / local-invocation / tool executors). Downstream code that checks error instanceof AbortError or similar fails, so cancellations surface as unhandled errors in the UI.

  • User cancels a tool run → sees an error toast instead of a clean "cancelled" state Introduce isCancellationError(err) that detects cancellation regardless of how the error was serialized/rethrown (checks name, message, cause chain). Update browserAgentInvocation, local-invocation, and tool executors to use it.

Fix Action

Fixed

PR fix notes

PR #23235: fix(core): robust cross-boundary cancellation detection

Description (problem / solution / changelog)

Introduces isCancellationError to reliably detect aborted requests even when the original AbortError type is lost across system boundaries. It updates browserAgentInvocation, local-invocation, and tool executors to gracefully handle cancellations rather than treating them as unhandled errors.

Changed files

  • packages/core/src/agents/browser/browserAgentInvocation.test.ts (modified, +23/-0)
  • packages/core/src/agents/browser/browserAgentInvocation.ts (modified, +7/-6)
  • packages/core/src/agents/local-invocation.test.ts (modified, +14/-0)
  • packages/core/src/agents/local-invocation.ts (modified, +2/-4)
  • packages/core/src/core/client.test.ts (modified, +15/-0)
  • packages/core/src/core/client.ts (modified, +2/-2)
  • packages/core/src/core/loggingContentGenerator.ts (modified, +2/-2)
  • packages/core/src/scheduler/confirmation.ts (modified, +2/-2)
  • packages/core/src/scheduler/scheduler.ts (modified, +2/-1)
  • packages/core/src/scheduler/tool-executor.test.ts (modified, +41/-1)
  • packages/core/src/scheduler/tool-executor.ts (modified, +3/-8)
  • packages/core/src/tools/web-search.ts (modified, +2/-2)
  • packages/core/src/utils/errors.test.ts (modified, +30/-0)
  • packages/core/src/utils/errors.ts (modified, +28/-0)

PR #25462: fix(core): robust cross-boundary cancellation detection

Description (problem / solution / changelog)

Fixes #20106 Related: #25457

Summary

Introduces isCancellationError() to reliably detect aborted requests even when the original AbortError type is lost as errors cross system boundaries. Directly addresses #20106 (Fatal CLI Crash on Loop Detection via Unhandled AbortError) — the @google/genai async iterator detaches error listeners during yield suspensions, so synchronous controller.abort() errors arrive at higher layers stripped of their AbortError typing. Existing error.name === 'AbortError' checks miss them, and the crash surfaces as unhandled.

Also updates browserAgentInvocation, local-invocation, and tool executors to treat cancellations as a clean terminal state instead of unhandled errors.

Changes

  • New isCancellationError(error) helper in errors.ts (checks name, CanceledError, and common cancellation message patterns so typing loss across async boundaries doesn't cause false negatives)
  • Replace ad-hoc error.name === 'AbortError' || message.includes('Aborted') checks at boundary sites with the helper
  • Mark running activity items as cancelled (not error) on cancel

Test plan

  • New unit tests for isCancellationError
  • Updated local/browser agent invocation tests
  • Manual: trigger loop detection on repetitive LLM output and confirm the CLI no longer crashes (repro from #20106)
  • Manual: cancel a long-running tool call and confirm UI shows cancelled state, not error toast

Replaces #23235 (auto-closed per contribution policy).

Changed files

  • packages/core/src/agents/browser/browserAgentInvocation.test.ts (modified, +23/-0)
  • packages/core/src/agents/browser/browserAgentInvocation.ts (modified, +7/-6)
  • packages/core/src/agents/local-invocation.test.ts (modified, +14/-0)
  • packages/core/src/agents/local-invocation.ts (modified, +2/-3)
  • packages/core/src/core/client.test.ts (modified, +15/-0)
  • packages/core/src/core/client.ts (modified, +2/-2)
  • packages/core/src/core/loggingContentGenerator.ts (modified, +2/-2)
  • packages/core/src/scheduler/confirmation.ts (modified, +2/-2)
  • packages/core/src/scheduler/scheduler.ts (modified, +2/-1)
  • packages/core/src/scheduler/tool-executor.test.ts (modified, +41/-1)
  • packages/core/src/scheduler/tool-executor.ts (modified, +3/-8)
  • packages/core/src/tools/web-search.ts (modified, +2/-2)
  • packages/core/src/utils/errors.test.ts (modified, +30/-0)
  • packages/core/src/utils/errors.ts (modified, +28/-0)
RAW_BUFFERClick to expand / collapse

Bug

When a request is aborted, the original AbortError type is lost when errors cross system boundaries (e.g. subagent / local-invocation / tool executors). Downstream code that checks error instanceof AbortError or similar fails, so cancellations surface as unhandled errors in the UI.

Impact

  • User cancels a tool run → sees an error toast instead of a clean "cancelled" state
  • Logs get noisy with false-positive errors

Proposal

Introduce isCancellationError(err) that detects cancellation regardless of how the error was serialized/rethrown (checks name, message, cause chain). Update browserAgentInvocation, local-invocation, and tool executors to use it.

Related

Fix proposed in #23235 (closed per contribution policy).

extent analysis

TL;DR

Introduce a new function isCancellationError(err) to detect cancellation errors across system boundaries.

Guidance

  • Update error handling in browserAgentInvocation, local-invocation, and tool executors to use the proposed isCancellationError(err) function.
  • Verify that the new function correctly identifies cancellation errors by checking its behavior with different error types and serialization methods.
  • Consider adding tests to ensure the isCancellationError(err) function works as expected in various scenarios.
  • Review the closed proposal in #23235 for additional context and potential implementation details.

Example

function isCancellationError(err) {
  // Check error name, message, and cause chain to determine if it's a cancellation error
  return err.name === 'AbortError' || err.message.includes('cancelled') || (err.cause && isCancellationError(err.cause));
}

Notes

The introduction of isCancellationError(err) may require adjustments to error handling logic in various parts of the system to ensure correct behavior.

Recommendation

Apply workaround by implementing the proposed isCancellationError(err) function, as it provides a more robust way to detect cancellation errors across system boundaries.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - ✅(Solved) Fix Cross-boundary cancellation errors surface as unhandled errors [2 pull requests, 2 comments, 1 participants]