-
fix(relevance): gate ONNX embedding backend behind AVX2 to avoid SIGILL (#1723) (#1765)
发布于
2026-07-03 19:10:34 +00:00 Description
Fixes the
SIGILL/ Illegal instruction crash inheadroom.compresson
CPUs without AVX2 (Docker / QEMU / older cloud VMs). The precompiled
ONNX Runtime binary shipped byort-sys(via fastembed's
ort-download-binaries*feature) contains AVX2-family instructions on
x86; running it on a non-AVX2 CPU traps with SIGILL — an uncatchable
native fault that kills the whole host process. Magika detection was
already guarded (#1162, landed afterv0.28.0); the embedding relevance
scorer shared the sameort-sysbinary with no guard. This PR closes
that remaining entry point and documents the requirement.Closes #1723
Type of Change
- Bug fix (non-breaking change that fixes an issue)
- New feature (non-breaking change that adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to change) - Documentation update
- Performance improvement
- Code refactoring (no functional changes)
Changes Made
- Add shared
onnx_cpu::onnx_runtime_supported_by_cpu()helper (AVX2
check on x86/x86_64,trueon other arches) as the single source of
truth. - Route
magika_detectorthrough the shared helper (no behavior
change). - Gate
EmbeddingScorer::try_new*on the helper: unsupported CPU
returnsErrbefore touching ONNX, so callers fall back to BM25/stub
instead of crashing. - Document the x86 AVX2 requirement + auto-fallback in the README.
- Add offline tests (no network / no
RUN_FASTEMBED_TESTS).
Testing
- Unit tests pass (Rust:
cargo test -p headroom-core) - Linting passes (
cargo clippy -p headroom-core --all-targets,
cargo fmt --check) - Type checking passes (
mypy headroom) — N/A, Rust-only change - New tests added for new functionality
- Manual testing performed
Test Output
$ cargo test -p headroom-core --lib relevance::embedding cargo test: 13 passed, 834 filtered out (1 suite, 0.00s) $ cargo test -p headroom-core --lib magika cargo test: 16 passed, 831 filtered out (1 suite, 0.16s) $ cargo clippy -p headroom-core --all-targets (no warnings, no errors) $ cargo fmt --check -p headroom-core (clean) $ cargo build --workspace cargo build (225 crates compiled) Finished `dev` profile [unoptimized + debuginfo] target(s) in 6m 57sReal Behavior Proof
- Environment:
headroom-coreworkspace, Rust stable, x86_64
(AVX2-capable dev host). - Exact command / steps: added
onnx_guard_matches_cpu_featuresand
try_new_errors_on_unsupported_cpu_instead_of_sigilltests; ran the
suites above. On a no-AVX2 host the guard makes
EmbeddingScorer::try_new()returnErr(... "AVX2" ...)instead of
executing the AVX2 ONNX binary; callers fall back to BM25 relevance
rather than crashing. - Observed result: guard returns
falseonly when the CPU lacks AVX2;
embedding + magika ONNX paths both short-circuit to non-ONNX fallbacks;
no SIGILL. All suites green. - Not tested: end-to-end
pip installrun on a physically AVX2-less
machine (dev host has AVX2); guard behavior is unit-tested via the
sharedonnx_cpuhelper and mirrors the already-shipped magika guard
(#1162).
Review Readiness
- I have performed a self-review
- This PR is ready for human review
Checklist
- My code follows the project's style guidelines
- I have performed a self-review of my code
- I have commented my code, particularly in hard-to-understand areas
- I have made corresponding changes to the documentation
- My changes generate no new warnings
- I have added tests that prove my fix is effective or that my
feature works - New and existing unit tests pass locally with my changes
- I have updated the CHANGELOG.md if applicable — N/A
(release-please generates the changelog)
Additional Notes
Rust-only change, so the Python
pytest/ruff/mypyitems are N/A;
equivalent Rustcargo test/clippy/fmtwere run and pasted above.
The fix is defense-in-depth parity with the existing magika AVX2 guard
(#1162), applied to the second ONNX entry point (embedding relevance).Co-authored-by: Claude Opus 4.8 noreply@anthropic.com
下载附件