Skip to content

fix(core): preserve shared references in JSON serialization - #29407

Open
Oscar-Williams wants to merge 1 commit into
google-gemini:mainfrom
Oscar-Williams:fix/safe-json-shared-references
Open

Oscar-Williams wants to merge 1 commit into
google-gemini:mainfrom
Oscar-Williams:fix/safe-json-shared-references

Conversation

@Oscar-Williams

Copy link
Copy Markdown

Summary

Fixes #29406 by treating only objects on the active JSON recursion path as circular. Repeated OpenTelemetry arrays in file exports now retain their values instead of becoming [Circular].

Details

  • Replaced the process-wide WeakSet with active ancestor-path tracking.
  • Kept [Circular] for genuine ancestor cycles.
  • Added regressions for generic shared references, span endTime/duration, and metric endTime/histogram boundaries.

Related Issues

Fixes #29406

How to Validate

  • npm test -w @google/gemini-cli-core -- src/utils/safeJsonStringify.test.ts src/telemetry/file-exporters.test.ts (20 passed)
  • npm run typecheck -w @google/gemini-cli-core
  • npm run lint -w @google/gemini-cli-core
  • npx prettier --check packages/core/src/telemetry/file-exporters.test.ts packages/core/src/utils/safeJsonStringify.test.ts packages/core/src/utils/safeJsonStringify.ts
  • git diff --check

The repository preflight reached dependency installation, formatting, build, ESLint, actionlint, shellcheck, and yamllint; the Windows run then stopped because grep is unavailable. The full test suite reached all workspaces and passed the changed tests, with unrelated Windows trust, symlink, PTY, and sandbox integration failures.

Pre-Merge Checklist

  • Added/updated tests
  • No breaking changes
  • Targeted tests, typecheck, lint, formatting, and diff checks pass

AI assistance was used for repository research, implementation, validation, and PR drafting; the patch was checked against the repository requirements.

@Oscar-Williams
Oscar-Williams requested a review from a team as a code owner September 19, 2026 07:42
@github-actions github-actions Bot added the size/m A medium sized PR label Sep 19, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 118
  • Additions: +109
  • Deletions: -9
  • Files changed: 3

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 improves the JSON serialization utility by refining how circular references are detected. By shifting from a process-wide tracking approach to one that only considers the current recursion path, the implementation now correctly handles shared object references that are not part of a recursive cycle. This change ensures that telemetry data, such as OpenTelemetry spans and metrics, maintains its integrity during serialization rather than being prematurely truncated.

Highlights

  • Circular Reference Logic: Replaced the global WeakSet-based circular reference detection with an active ancestor-path tracking mechanism to ensure only true recursive cycles are marked as [Circular].
  • Data Integrity: Fixed an issue where shared references in OpenTelemetry spans and metrics were incorrectly serialized as [Circular], ensuring values are preserved during JSON export.
  • Regression Testing: Added comprehensive test cases for shared span values, metric end times, histogram boundaries, and generic shared object references.
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 the 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 counterproductive. 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.

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.

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

Copy link
Copy Markdown
Contributor

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 updates the safeJsonStringify utility to correctly handle repeated, non-circular object references. Instead of using a WeakSet which flags any previously seen object as circular, the implementation now tracks the active ancestor path using an array and pops elements as the traversal backtracks. This ensures that shared references (such as shared end times or histogram boundaries in telemetry spans and metrics) are preserved in the serialized JSON output rather than being incorrectly replaced with [Circular]. Corresponding unit tests have been added to verify this behavior for both the utility and the file exporters. I have no feedback to provide as the changes are well-implemented and fully tested.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/enterprise Issues related to Telemetry, Policy, Quota / Licensing labels Sep 19, 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 priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry outfile writes "[Circular]" for shared metric endTime and histogram boundaries

1 participant