When a builder (lets take the mason as this is a big problem with them) makes something like a wall it seems they have a preffered side to attempt to build from. (preference order is left, top as far as I have bothered to test/observe) This gets my builders stuck a LOT. Could builders start building single tile constructions (no other construction tiles around it) from the direction which they approach it? this way they are guaranteed to have a way back (pending someone didn't build something in the hallway behind them).
A solution for situations when there is more than one tile would be to somehow simulate building the thing to detect which one to build first so as not to trap ones self.
ex.
Wall = X
ground = G (same height as the wall's top)
G
X 1
X 2
X 3
X 4
X 5
builders can only access the top of the wall from G
You have a wall 1 tile wide and you build fortifications on it (the other tiles of the wall aren't built yet, the wall is supposed to be 3 thick). Currently I'm not sure how the builders decide which fortification brick to build first but it seems they prefer to trap themselves. (the builder will build fortifcation 1 from below sometimes and trap themselves) it would be ideal if the AI could quickly glance over the fortification build layout and see that it must start from atleast 5 if it wants a way out.
If it has diagonal access to 2 and thus can build one first then it should/could do that. This isn't a request for super smart building order, just an order so they don't trap themselves. (maybe even so other dwarves don't trap them, aka a "look ahead" where the AI scans down the tunnel (not physically by walking) and checks to make sure it's not sealing anyone off)
Edit: I'm not sure how this will affect the build system as the wiki says it's LIFO so maybe all build jobs should become singular or again use a "look ahead" to make sure completion of one job won't block access to another job first (in that case switch their order on the stack)