@@ -502,19 +502,24 @@ export default class Account {
502502 }
503503 if ( actionsDone ) {
504504 const mappings = this . syncProcess . getMappingsInstance ( )
505- if ( this . server . isAtomic ( ) ) {
506- Logger . log ( 'progressCallback: Persisting cache' )
507- if ( ! this . localCachingResource ) {
508- return
509- }
510- const cache = ( await this . localCachingResource . getCacheTree ( ) ) . clone (
511- false
512- )
513- this . syncProcess . filterOutUnacceptedBookmarks ( cache )
514- await this . storage . setCache ( cache )
515- Logger . log ( 'progressCallback: Persisting mappings' )
516- await mappings . persist ( )
517- } else {
505+ if ( ! this . localCachingResource ) {
506+ return
507+ }
508+ // Persist the cache incrementally in *both* the atomic and non-atomic cases.
509+ // Previously the cache was only persisted here for atomic adapters; for non-atomic
510+ // adapters it was written only on successful sync completion (see sync()). During a long
511+ // run of interrupted (never-completed) syncs that left the stored cache stale, so the next
512+ // fresh sync re-saw already-synced items as new creations and re-created them on the
513+ // non-atomic server — accumulating duplicate folders whose mappings then collided
514+ // (MappingFailureError -> reset+forceSync -> divergence). Mappings are already persisted at
515+ // the interrupt point; the cache must be kept in step with them.
516+ Logger . log ( 'progressCallback: Persisting cache' )
517+ const cache = ( await this . localCachingResource . getCacheTree ( ) ) . clone (
518+ false
519+ )
520+ this . syncProcess . filterOutUnacceptedBookmarks ( cache )
521+ await this . storage . setCache ( cache )
522+ if ( ! this . server . isAtomic ( ) ) {
518523 Logger . log ( 'progressCallback: Serializing continuation' )
519524 const cont = await this . syncProcess . toJSONAsync ( )
520525 if ( ! this . syncing ) {
@@ -525,9 +530,9 @@ export default class Account {
525530 }
526531 Logger . log ( 'progressCallback: Persisting continuation' )
527532 await this . storage . setCurrentContinuation ( cont )
528- Logger . log ( 'progressCallback: Persisting mappings' )
529- await mappings . persist ( )
530533 }
534+ Logger . log ( 'progressCallback: Persisting mappings' )
535+ await mappings . persist ( )
531536 }
532537 }
533538
0 commit comments