@@ -7,7 +7,7 @@ import crypto from "node:crypto";
77import type { ClearSessionQueueResult } from "../auto-reply/reply/queue.js" ;
88import { resolveSubagentLabel , sortSubagentRuns } from "../auto-reply/reply/subagents-utils.js" ;
99import { resolveStorePath } from "../config/sessions/paths.js" ;
10- import { loadSessionStore , updateSessionStore } from "../config/sessions/store .js" ;
10+ import { loadSessionEntry , patchSessionEntry } from "../config/sessions/session-accessor .js" ;
1111import type { SessionEntry } from "../config/sessions/types.js" ;
1212import type { OpenClawConfig } from "../config/types.openclaw.js" ;
1313import { callGateway } from "../gateway/call.js" ;
@@ -50,18 +50,18 @@ const SUBAGENT_REPLY_HISTORY_LIMIT = 50;
5050const steerRateLimit = new Map < string , number > ( ) ;
5151
5252type GatewayCaller = typeof callGateway ;
53- type UpdateSessionStore = typeof updateSessionStore ;
53+ type PatchSessionEntry = typeof patchSessionEntry ;
5454type AbortEmbeddedAgentRun = ( sessionId : string ) => boolean ;
5555type ClearSessionQueues = ( keys : Array < string | undefined > ) => ClearSessionQueueResult ;
5656
5757const defaultSubagentControlDeps = {
5858 callGateway,
59- updateSessionStore ,
59+ patchSessionEntry ,
6060} ;
6161
6262let subagentControlDeps : {
6363 callGateway : GatewayCaller ;
64- updateSessionStore : UpdateSessionStore ;
64+ patchSessionEntry : PatchSessionEntry ;
6565 abortEmbeddedAgentRun ?: AbortEmbeddedAgentRun ;
6666 clearSessionQueues ?: ClearSessionQueues ;
6767} = defaultSubagentControlDeps ;
@@ -187,15 +187,15 @@ async function killSubagentRun(params: {
187187 }
188188 if ( resolved . entry ) {
189189 try {
190- await subagentControlDeps . updateSessionStore ( resolved . storePath , ( store ) => {
191- const current = store [ childSessionKey ] ;
192- if ( ! current ) {
193- return ;
194- }
195- current . abortedLastRun = true ;
196- current . updatedAt = Date . now ( ) ;
197- store [ childSessionKey ] = current ;
198- } ) ;
190+ await subagentControlDeps . patchSessionEntry (
191+ { storePath : resolved . storePath , sessionKey : childSessionKey } ,
192+ ( current ) => ( {
193+ ... current ,
194+ abortedLastRun : true ,
195+ updatedAt : Date . now ( ) ,
196+ } ) ,
197+ { replaceEntry : true } ,
198+ ) ;
199199 } catch ( error ) {
200200 logVerbose (
201201 `subagents control kill: failed to persist abortedLastRun for ${ childSessionKey } : ${ formatErrorMessage ( error ) } ` ,
@@ -660,8 +660,11 @@ export async function sendControlledSubagentMessage(params: {
660660 const targetSessionKey = params . entry . childSessionKey ;
661661 const parsed = parseAgentSessionKey ( targetSessionKey ) ;
662662 const storePath = resolveStorePath ( params . cfg . session ?. store , { agentId : parsed ?. agentId } ) ;
663- const store = loadSessionStore ( storePath ) ;
664- const targetSessionEntry = store [ targetSessionKey ] ;
663+ const targetSessionEntry = loadSessionEntry ( {
664+ storePath,
665+ sessionKey : targetSessionKey ,
666+ clone : false ,
667+ } ) ;
665668 const targetSessionId =
666669 typeof targetSessionEntry ?. sessionId === "string" && targetSessionEntry . sessionId . trim ( )
667670 ? targetSessionEntry . sessionId . trim ( )
@@ -724,7 +727,7 @@ export const testing = {
724727 setDepsForTest (
725728 overrides ?: Partial < {
726729 callGateway : GatewayCaller ;
727- updateSessionStore : UpdateSessionStore ;
730+ patchSessionEntry : PatchSessionEntry ;
728731 abortEmbeddedAgentRun : AbortEmbeddedAgentRun ;
729732 clearSessionQueues : ClearSessionQueues ;
730733 } > ,
0 commit comments