gemini-cli - ✅(Solved) Fix Bug: Telemetry object truncation produces unparseable JSON and risks OOM crashes [1 pull requests, 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#25401Fetched 2026-04-15 06:44:59
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×2added_to_project_v2 ×1cross-referenced ×1parent_issue_added ×1

Fix Action

Fixed

PR fix notes

PR #25344: fix(telemetry): implement bounded structural truncation

Description (problem / solution / changelog)

Summary

Implements a bounded structural truncation strategy for telemetry payloads to prevent JSON parsing errors while maintaining OOM safety.

Details

  • Rewrote truncateForTelemetry to recursively truncate objects by limiting string lengths (via graphemes), array sizes, and traversal depth.
  • Prevents OOM crashes by capping object key lengths to 100 characters.
  • Safely handles getters via direct property access wrapped in error boundaries (try/catch).
  • Respects .toJSON() methods (e.g., on Date objects) to ensure correct serialization.
  • Relies exclusively on structural limits to guarantee the final exported payload remains 100% perfectly valid and parseable JSON.

Related Issues

Fixes #25401

How to Validate

  1. Run the test suite: npm run test:ci -w @google/gemini-cli-core -- src/telemetry/trace.test.ts
  2. Verify all 20 test cases pass, including the new tests for toJSON, getters, long keys, and structural limits.

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
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Changed files

  • packages/core/src/telemetry/trace.test.ts (modified, +61/-9)
  • packages/core/src/telemetry/trace.ts (modified, +94/-19)

Code Example

> /about
# paste output here
RAW_BUFFERClick to expand / collapse

What happened?

As outlined in the parent issue #25146, the current truncateForTelemetry function breaks JSON parseability. It relies on safeJsonStringify and blindly cuts the resulting string at 10,000 characters, appending ...[TRUNCATED]. This results in fundamentally unparseable JSON payloads and can split multi-byte unicode characters (emojis) in half. Furthermore, the unbounded object traversal using Object.entries() risks Out-Of-Memory (OOM) crashes on payloads with massive keys or depth, and using descriptors misses properties defined with getters or .toJSON() methods.

What did you expect to happen?

Telemetry object truncation should guarantee that the exported payload is always perfectly valid JSON. The truncation strategy should be strictly bounded and structural—limiting the maximum depth, maximum array size, string length (via graphemes), and object key length. It should safely access properties via getters using try/catch boundaries and respect .toJSON() methods if present. A global payload character limit should also be enforced as a final safety net to ensure payloads never exceed collector limits.

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
# paste output here
</details>

Login information

No response

Anything else we need to know?

No response

extent analysis

TL;DR

The truncateForTelemetry function needs to be revised to ensure it produces valid JSON payloads by limiting object depth, array size, string length, and object key length, while safely handling getters and respecting .toJSON() methods.

Guidance

  • Review the current truncateForTelemetry function to identify areas where it fails to guarantee valid JSON output, such as unbounded object traversal and blind string cutting.
  • Implement a new truncation strategy that limits the maximum depth, maximum array size, string length (considering graphemes for Unicode support), and object key length to prevent Out-Of-Memory crashes and ensure JSON parseability.
  • Use try/catch blocks to safely access properties via getters and respect .toJSON() methods if present to handle complex objects correctly.
  • Enforce a global payload character limit as a final safety measure to prevent payloads from exceeding collector limits.

Example

No specific code example can be provided without the current implementation details of truncateForTelemetry, but a revised approach might involve recursive functions with depth limits and careful handling of object properties.

Notes

The solution must be tailored to the specific requirements and constraints of the telemetry system, including any character limits imposed by collectors. Testing with various payloads, including those with deep objects, large arrays, and Unicode characters, will be crucial to ensure the revised function meets all necessary criteria.

Recommendation

Apply a workaround by revising the truncateForTelemetry function according to the guidance provided, as there is no clear indication of an available fixed version that addresses these specific issues. This approach ensures that the telemetry data is always valid JSON and prevents potential crashes due to excessive memory usage.

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