fix(session): clone tool input before passing to EventV2 to prevent Immer freeze#25867
fix(session): clone tool input before passing to EventV2 to prevent Immer freeze#25867stephanschielke wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
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. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
ba76c56 to
00d8629
Compare
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
@thdxr You are working on the new event system, right? As code-yeongyu/oh-my-openagent#3816 rightfully points out plugins should not be allowed to change/modify arguments like tool calls to prevent them from braking out. However, as the current v1 event system (probably unconsciously) established, plugins rely on / make use of receiving mutable arguments as a plugin system "feature". What are your plans for the new v2 event system? Should plugins receive a mutable reference of the arguments, or a copy? How should plugins return a modification of arguments? |
…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
c3777c1 to
7bb175f
Compare
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