Fix: preserve modelOverride in agent handler (#5369)#15
Open
BingqingLyu wants to merge 2 commits into
Open
Conversation
) When building the session-entry patch in the agent handler, the cached `entry` may be stale relative to the store — e.g. when sessions.patch writes modelOverride between spawn and run (~3% failure rate for sub-agent model overrides). mergeSessionEntry spreads {...freshStore, ...patch}, so any field read from stale `entry` and placed in the patch clobbers the fresh store value. Fix by removing blind stale-writebacks from the patch. mergeSessionEntry preserves anything not in the patch, so fresh modelOverride, providerOverride, sendPolicy, skillsSnapshot, thinkingLevel, cliSessionBindings, etc. survive the write. Fixes openclaw#5369
Ensure no future change silently re-adds a stale-cache field read to the agent session-entry patch. The original openclaw#5369 test only asserted modelOverride and providerOverride; this one asserts the whole class (sendPolicy, skillsSnapshot, thinkingLevel, fastMode, verboseLevel, traceLevel, reasoningLevel, systemSent, spawnedWorkspaceDir, spawnDepth, cliSessionIds, cliSessionBindings, claudeCliSessionId) survives a stale-cache / fresh-store race. Verified to fail when any of those fields is re-added to nextEntryPatch as `entry?.X`.
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 the intermittent race condition where sub-agent model overrides were silently ignored (~3% failure rate).
sessions_spawnsets a model override viasessions.patch, the agent handler could read stale cached data and overwrite the freshmodelOverridewhen writing back to the session storeupdateSessionStoremutator, ensuring it always uses fresh store data (loaded withskipCache: true)Root Cause
The agent handler was:
loadSessionEntry()(could return cached/stale data)nextEntrywithmodelOverride: entry?.modelOverride(potentially undefined)updateSessionStore()which correctly re-reads withskipCache: truestore[key] = nextEntryThis meant freshly-written
modelOverridevalues fromsessions.patchcould be overwritten.Changes
src/gateway/server-methods/agent.ts: Build session entry insideupdateSessionStoreusing fresh store datasrc/gateway/server-methods/agent.test.ts: Add 4 comprehensive tests for the fixTest plan
issue #5369: agent handler preserves fresh modelOverride from storeissue #5369: request params override fresh store values for label/spawnedByissue #5369: creates new entry when store has no existing entryissue #5369: preserves all important fields from fresh storeFixes openclaw#5369
Supersedes openclaw#8398 (rebased onto latest main to resolve conflicts).
Greptile Summary
Fixes race condition where sub-agent
modelOverridevalues set viasessions.patchcould be silently overwritten. The agent handler previously built session entries using potentially stale cached data, then overwrote fresh store values. The fix moves session entry construction inside theupdateSessionStoremutator, ensuring it always reads and uses fresh store data (loaded withskipCache: true).updateSessionStoremutator (src/gateway/server-methods/agent.ts:391-443)freshEntryfrom store instead of staleentryfor all fields thatsessions.patchcan modifysendPolicydenial handling inside the mutator with structured return valuestorePathand no-storePath (fallback) cases correctlyConfidence Score: 5/5
Last reviewed commit: ffe4cde
(5/5) You can turn off certain types of comments like style here!