fix(session): clone tool input before passing to EventV2 to prevent Immer freeze#25867
Open
stephanschielke wants to merge 2 commits intoanomalyco:devfrom
Open
fix(session): clone tool input before passing to EventV2 to prevent Immer freeze#25867stephanschielke wants to merge 2 commits intoanomalyco:devfrom
stephanschielke wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This was referenced May 5, 2026
This was referenced May 6, 2026
This was referenced May 6, 2026
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…mmer freeze The v2 event system passes value.input by reference to EventV2.run(), which routes it through SyncEvent -> SessionMessageUpdater -> Immer produce(). Immer freezes the entire produced state tree including value.input, which is the same object reference as the tool args. When a plugin (oh-my-openagent) later tries to mutate args in a tool.execute.before hook, the frozen object throws: TypeError: Attempted to assign to readonly property. Clone the input before passing to EventV2.run so Immer freezes the clone instead of the original args object. Conditions: OPENCODE_EXPERIMENTAL=true + plugin that mutates tool args. Fixes anomalyco#25873
ba76c56 to
00d8629
Compare
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #25873
Type of change
What does this PR do?
Fixes
TypeError: Attempted to assign to readonly propertythat occurs on every tool call whenOPENCODE_EXPERIMENTAL=trueand a plugin mutates tool args intool.execute.beforehooks (e.g. oh-my-openagent).Root cause: In
processor.ts:329, thetool-callevent handler passesvalue.inputby reference toEventV2.run(). This reference is the same object as the tool'sargsinexecute(args, options). The call flows throughSyncEvent.run->SessionMessageUpdater.update()-> Immerproduce(), which callsObject.freeze()on the entire produced state tree, including the original args object. When a plugin hook subsequently tries to mutateargs.command, it throws.Fix: Clone the input before passing to
EventV2.runso Immer freezes the clone instead of the original:Instrumented proof:
How did you verify your code works?
OPENCODE_EXPERIMENTAL=true+ oh-my-openagent pluginAttempted to assign to readonly propertyOPENCODE_EXPERIMENTAL=false: 8/8 succeed (confirms the flag gates the code path)git bisectacross 12,213 commits identified commit a3bc5d35b (PR Refactor v2 session events as schemas #24512) as the first bad commitprocessor.tsfixes the crashEventV2.runas a no-op fixes the crashScreenshots / recordings
N/A (not a UI change)
Checklist