Skip to content

fix(core): skip telemetry logging for AbortError exceptions#19477

Merged
yunaseoul merged 1 commit intomainfrom
yunaseol/telemetry
Mar 2, 2026
Merged

fix(core): skip telemetry logging for AbortError exceptions#19477
yunaseoul merged 1 commit intomainfrom
yunaseol/telemetry

Conversation

@yunaseoul
Copy link
Copy Markdown
Contributor

@yunaseoul yunaseoul commented Feb 18, 2026

Summary

Skip logging API errors when a request is aborted by the user or encounters an internal timeout (i.e., AbortError).

Details

When a user cancels a request or leaves a session, the Gemini API client throws an AbortError. Previously, this was logged as a generic API error in the LoggingContentGenerator, which skewed telemetry and error reporting for model usage.

This PR adds a centralized isAbortError utility to packages/core/src/utils/errors.ts and uses it to add explicit checks for AbortError in both streaming and non-streaming request paths in LoggingContentGenerator. This ensures these user-initiated cancellations or timeouts are not tracked as system or API errors.

Related Issues

Fixes #17328

How to Validate

  1. Run the CLI and initiate a model request.
  2. Abort the request (e.g., via Ctrl+C or by triggering an abort signal during a long generation).
  3. Verify that logApiError is NOT triggered in the telemetry/logs.
  4. Review and run the new unit tests in packages/core/src/core/loggingContentGenerator.test.ts and packages/core/src/utils/errors.test.ts.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt

@yunaseoul yunaseoul requested a review from a team as a code owner February 18, 2026 22:02
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @yunaseoul, 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 refines the error handling within the API client to differentiate between genuine API errors and user-initiated cancellations. By specifically identifying and ignoring AbortErrors, the system's error logging becomes more accurate, providing a clearer picture of actual service issues versus expected user behavior.

Highlights

  • Error Logging: API errors resulting from user-aborted requests (i.e., AbortError) are now explicitly skipped from logging.
  • Telemetry Accuracy: This change prevents user-initiated cancellations from skewing telemetry and error reporting for model usage.
  • Affected Paths: The AbortError handling has been implemented in both streaming and non-streaming request paths within the LoggingContentGenerator.
  • New Unit Tests: Comprehensive unit tests have been added to verify that AbortErrors are correctly handled and not logged for both generateContent and generateContentStream methods.
Changelog
  • packages/core/src/core/loggingContentGenerator.test.ts
    • Added a new test case to verify that logApiError is not called when generateContent rejects with an AbortError.
    • Added a test case to ensure logApiError is not called when generateContentStream rejects with an AbortError during the connection phase.
    • Added a test case to confirm logApiError is not called when generateContentStream throws an AbortError during stream iteration.
  • packages/core/src/core/loggingContentGenerator.ts
    • Introduced a check for AbortError in the generateContent method's catch block to prevent logging user cancellations.
    • Added a similar AbortError check within the generateContentStream method's catch block.
    • Implemented an AbortError check in the _callApi method's catch block to ensure consistent handling of aborted requests.
Activity
  • The author added new unit tests to cover the AbortError handling scenarios.
  • The author validated the changes on MacOS using npm run.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly prevents logging AbortError when a user cancels a request. The changes in LoggingContentGenerator effectively check for this specific error in both streaming and non-streaming paths and prevent it from being logged, which will improve the accuracy of error telemetry. The accompanying tests are thorough, covering all the modified code paths. I have one suggestion to improve maintainability by refactoring the duplicated AbortError check into a single utility function.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 18, 2026

Size Change: +205 B (0%)

Total Size: 25.8 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.3 MB +205 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added area/enterprise Issues related to Telemetry, Policy, Quota / Licensing 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 18, 2026
Copy link
Copy Markdown
Contributor

@sehoon38 sehoon38 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yunaseoul yunaseoul force-pushed the yunaseol/telemetry branch 2 times, most recently from b5dce07 to 377b7d2 Compare March 2, 2026 22:41
@yunaseoul yunaseoul changed the title fix(core): skip API error logging for user-aborted requests fix(core): skip telemetry logging for AbortError exceptions Mar 2, 2026
@yunaseoul yunaseoul force-pushed the yunaseol/telemetry branch from 377b7d2 to 1c0fa35 Compare March 2, 2026 22:52
Avoids logging AbortError instances as API errors during content generation and streaming, as these typically represent user cancellations or expected internal timeouts rather than actual API failures. Added isAbortError utility to support this check.
@yunaseoul yunaseoul force-pushed the yunaseol/telemetry branch from 1c0fa35 to 01b3943 Compare March 2, 2026 22:53
@yunaseoul yunaseoul enabled auto-merge March 2, 2026 23:00
@yunaseoul yunaseoul added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit 69e15a5 Mar 2, 2026
27 checks passed
@yunaseoul yunaseoul deleted the yunaseol/telemetry branch March 2, 2026 23:28
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate and refine logApiError telemetry to exclude AbortErrors

2 participants