Skip to content

Conversation

@0xApotheosis
Copy link
Member

@0xApotheosis 0xApotheosis commented Nov 27, 2025

Problem

Users were experiencing a runtime error: [Immer] minified error nr: 3 ("Cannot use a proxy that has been revoked").

Root Cause

In the error handling paths of useSwapExecution and useSendExecution, the code captured the Immer draft state using a shallow spread ({ ...draft }). The completedSteps Set remained as an Immer proxy, which gets revoked after produce() finishes. Accessing this revoked proxy in swapStateToPersistedState() / sendStateToPersistedState() caused the error.

Solution

Use Immer's current() function to safely extract a deep, non-proxy snapshot of the draft state before using it outside the producer callback.

Changes

  • useSwapExecution.ts: Import current from Immer and use it to snapshot error state
  • useSendExecution.ts: Import current from Immer and use it to snapshot error state

Sentry Issue

https://shapeshift-dao.sentry.io/share/issue/33fa363746374aa6bf60e5141b2c3e12/

Summary by CodeRabbit

  • Refactor
    • Improved error state handling in execution hooks to enhance code reliability and maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
shapeshift-agentic Ready Ready Preview Comment Nov 27, 2025 3:27am

@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

📝 Walkthrough

Walkthrough

Two hook files updated to import Immer's current function and replace shallow spread state capture ({ ...draft }) with current(draft) in error handling blocks. No functional logic changes or exported signature modifications.

Changes

Cohort / File(s) Summary
Immer current() refactoring for error state capture
apps/agentic-chat/src/hooks/useSendExecution.ts, apps/agentic-chat/src/hooks/useSwapExecution.ts
Added import of current from immer; replaced shallow spread { ...draft } with current(draft) in catch block error state assignments for improved draft state snapshot handling

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰✨ A rabbit's delight in refactoring's grace,
Where spreads turn to Immer's current embrace,
Two hooks now pristine, their errors well-caught,
With snapshots more proper than shallow spread bought! 🎯

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: fixing an Immer proxy revocation error in swap/send execution hooks, which matches the primary objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-immer-bug

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e4701d5 and 48198ca.

📒 Files selected for processing (2)
  • apps/agentic-chat/src/hooks/useSendExecution.ts (2 hunks)
  • apps/agentic-chat/src/hooks/useSwapExecution.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: main
🔇 Additional comments (4)
apps/agentic-chat/src/hooks/useSendExecution.ts (2)

5-5: LGTM! Correct import for the Immer snapshot fix.

The current import from Immer is the appropriate solution for creating a deep, non-proxy snapshot of draft state in error handling.


235-254: Excellent fix for the Immer proxy revocation error!

Using current(draft) correctly creates a deep, non-proxy snapshot of the draft state, ensuring that completedSteps is a plain Set rather than a revoked proxy when accessed later in sendStateToPersistedState(). This directly addresses the root cause of the "[Immer] minified error nr: 3" runtime error.

apps/agentic-chat/src/hooks/useSwapExecution.ts (2)

6-6: LGTM! Correct import for the Immer snapshot fix.

The current import from Immer is the appropriate solution for creating a deep, non-proxy snapshot of draft state in error handling.


291-310: Excellent fix for the Immer proxy revocation error!

Using current(draft) correctly creates a deep, non-proxy snapshot of the draft state, ensuring that completedSteps is a plain Set rather than a revoked proxy when accessed later in swapStateToPersistedState(). This mirrors the fix in useSendExecution.ts and directly addresses the root cause of the "[Immer] minified error nr: 3" runtime error.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@premiumjibles premiumjibles left a comment

Choose a reason for hiding this comment

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

Looks good

@premiumjibles premiumjibles merged commit 208a061 into main Nov 27, 2025
4 checks passed
@premiumjibles premiumjibles deleted the fix-immer-bug branch November 27, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants