@@ -2291,85 +2291,87 @@ describe("gateway agent handler", () => {
22912291 it . each ( [ "all" , "non-main" ] as const ) (
22922292 "does not preload startup memory from inherited workspaces for spawned sandboxed sessions in %s mode" ,
22932293 async ( sandboxMode ) => {
2294- vi . useFakeTimers ( ) ;
2295- vi . setSystemTime ( new Date ( "2026-04-27T12:00:00.000Z" ) ) ;
2296- try {
2297- await withTempDir (
2298- { prefix : "openclaw-gateway-startup-canonical-" } ,
2299- async ( canonicalWorkspaceDir ) => {
2300- await withTempDir (
2301- { prefix : "openclaw-gateway-startup-inherited-" } ,
2302- async ( inheritedWorkspaceDir ) => {
2303- await fs . mkdir ( `${ inheritedWorkspaceDir } /memory` , { recursive : true } ) ;
2304- const inheritedMarker = "OC_INHERITED_WORKSPACE_MEMORY_MARKER" ;
2305- await fs . writeFile (
2306- `${ inheritedWorkspaceDir } /memory/2026-04-27.md` ,
2307- inheritedMarker ,
2308- "utf-8" ,
2309- ) ;
2310- mocks . loadConfigReturn = {
2311- agents : {
2312- defaults : {
2313- workspace : canonicalWorkspaceDir ,
2314- userTimezone : "UTC" ,
2315- startupContext : {
2316- enabled : true ,
2317- applyOn : [ "new" ] ,
2318- dailyMemoryDays : 1 ,
2319- } ,
2320- sandbox : {
2321- mode : sandboxMode ,
2322- scope : "session" ,
2323- workspaceAccess : "none" ,
2294+ vi . useFakeTimers ( ) ;
2295+ vi . setSystemTime ( new Date ( "2026-04-27T12:00:00.000Z" ) ) ;
2296+ try {
2297+ await withTempDir (
2298+ { prefix : "openclaw-gateway-startup-canonical-" } ,
2299+ async ( canonicalWorkspaceDir ) => {
2300+ await withTempDir (
2301+ { prefix : "openclaw-gateway-startup-inherited-" } ,
2302+ async ( inheritedWorkspaceDir ) => {
2303+ await fs . mkdir ( `${ inheritedWorkspaceDir } /memory` , { recursive : true } ) ;
2304+ const inheritedMarker = "OC_INHERITED_WORKSPACE_MEMORY_MARKER" ;
2305+ await fs . writeFile (
2306+ `${ inheritedWorkspaceDir } /memory/2026-04-27.md` ,
2307+ inheritedMarker ,
2308+ "utf-8" ,
2309+ ) ;
2310+ mocks . loadConfigReturn = {
2311+ agents : {
2312+ defaults : {
2313+ workspace : canonicalWorkspaceDir ,
2314+ userTimezone : "UTC" ,
2315+ startupContext : {
2316+ enabled : true ,
2317+ applyOn : [ "new" ] ,
2318+ dailyMemoryDays : 1 ,
2319+ } ,
2320+ sandbox : {
2321+ mode : sandboxMode ,
2322+ scope : "session" ,
2323+ workspaceAccess : "none" ,
2324+ } ,
23242325 } ,
23252326 } ,
2326- } ,
2327- } ;
2328- mockSessionResetSuccess ( {
2329- reason : "new" ,
2330- key : "agent:main:subagent:sandbox-child" ,
2331- } ) ;
2332- mocks . loadSessionEntry . mockReturnValue ( {
2333- cfg : mocks . loadConfigReturn ,
2334- storePath : "/tmp/sessions.json" ,
2335- entry : {
2336- sessionId : "existing-child-session" ,
2337- updatedAt : Date . now ( ) ,
2338- spawnedBy : "agent:main:main" ,
2339- spawnedWorkspaceDir : inheritedWorkspaceDir ,
2340- } ,
2341- canonicalKey : "agent:main:subagent:sandbox-child" ,
2342- } ) ;
2343- mocks . updateSessionStore . mockResolvedValue ( undefined ) ;
2344- mocks . agentCommand . mockResolvedValue ( {
2345- payloads : [ { text : "ok" } ] ,
2346- meta : { durationMs : 100 } ,
2347- } ) ;
2348-
2349- await invokeAgent (
2350- {
2351- message : "/new" ,
2352- sessionKey : "agent:main:subagent:sandbox-child" ,
2353- idempotencyKey : `test-idem-new-spawned-sandbox-memory-${ sandboxMode } ` ,
2354- } ,
2355- {
2356- reqId : `4-startup-spawned-sandbox-memory-${ sandboxMode } ` ,
2357- client : { connect : { scopes : [ "operator.admin" ] } } as AgentHandlerArgs [ "client" ] ,
2358- } ,
2359- ) ;
2327+ } ;
2328+ mockSessionResetSuccess ( {
2329+ reason : "new" ,
2330+ key : "agent:main:subagent:sandbox-child" ,
2331+ } ) ;
2332+ mocks . loadSessionEntry . mockReturnValue ( {
2333+ cfg : mocks . loadConfigReturn ,
2334+ storePath : "/tmp/sessions.json" ,
2335+ entry : {
2336+ sessionId : "existing-child-session" ,
2337+ updatedAt : Date . now ( ) ,
2338+ spawnedBy : "agent:main:main" ,
2339+ spawnedWorkspaceDir : inheritedWorkspaceDir ,
2340+ } ,
2341+ canonicalKey : "agent:main:subagent:sandbox-child" ,
2342+ } ) ;
2343+ mocks . updateSessionStore . mockResolvedValue ( undefined ) ;
2344+ mocks . agentCommand . mockResolvedValue ( {
2345+ payloads : [ { text : "ok" } ] ,
2346+ meta : { durationMs : 100 } ,
2347+ } ) ;
2348+
2349+ await invokeAgent (
2350+ {
2351+ message : "/new" ,
2352+ sessionKey : "agent:main:subagent:sandbox-child" ,
2353+ idempotencyKey : `test-idem-new-spawned-sandbox-memory-${ sandboxMode } ` ,
2354+ } ,
2355+ {
2356+ reqId : `4-startup-spawned-sandbox-memory-${ sandboxMode } ` ,
2357+ client : {
2358+ connect : { scopes : [ "operator.admin" ] } ,
2359+ } as AgentHandlerArgs [ "client" ] ,
2360+ } ,
2361+ ) ;
23602362
2361- await waitForAssertion ( ( ) => expect ( mocks . agentCommand ) . toHaveBeenCalled ( ) ) ;
2362- const call = readLastAgentCommandCall ( ) ;
2363- expect ( call ?. message ) . toContain ( "Execute your Session Startup sequence now" ) ;
2364- expect ( call ?. message ) . not . toContain ( "[Startup context loaded by runtime]" ) ;
2365- expect ( call ?. message ) . not . toContain ( inheritedMarker ) ;
2366- } ,
2367- ) ;
2368- } ,
2369- ) ;
2370- } finally {
2371- vi . useRealTimers ( ) ;
2372- }
2363+ await waitForAssertion ( ( ) => expect ( mocks . agentCommand ) . toHaveBeenCalled ( ) ) ;
2364+ const call = readLastAgentCommandCall ( ) ;
2365+ expect ( call ?. message ) . toContain ( "Execute your Session Startup sequence now" ) ;
2366+ expect ( call ?. message ) . not . toContain ( "[Startup context loaded by runtime]" ) ;
2367+ expect ( call ?. message ) . not . toContain ( inheritedMarker ) ;
2368+ } ,
2369+ ) ;
2370+ } ,
2371+ ) ;
2372+ } finally {
2373+ vi . useRealTimers ( ) ;
2374+ }
23732375 } ,
23742376 ) ;
23752377
0 commit comments