fix: Pre-merge stateDelta before onUserMessageCallback#1117
Open
YuqiGuo105 wants to merge 1 commit intogoogle:mainfrom
Open
fix: Pre-merge stateDelta before onUserMessageCallback#1117YuqiGuo105 wants to merge 1 commit intogoogle:mainfrom
YuqiGuo105 wants to merge 1 commit intogoogle:mainfrom
Conversation
The stateDelta was not merged into session state before onUserMessageCallback was invoked, causing plugins to see null values when reading caller-provided state entries. This fix pre-merges stateDelta into the session's in-memory state before creating the InvocationContext. Since the session is already a copy from getSession(), this is safe and does not affect the persistence path which still happens via EventActions in appendNewMessageToSession. Added test: onUserMessageCallback_withStateDelta_seesMergedState
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.
Summary
Fixes #1099
When
runner.runAsync(userId, sessionId, message, config, stateDelta)is called, thestateDeltamap was not merged into the session beforepluginManager.onUserMessageCallbackwas executed. This caused plugins to seenullwhen reading caller-provided state entries.Root Cause
In
Runner.runAsyncImpl, the execution order was:initialContextusing the original session (no stateDelta)onUserMessageCallback(initialContext, message)- plugins see stale stateappendNewMessageToSession(...)which writes stateDelta via EventActionsbeforeRunCallback- plugins see correct stateFix
Pre-merge stateDelta into the session's in-memory state before creating the initial context. This is safe because the session is already a copy from
getSession(). Persistence still happens via EventActions inappendNewMessageToSession, making this an idempotent optimization.Workflow Comparison
BEFORE (Bug)
AFTER (Fixed)
Changes
onUserMessageCallback_withStateDelta_seesMergedStatetestTesting
All 56 RunnerTest tests pass, including the new test and existing
beforeRunCallback_withStateDelta_seesMergedState.