@@ -40,6 +40,7 @@ describe("memory index", () => {
4040 let indexExtraPath = "" ;
4141 let indexStatusPath = "" ;
4242 let indexSourceChangePath = "" ;
43+ let indexSessionStartPath = "" ;
4344 let indexModelPath = "" ;
4445 let sourceChangeStateDir = "" ;
4546 const sourceChangeSessionLogLines = [
@@ -73,6 +74,7 @@ describe("memory index", () => {
7374 indexExtraPath = path . join ( workspaceDir , "index-extra.sqlite" ) ;
7475 indexStatusPath = path . join ( workspaceDir , "index-status.sqlite" ) ;
7576 indexSourceChangePath = path . join ( workspaceDir , "index-source-change.sqlite" ) ;
77+ indexSessionStartPath = path . join ( workspaceDir , "index-session-start.sqlite" ) ;
7678 indexModelPath = path . join ( workspaceDir , "index-model-change.sqlite" ) ;
7779 sourceChangeStateDir = path . join ( fixtureRoot , "state-source-change" ) ;
7880
@@ -321,6 +323,44 @@ describe("memory index", () => {
321323 }
322324 } ) ;
323325
326+ it ( "includes sessions in a full reindex triggered from session-start" , async ( ) => {
327+ const stateDir = path . join ( fixtureRoot , "state-session-start" ) ;
328+ const sessionDir = path . join ( stateDir , "agents" , "main" , "sessions" ) ;
329+ await fs . rm ( stateDir , { recursive : true , force : true } ) ;
330+ await fs . mkdir ( sessionDir , { recursive : true } ) ;
331+ await fs . writeFile (
332+ path . join ( sessionDir , "session-start-reindex.jsonl" ) ,
333+ `${ sourceChangeSessionLogLines } \n` ,
334+ ) ;
335+
336+ const previousStateDir = process . env . OPENCLAW_STATE_DIR ;
337+ process . env . OPENCLAW_STATE_DIR = stateDir ;
338+
339+ try {
340+ const cfg = createCfg ( {
341+ storePath : indexSessionStartPath ,
342+ sources : [ "memory" , "sessions" ] ,
343+ sessionMemory : true ,
344+ } ) ;
345+ const result = await getMemorySearchManager ( { cfg, agentId : "main" } ) ;
346+ const manager = requireManager ( result ) ;
347+ await manager . sync ?.( { reason : "session-start" } ) ;
348+ const status = manager . status ( ) ;
349+ expect ( status . sourceCounts ?. find ( ( entry ) => entry . source === "sessions" ) ?. files ) . toBe ( 1 ) ;
350+ expect (
351+ status . sourceCounts ?. find ( ( entry ) => entry . source === "sessions" ) ?. chunks ?? 0 ,
352+ ) . toBeGreaterThan ( 0 ) ;
353+ await manager . close ?.( ) ;
354+ } finally {
355+ if ( previousStateDir === undefined ) {
356+ delete process . env . OPENCLAW_STATE_DIR ;
357+ } else {
358+ process . env . OPENCLAW_STATE_DIR = previousStateDir ;
359+ }
360+ await fs . rm ( stateDir , { recursive : true , force : true } ) ;
361+ }
362+ } ) ;
363+
324364 it ( "reindexes when the embedding model changes" , async ( ) => {
325365 const base = createCfg ( { storePath : indexModelPath } ) ;
326366 const baseAgents = base . agents ! ;
0 commit comments