There are conventions galore that will determine which accidental is "correct" but the most important consideration imho is What Makes The Passage Easiest To Read/Understand By The Musician Who Has To Perform It?
E.g., most musicians are accustomed to seeing stepwise motion, or triadic arpeggios spelled out so that the implied chord shape is recognizeable...while there are some situations where the prevailing key signature, or direction of motion, might make a different spelling more "correct", it almost always yields more immediate results to temporarily violate convention to allow the performer to quickly recognize these patterns.
E.g., most musicians are accustomed to seeing stepwise motion, or triadic arpeggios spelled out so that the implied chord shape is recognizeable...while there are some situations where the prevailing key signature, or direction of motion, might make a different spelling more "correct", it almost always yields more immediate results to temporarily violate convention to allow the performer to quickly recognize these patterns.