I recall an hn post a bit back that cataloged all the ways POSIX guaranteed atomicity, which might help bashdb. Rename is the first thing I’d explore.
Maybe this from 2010 is what I was remembering from a repost, alas the link has rotted:
Maybe this from 2010 is what I was remembering from a repost, alas the link has rotted: