@@ -762,16 +762,17 @@ export function resolveDeletedAgentIdFromSessionKey(
762762 return agentId ;
763763}
764764
765- export function loadSessionEntry ( sessionKey : string , opts ?: { agentId ?: string } ) {
765+ export function loadSessionEntry ( sessionKey : string , opts ?: { agentId ?: string ; clone ?: boolean } ) {
766766 const cfg = getRuntimeConfig ( ) ;
767767 const key = normalizeOptionalString ( sessionKey ) ?? "" ;
768768 const target = resolveGatewaySessionStoreTarget ( {
769769 cfg,
770770 key,
771+ ...( opts ?. clone === false ? { clone : false } : { } ) ,
771772 ...( opts ?. agentId ? { agentId : opts . agentId } : { } ) ,
772773 } ) ;
773774 const storePath = target . storePath ;
774- const store = loadSessionStore ( storePath ) ;
775+ const store = loadSessionStore ( storePath , opts ?. clone === false ? { clone : false } : undefined ) ;
775776 const freshestMatch = resolveFreshestSessionStoreMatchFromStoreKeys ( store , target . storeKeys ) ;
776777 const legacyKey = freshestMatch ?. key !== target . canonicalKey ? freshestMatch ?. key : undefined ;
777778 return {
@@ -1148,6 +1149,7 @@ function resolveGatewaySessionStoreLookup(params: {
11481149 key : string ;
11491150 canonicalKey : string ;
11501151 agentId : string ;
1152+ clone ?: boolean ;
11511153 initialStore ?: Record < string , SessionEntry > ;
11521154} ) : {
11531155 storePath : string ;
@@ -1160,8 +1162,9 @@ function resolveGatewaySessionStoreLookup(params: {
11601162 agentId : params . agentId ,
11611163 storePath : resolveStorePath ( params . cfg . session ?. store , { agentId : params . agentId } ) ,
11621164 } ;
1165+ const loadOptions = params . clone === false ? { clone : false } : undefined ;
11631166 let selectedStorePath = fallback . storePath ;
1164- let selectedStore = params . initialStore ?? loadSessionStore ( fallback . storePath ) ;
1167+ let selectedStore = params . initialStore ?? loadSessionStore ( fallback . storePath , loadOptions ) ;
11651168 let selectedMatch = findFreshestStoreMatch ( selectedStore , ...scanTargets ) ;
11661169 let selectedUpdatedAt = selectedMatch ?. entry . updatedAt ?? Number . NEGATIVE_INFINITY ;
11671170
@@ -1170,7 +1173,7 @@ function resolveGatewaySessionStoreLookup(params: {
11701173 if ( ! candidate ) {
11711174 continue ;
11721175 }
1173- const store = loadSessionStore ( candidate . storePath ) ;
1176+ const store = loadSessionStore ( candidate . storePath , loadOptions ) ;
11741177 const match = findFreshestStoreMatch ( store , ...scanTargets ) ;
11751178 if ( ! match ) {
11761179 continue ;
@@ -1196,6 +1199,7 @@ function resolveGatewaySessionStoreLookup(params: {
11961199function resolveExplicitDeletedLegacyMainStoreTarget ( params : {
11971200 cfg : OpenClawConfig ;
11981201 key : string ;
1202+ clone ?: boolean ;
11991203 scanLegacyKeys ?: boolean ;
12001204} ) : {
12011205 agentId : string ;
@@ -1232,11 +1236,12 @@ function resolveExplicitDeletedLegacyMainStoreTarget(params: {
12321236 match : { entry : SessionEntry ; key : string } ;
12331237 }
12341238 | undefined ;
1239+ const loadOptions = params . clone === false ? { clone : false } : undefined ;
12351240 for ( const target of resolveAllAgentSessionStoreTargetsSync ( params . cfg ) ) {
12361241 if ( target . agentId !== legacyAgentId ) {
12371242 continue ;
12381243 }
1239- const store = loadSessionStore ( target . storePath ) ;
1244+ const store = loadSessionStore ( target . storePath , loadOptions ) ;
12401245 const match = findFreshestStoreMatch ( store , ...lookupSeeds ) ;
12411246 if ( ! match ) {
12421247 continue ;
@@ -1274,6 +1279,7 @@ export function resolveGatewaySessionStoreTarget(params: {
12741279 cfg : OpenClawConfig ;
12751280 key : string ;
12761281 agentId ?: string ;
1282+ clone ?: boolean ;
12771283 scanLegacyKeys ?: boolean ;
12781284 store ?: Record < string , SessionEntry > ;
12791285} ) : {
@@ -1286,6 +1292,7 @@ export function resolveGatewaySessionStoreTarget(params: {
12861292 const explicitDeletedMainTarget = resolveExplicitDeletedLegacyMainStoreTarget ( {
12871293 cfg : params . cfg ,
12881294 key,
1295+ clone : params . clone ,
12891296 scanLegacyKeys : params . scanLegacyKeys ,
12901297 } ) ;
12911298 if ( explicitDeletedMainTarget ) {
@@ -1306,6 +1313,7 @@ export function resolveGatewaySessionStoreTarget(params: {
13061313 key,
13071314 canonicalKey,
13081315 agentId,
1316+ clone : params . clone ,
13091317 initialStore : params . store ,
13101318 } ) ;
13111319
0 commit comments