@@ -174,6 +174,29 @@ export abstract class MemoryManagerSourceSyncOps extends MemoryManagerSessionSyn
174174 const deleteChunksByPathAndSource = this . db . prepare (
175175 `DELETE FROM memory_index_chunks WHERE path = ? AND source = ?` ,
176176 ) ;
177+ const updateUnchangedSessionSourceMetadata = this . db . prepare (
178+ `UPDATE memory_index_sources
179+ SET mtime = ?, size = ?
180+ WHERE path = ? AND source = 'sessions' AND hash = ?` ,
181+ ) ;
182+ const refreshUnchangedSessionSourceMetadata = ( entry : MemoryIndexEntry ) : boolean => {
183+ // Hash equality preserves chunks and embeddings; only converge the source
184+ // fingerprint so restored sessions do not repeat catch-up on every startup.
185+ return (
186+ updateUnchangedSessionSourceMetadata . run ( entry . mtimeMs , entry . size , entry . path , entry . hash )
187+ . changes === 1
188+ ) ;
189+ } ;
190+ const canSkipUnchangedSessionEntry = (
191+ entry : MemoryIndexEntry ,
192+ absPath : string ,
193+ existingHash : string | undefined ,
194+ ) : boolean => {
195+ if ( params . needsFullReindex || existingHash !== entry . hash ) {
196+ return false ;
197+ }
198+ return ! this . sessionsDirtyFiles . has ( absPath ) || refreshUnchangedSessionSourceMetadata ( entry ) ;
199+ } ;
177200 const deleteFtsRowsByPathAndSource =
178201 this . fts . enabled && this . fts . available
179202 ? this . db . prepare ( `DELETE FROM ${ FTS_TABLE } WHERE path = ? AND source = ?` )
@@ -340,7 +363,7 @@ export abstract class MemoryManagerSourceSyncOps extends MemoryManagerSessionSyn
340363 path : entry . path ,
341364 existingHashes,
342365 } ) ;
343- if ( ! params . needsFullReindex && existingHash === entry . hash ) {
366+ if ( canSkipUnchangedSessionEntry ( entry , absPath , existingHash ) ) {
344367 if ( params . progress ) {
345368 params . progress . completed += 1 ;
346369 params . progress . report ( {
@@ -412,7 +435,7 @@ export abstract class MemoryManagerSourceSyncOps extends MemoryManagerSessionSyn
412435 path : entry . path ,
413436 existingHashes,
414437 } ) ;
415- if ( ! params . needsFullReindex && existingHash === entry . hash ) {
438+ if ( canSkipUnchangedSessionEntry ( entry , absPath , existingHash ) ) {
416439 if ( params . progress ) {
417440 params . progress . completed += 1 ;
418441 params . progress . report ( {
0 commit comments