fix(core): preserve shared references in JSON serialization - #29407
Oscar-Williams wants to merge 1 commit into
Conversation
|
📊 PR Size: size/M
|
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 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
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 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 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
|
There was a problem hiding this comment.
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.
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
WeakSetwith active ancestor-path tracking.[Circular]for genuine ancestor cycles.endTime/duration, and metricendTime/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-corenpm run lint -w @google/gemini-cli-corenpx prettier --check packages/core/src/telemetry/file-exporters.test.ts packages/core/src/utils/safeJsonStringify.test.ts packages/core/src/utils/safeJsonStringify.tsgit diff --checkThe repository preflight reached dependency installation, formatting, build, ESLint, actionlint, shellcheck, and yamllint; the Windows run then stopped because
grepis 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
AI assistance was used for repository research, implementation, validation, and PR drafting; the patch was checked against the repository requirements.