I have to stop in order to have regular sleep, but I did finally fix the problem with wall gaps being filled in by other walls that happened to go over the original wall with the gap.
The gaps are now properly rendered at the places where they are assigned, but the gaps (gray squares in this debug map) are sometimes nowhere near the walls.