@@ -623,31 +623,31 @@ export async function runSessionsCleanup(params: {
623623 mode,
624624 maintenance,
625625 } ) ;
626- const preview = previewResults . find (
627- ( result ) => result . summary . storePath === target . storePath ,
628- ) ;
626+ const missing = missingRemovals . filter ( ( { sessionKey } ) =>
627+ removedSessionKeys . has ( sessionKey ) ,
628+ ) . length ;
629+ const dmScopeRetired = dmScopeRetiredRemovals . filter ( ( { sessionKey } ) =>
630+ removedSessionKeys . has ( sessionKey ) ,
631+ ) . length ;
632+ const maintenanceRemovedEntries =
633+ lifecycleResult . modelRunPruned + lifecycleResult . pruned + lifecycleResult . capped ;
629634 const summary : SessionCleanupSummary = {
630- ...( preview ?. summary ?? {
631- agentId : target . agentId ,
632- storePath : target . storePath ,
633- mode,
634- dryRun : false ,
635- beforeCount : 0 ,
636- afterCount : 0 ,
637- missing : 0 ,
638- dmScopeRetired : 0 ,
639- modelRunPruned : 0 ,
640- pruned : 0 ,
641- capped : 0 ,
642- unreferencedArtifacts,
643- diskBudget : null ,
644- wouldMutate : false ,
645- } ) ,
635+ agentId : target . agentId ,
636+ storePath : target . storePath ,
637+ mode,
646638 dryRun : false ,
639+ beforeCount : lifecycleResult . beforeCount ,
640+ afterCount : lifecycleResult . afterCount ,
641+ missing,
642+ dmScopeRetired,
643+ modelRunPruned : lifecycleResult . modelRunPruned ,
644+ pruned : lifecycleResult . pruned ,
645+ capped : lifecycleResult . capped ,
647646 unreferencedArtifacts,
648647 diskBudget : appliedDiskBudget ,
649648 wouldMutate :
650- removedSessionKeys . size > 0 ||
649+ lifecycleResult . removedEntries > 0 ||
650+ maintenanceRemovedEntries > 0 ||
651651 unreferencedArtifacts . removedFiles > 0 ||
652652 ( appliedDiskBudget ?. removedEntries ?? 0 ) > 0 ||
653653 ( appliedDiskBudget ?. removedFiles ?? 0 ) > 0 ||
@@ -669,24 +669,37 @@ export async function runSessionsCleanup(params: {
669669export async function purgeAgentSessionStoreEntries (
670670 cfg : OpenClawConfig ,
671671 agentId : string ,
672- ) : Promise < void > {
672+ ) : Promise < boolean > {
673+ const normalizedAgentId = normalizeAgentId ( agentId ) ;
674+ let storePath = typeof cfg . session ?. store === "string" ? cfg . session . store : "<default>" ;
673675 try {
674- const normalizedAgentId = normalizeAgentId ( agentId ) ;
675676 const storeConfig = cfg . session ?. store ;
676677 const storeAgentId =
677678 typeof storeConfig === "string" && ! storeConfig . includes ( "{agentId}" )
678679 ? resolveSessionStoreCompatibilityAgentId ( cfg )
679680 : normalizedAgentId ;
680- const storePath = resolveSessionStorePathCore ( cfg . session ?. store , {
681+ storePath = resolveSessionStorePathCore ( cfg . session ?. store , {
681682 agentId : normalizedAgentId ,
682683 } ) ;
684+ const sqlitePath = resolveSqliteTargetFromSessionStorePath ( storePath , {
685+ agentId : storeAgentId ,
686+ } ) . path ;
687+ if ( ! sqlitePath || ! fs . existsSync ( sqlitePath ) ) {
688+ return false ;
689+ }
683690 await purgeDeletedAgentSessionEntries ( {
684691 cfg,
685692 agentId : normalizedAgentId ,
686693 storeAgentId,
687694 storePath,
688695 } ) ;
689- } catch ( err ) {
690- getLogger ( ) . debug ( "session store purge skipped during agent delete" , err ) ;
696+ return false ;
697+ } catch ( error ) {
698+ getLogger ( ) . warn ( "session store purge failed during agent deletion" , {
699+ agentId : normalizedAgentId ,
700+ error,
701+ storePath,
702+ } ) ;
703+ return true ;
691704 }
692705}
0 commit comments