@@ -265,14 +265,23 @@ export class FileSystemStorageClient implements storage.StorageClient {
265265 * - the default request queue.
266266 */
267267 async purge ( ) : Promise < void > {
268- const isDefault = ( store : { name ?: string ; cacheKey : string } ) =>
269- store . name === 'default' || store . cacheKey === 'default' ;
268+ // Resolve the default stores up front so leftover on-disk records are purged even when the
269+ // store has not been opened in this process yet (e.g. a fresh run over a pre-existing
270+ // directory). Opening caches the client, so the subsequent purge operates on a real client.
271+ // The default store is opened via the internal `__default__` alias (see resolveStorageIdentifier
272+ // in @crawlee /core), which resolves to the `default` cache key — match that here so we purge the
273+ // very client the default open would return rather than creating a divergent one.
274+ const [ defaultKeyValueStore , defaultDataset , defaultRequestQueue ] = await Promise . all ( [
275+ this . createKeyValueStoreClient ( { alias : '__default__' } ) as Promise < KeyValueStoreClient > ,
276+ this . createDatasetClient ( { alias : '__default__' } ) as Promise < DatasetClient > ,
277+ this . createRequestQueueClient ( { alias : '__default__' } ) as Promise < RequestQueueClient > ,
278+ ] ) ;
270279
271280 await Promise . all ( [
272281 // Preserve the run input (INPUT) when purging the default key-value store.
273- ... this . keyValueStoreCache . filter ( isDefault ) . map ( async ( store ) => store . purgeExceptInput ( ) ) ,
274- ... this . datasetClientCache . filter ( isDefault ) . map ( async ( store ) => store . purge ( ) ) ,
275- ... this . requestQueueCache . filter ( isDefault ) . map ( async ( store ) => store . purge ( ) ) ,
282+ defaultKeyValueStore . purgeExceptInput ( ) ,
283+ defaultDataset . purge ( ) ,
284+ defaultRequestQueue . purge ( ) ,
276285 ] ) ;
277286 }
278287
0 commit comments