-
Notifications
You must be signed in to change notification settings - Fork 309
Runner.runAsync applies stateDelta too late, causing missing(outdated) context in onUserMessageCallback #1099
Description
Description
In the current implementation of Runner.java, the stateDelta provided to runAsync is merged into the session only after the pluginManager.onUserMessageCallback has been executed.
Because the stateDelta is merged into the session only after the pluginManager.onUserMessageCallback has been executed, the data available to plugins is inconsistent with the current execution call. Furthermore, because the session is a copy, any attempt to manually update the state from the outside before the callback is ineffective, as the InvocationContext is built from a stale snapshot.
Steps to Reproduce
- Call
runner.runAsync(userId, sessionId, message, config, stateDelta). sessionService.getSession(sessionId)returns a copy of the session.pluginManager.onUserMessageCallback(initialContext, newMessage)is triggered using this copy.- Any
stateDeltapassed in therunAsynccall is missing from theinitialContext. - The
stateDeltais only applied insideappendNewMessageToSessionafter the plugin execution, leading to inconsistent behavior during the plugin lifecycle.
Expected Behavior
The stateDelta must be integrated into the session state before the InvocationContext is created and before any plugins are notified. This ensures that plugins operate on a consistent and up-to-date representation of the user session.