One function

order_layers in fasouto/termaid

The author described this change as fix: keep all nodes when an orthogonal subgraph contains a cycle. It counts as a record because the check below fails on the code as it stood at e88991c2d and passes on 81c69b2d7, with nothing else changed between the two runs.

Fix saved2026-06-11
Sharing licenceMIT · LICENSE
Change size+5 3

What the code was meant to do, written into the code itself as a docstring

Order nodes within each layer using barycenter heuristic.

The change

6767 in_degree[succ] -= 1
6868 if in_degree[succ] == 0:
6969 kahn_queue.append(succ)
70- # Replace in-layer positions: find positions of sg nodes, fill with topo order
70+ # Replace in-layer positions: find positions of sg nodes, fill with topo order.
71+ # A cycle leaves topo incomplete; rewriting then duplicates
72+ # some nodes and drops others, so keep the original order.
7173 positions = [i for i, n in enumerate(layer) if n in internal]
72- for idx, pos in enumerate(positions):
73- if idx < len(topo):
74+ if len(topo) == len(positions):
75+ for idx, pos in enumerate(positions):
7476 layer[pos] = topo[idx]
7577
7678 return layer_lists

The check that tells the two apart

failpass·tests/test_layout.py::TestOrthogonalSubgraphOrdering::test_cyclic_subgraph_keeps_all_nodes

Check file tests/test_layout.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before ite88991c2df3e657899070548830e7571732650f5
Broken version dated2026-06-11
Moduletermaid.layout.layers
Units changedorder_layers
Fingerprint809ff463681bbc6f
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in fasouto/termaid