How to repair programmatically this crazy face?

Steve beat me.

It looks like the same issue as this.

Select one of the edges in the inner ‘loop’, and run this code to delete and recreate it.

mod = Sketchup.active_model
sel = mod.selection
ent = mod.entities
e = sel[0]
p1 = e.start.position.to_a
p2 = e.end.position.to_a
e.erase!
ent.add_line(p1,p2)