File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -761,4 +761,31 @@ describe("sessions", () => {
761761 expect ( store [ mainSessionKey ] ?. providerOverride ) . toBe ( "anthropic" ) ;
762762 expect ( store [ mainSessionKey ] ?. thinkingLevel ) . toBe ( "high" ) ;
763763 } ) ;
764+
765+ it ( "loadSessionStore skipCache returns a fresh mutable store without tainting cached reads" , async ( ) => {
766+ const mainSessionKey = "agent:main:main" ;
767+ const { storePath } = await createSessionStoreFixture ( {
768+ prefix : "loadSessionStore-skip-cache-fresh" ,
769+ entries : {
770+ [ mainSessionKey ] : {
771+ sessionId : "sess-1" ,
772+ updatedAt : 123 ,
773+ thinkingLevel : "low" ,
774+ } ,
775+ } ,
776+ } ) ;
777+
778+ const fresh = loadSessionStore ( storePath , { skipCache : true } ) ;
779+ expect ( fresh [ mainSessionKey ] ?. thinkingLevel ) . toBe ( "low" ) ;
780+
781+ fresh [ mainSessionKey ] = {
782+ ...fresh [ mainSessionKey ] ,
783+ thinkingLevel : "high" ,
784+ } ;
785+
786+ expect ( loadSessionStore ( storePath ) [ mainSessionKey ] ?. thinkingLevel ) . toBe ( "low" ) ;
787+ expect ( loadSessionStore ( storePath , { skipCache : true } ) [ mainSessionKey ] ?. thinkingLevel ) . toBe (
788+ "low" ,
789+ ) ;
790+ } ) ;
764791} ) ;
Original file line number Diff line number Diff line change @@ -129,5 +129,12 @@ export function loadSessionStore(
129129 } ) ;
130130 }
131131
132+ // `skipCache` callers already forced a fresh disk load, so there is no shared
133+ // cached object to protect here. Returning the parsed store directly avoids an
134+ // extra full-store clone on hot read-modify-write paths.
135+ if ( opts . skipCache ) {
136+ return store ;
137+ }
138+
132139 return structuredClone ( store ) ;
133140}
You can’t perform that action at this time.
0 commit comments