-
-
Notifications
You must be signed in to change notification settings - Fork 475
fix(internal): improve safeStringify function to handle circular references more effectively #961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…s more effectively Fixes VoltAgent#960
🦋 Changeset detectedLatest commit: e67421f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughReworks the safe-stringify replacer to use an explicit traversal stack tracking Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/internal/src/utils/safe-stringify.ts`:
- Around line 46-58: The code calls value.toJSON() then immediately uses value
with stack.includes and seen.add, which throws when toJSON returns a primitive;
update the branch in safeStringify so after calling value = value.toJSON() you
re-check that value is non-null and typeof value === "object" before using
stack.includes or seen.add; i.e., guard both the stack.includes(value) and
seen.add(value) calls (and any circular-reference logic) with the same
object-type check to avoid adding primitives to the WeakSet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 1 file
|
Hey @rallu , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/internal/src/utils/safe-stringify.ts">
<violation number="1" location="packages/internal/src/utils/safe-stringify.ts:47">
P2: Missing post-toJSON object guard allows WeakSet on primitives, throwing in safeStringify.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Fixes #960
What is the current behavior?
Very slow processing of safeStringify
What is the new behavior?
On my test processing time reduced from 89000ms to 1ms.
Summary by cubic
Improved safeStringify to correctly handle circular references and run dramatically faster. The replacer now tracks the traversal stack and marks cycles as "[Circular]" while respecting toJSON; observed time drops from ~89s to ~1ms.
Written for commit e67421f. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.