The core problem is that the geometry nodes modifier sometimes support "mapping" (i.e. it remembers which new vertices correspond to edit mode vertices) and sometimes it does not, depending on what the nodes are doing. Also see rB07ce9910f7cc: Geometry Nodes: enabled supports-mapping in nodes modifier.
The solution here is that the fallback case in BKE_mesh_foreach_mapped_edge does not call the callback with "invalid" indices.
Alternative solutions:
- Just don't implement the fallback solution for the case when CustomData_get_layer(&mesh->edata, CD_ORIGINDEX) returns null. This will probably result in a regression in other cases.
- Make the "supports mapping" flag on modifiers more flexible to allow modifiers to sometimes support it and sometimes not. That's probably a better long term solution, but will require quite a bit more work.