Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

Stop hnswlib's wheel core-dumping the whole Python job (#223)

Fabio Rovaiac1b0d3300c6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cb7b557e..3dfc7c28 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -347,9 +347,32 @@ jobs:
run: cargo build --release --bin open-ontologies
# shacl and align as well as dev. Those two extras are the whole reason
# three more files skipped here, and they are small.
+ # `hnswlib` is built from source rather than taken as a wheel.
+ #
+ # The published wheel is compiled for a newer CPU than some of GitHub's
+ # runners provide, and it raises SIGILL on IMPORT. No `try`/`except`
+ # reaches that: the interpreter dies during collection and takes the
+ # whole suite with it, so the job fails with "Fatal Python error:
+ # Illegal instruction" and a core dump, on branches that touched no
+ # Python at all. Seen twice on 19 September 2026, on #211 (a docs-only
+ # change) and #219. Building it here compiles for the CPU the job is
+ # actually running on.
+ #
+ # Two more things, learned from the first attempt, which built from
+ # source and STILL crashed on import. hnswlib's setup.py compiles with
+ # `-march=native` unless HNSWLIB_NO_NATIVE is set, and setup-uv caches
+ # BUILT WHEELS across runners, keyed by requirements files and never by
+ # CPU, so a native build from one machine is handed to the next. The
+ # env var drops the flag. `--no-cache` is what forces the compile:
+ # measured locally, `--reinstall-package` and `--refresh-package` both
+ # still "Prepared 1 package in 0.39ms" from the wheel cache, while
+ # `--no-cache` logs "Building hnswlib" and the resulting compiler lines
+ # contain -march=native 0 times with the env var and 4 without.
- name: Install with the extras the tests need
working-directory: python
- run: uv pip install --system -e ".[dev,shacl,align]"
+ env:
+ HNSWLIB_NO_NATIVE: "1"
+ run: uv pip install --system --no-cache --no-binary hnswlib -e ".[dev,shacl,align]"
- name: Test
working-directory: python
run: python -m pytest -q
diff --git a/python/tests/test_align.py b/python/tests/test_align.py
index a1bf613e..1d1e8980 100644
--- a/python/tests/test_align.py
+++ b/python/tests/test_align.py
@@ -2,8 +2,57 @@
Run: pip install -e ".[align,dev]" && pytest -q
"""
+import subprocess
+import sys
+
import pytest
+
+def _first_import_that_dies() -> str | None:
+ """Import numpy, then hnswlib, each in its own SUBPROCESS, and name the
+ first one that kills the interpreter.
+
+ Two, not one, because hnswlib imports numpy: a probe that imports only
+ hnswlib blames hnswlib for a numpy crash, and the fix for each is
+ different. numpy dispatches on the CPU at run time and should not do
+ this; hnswlib compiles with -march=native and does it whenever the wheel
+ was built on a newer CPU than the one running it.
+ """
+ for module in ("numpy", "hnswlib"):
+ r = subprocess.run([sys.executable, "-c", f"import {module}"], capture_output=True)
+ if r.returncode != 0:
+ return f"{module} (exit {r.returncode}{', SIGILL' if r.returncode in (-4, 132) else ''})"
+ return None
+
+
+def _import_survives_in_a_subprocess() -> bool:
+ """Import `hnswlib` in a SUBPROCESS before importing it here.
+
+ A wheel compiled for a newer CPU than the machine provides raises SIGILL on
+ import, and no `try`/`except` reaches that: the interpreter dies during
+ COLLECTION and takes every other test in the run with it. The job then
+ reports "Fatal Python error: Illegal instruction" and a core dump, with no
+ indication of which import did it. That happened twice on 19 September 2026,
+ on branches that touched no Python.
+
+ CI builds hnswlib from source so this should not fire. It is here so that if
+ it ever does, the run says which library and why instead of dying.
+ """
+ return subprocess.run(
+ [sys.executable, "-c", "import hnswlib"],
+ capture_output=True,
+ ).returncode == 0
+
+
+_DEAD = _first_import_that_dies()
+if _DEAD is not None:
+ pytest.fail(
+ f"{_DEAD} crashes the interpreter on import: a wheel built for a CPU this "
+ "machine does not have. For hnswlib, build it here without -march=native: "
+ "HNSWLIB_NO_NATIVE=1 pip install --no-binary hnswlib --force-reinstall hnswlib",
+ pytrace=False,
+ )
+
hnswlib = pytest.importorskip("hnswlib") # noqa: F841
from open_ontologies_lite import AlignmentIndex # noqa: E402