Skip to content

fix(rivetkit): bind methods through createWriteThroughProxy#4987

Open
abcxff wants to merge 1 commit into05-06-fix_log_error_on_failed_inspector_requestsfrom
05-06-fix_rivetkit_bind_methods_through_createwritethroughproxy
Open

fix(rivetkit): bind methods through createWriteThroughProxy#4987
abcxff wants to merge 1 commit into05-06-fix_log_error_on_failed_inspector_requestsfrom
05-06-fix_rivetkit_bind_methods_through_createwritethroughproxy

Conversation

@abcxff
Copy link
Copy Markdown
Contributor

@abcxff abcxff commented May 6, 2026

Fixes an error that occurs when inspector state attempts to serialize non trivial values (ie Date).

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 6, 2026

🚅 Deployed to the rivet-pr-4987 environment in rivet-frontend

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web May 7, 2026 at 8:20 pm
website 😴 Sleeping (View Logs) Web May 7, 2026 at 2:22 am
frontend-inspector ❌ Build Failed (View Logs) Web May 6, 2026 at 10:05 pm
frontend-cloud ❌ Build Failed (View Logs) Web May 6, 2026 at 10:04 pm
ladle ❌ Build Failed (View Logs) Web May 6, 2026 at 8:30 pm
mcp-hub ✅ Success (View Logs) Web May 6, 2026 at 8:30 pm

Copy link
Copy Markdown
Contributor Author

abcxff commented May 6, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

Code Review - fix(rivetkit): bind methods through createWriteThroughProxy

Overview: This PR adds method binding in createWriteThroughProxy get trap so that functions retrieved from a proxied state object are called with the correct this (the raw inner target, not the proxy wrapper).

What the Fix Solves: Without the fix, calling prototype methods on built-in types stored in actor state (Map, Set, Date, etc.) throws a TypeError because those built-ins use internal slots that proxies cannot satisfy. Binding to innerTarget makes those calls work.

Critical Issue - Mutation Tracking Is Broken for Array Methods: The fix is too broad. By binding every function to innerTarget, mutations performed via method calls no longer flow through the proxy set trap, so commit is never called. Before this change, array.push() called with this=proxy caused the proxy set trap to fire (since push sets this[length]), so mutations were tracked. After the change, the raw array is mutated silently. Any user relying on in-place array mutations (push, pop, splice, sort, reverse, etc.) will silently lose state persistence. This is the core regression concern that needs to be resolved before merging.

Possible Better Approach: Wrap the method call so mutations still reach the proxy, with a fallback to the raw target when built-in slots reject the proxy this. Alternatively, explicitly detect known incompatible built-ins (Map, Set, Date, RegExp, etc.) and only bind in those cases, preserving proxy-mediated mutation tracking for plain objects and arrays.

Additional Concerns: (1) No tests - the change affects both array mutation tracking and built-in-type method calls. Tests should cover Map/Set calls through the proxy and Array push/splice triggering commit. (2) PR is a draft with description template unfilled and checklist unchecked. (3) Missing root cause description - knowing whether the target was Map/Set/Date would help scope the fix correctly.

Summary: The intent is correct - bound receivers are required for certain built-in types - but the implementation is too broad and silently breaks write-through mutation tracking for array methods. Please add test coverage and reconsider the binding strategy before merging.

@abcxff abcxff force-pushed the 05-06-fix_log_error_on_failed_inspector_requests branch from b150344 to fc4756e Compare May 6, 2026 22:03
@abcxff abcxff force-pushed the 05-06-fix_rivetkit_bind_methods_through_createwritethroughproxy branch from af6e0e4 to 3be897d Compare May 6, 2026 22:03
@abcxff abcxff force-pushed the 05-06-fix_rivetkit_bind_methods_through_createwritethroughproxy branch from 3be897d to c39972c Compare May 7, 2026 20:16
@abcxff abcxff force-pushed the 05-06-fix_log_error_on_failed_inspector_requests branch from fc4756e to 5ec0839 Compare May 7, 2026 20:16
@abcxff abcxff marked this pull request as ready for review May 7, 2026 20:19
@abcxff abcxff requested a review from NathanFlurry May 7, 2026 20:23
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.

1 participant