@@ -630,12 +630,17 @@ export async function migrateOrphanedSessionKeys(params: {
630630 } ) ;
631631 const pluginAgentIdSet = new Set ( pluginAgentIds . map ( ( id ) => normalizeAgentId ( id ) ) ) ;
632632
633- // Collect all known agent store paths with their owning agentIds.
634- // A single path may be shared by multiple agents when session.store
635- // does not contain {agentId}.
633+ // Fixed session.store paths can be shared by several agent owners.
636634 const storeMap = new Map < string , Set < string > > ( ) ;
637635 const storeAliasCandidates = new Map < string , Set < string > > ( ) ;
638636 const addToStoreMap = ( p : string , id : string ) => {
637+ try {
638+ if ( ! fs . statSync ( p , { throwIfNoEntry : false } ) ?. isFile ( ) ) {
639+ return ;
640+ }
641+ } catch {
642+ // Inaccessible paths must stay in their fail-closed alias group.
643+ }
639644 // A fixed-store owner is durable migration provenance. Keep other configured
640645 // agents from making that store's unscoped rows look ambiguous.
641646 const ownerId =
@@ -649,12 +654,7 @@ export async function migrateOrphanedSessionKeys(params: {
649654 const aliasCandidates = storeAliasCandidates . get ( storePath ) ?? new Set ( [ storePath ] ) ;
650655 aliasCandidates . add ( p ) ;
651656 storeAliasCandidates . set ( storePath , aliasCandidates ) ;
652- const existing = storeMap . get ( storePath ) ;
653- if ( existing ) {
654- existing . add ( ownerId ) ;
655- } else {
656- storeMap . set ( storePath , new Set ( [ ownerId ] ) ) ;
657- }
657+ storeMap . set ( storePath , ( storeMap . get ( storePath ) ?? new Set < string > ( ) ) . add ( ownerId ) ) ;
658658 } ;
659659 // Configured ownership includes normal agents plus ACP runtime/default hints.
660660 for ( const configuredAgentId of listConfiguredSessionStoreAgentIds ( params . cfg ) ) {
0 commit comments