Skip to content

[4.2-dev] fix(build): pin usearch to a portable arm64 baseline to stop SIGILL on non-SVE CPUs (#30413) - #30609

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
cpegeric:bug_30413_4.2
Oct 20, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
cpegeric:bug_30413_4.2

Conversation

@cpegeric

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #30413 (4.2-dev backport)

What this PR does / why we need it:

HNSW index build crashes mo-service with SIGILL (illegal instruction) inside
the vendored usearch native library (usearch_add) on arm64 images, whenever
there are rows to index. IVFFlat is unaffected.

Root cause

usearch's CMakeLists.txt compiles with -march=native, which tunes the artifact
to the build host's CPU. thirdparties/Makefile already rewrites that to a
portable haswell baseline — but the probe it uses (-march=haswell) only succeeds
on x86, so on arm64 the rewrite was skipped and -march=native survived.

A release/image built on an SVE-capable arm64 host (modern Graviton / Ampere /
Neoverse CI runners) then auto-vectorizes usearch's distance loops into SVE and
bakes those instructions into libusearch_c with no runtime dispatch. That binary
SIGILLs on any arm64 CPU without SVE — e.g. Apple Silicon under Docker, which is
NEON-only. The faulting bytes disassemble to SVE (ptrue p0.s, vl4,
ld1w {z0.s}, p0/z, ...). IVFFlat uses no -march=native native kernel, so it is
unaffected.

(Note: this is not SimSIMD — it is off by default; and not a stale/make clean
artifact — a fresh build on the same SVE host reproduces the same binary.)

Fix

Add the matching arm64 arm to the existing baseline rewrite: when -march=haswell
is unavailable but -march=armv8-a compiles, rewrite usearch's -march=native to
-march=armv8-a. armv8-a is the AArch64 floor — every arm64 CPU implements it —
and keeps mandatory NEON vectorization while dropping the optional SVE. SVE on
genuinely-SVE hardware belongs behind SimSIMD runtime dispatch
(MO_CL_SIMSIMD=1, which already pairs the SVE targets with
SIMSIMD_DYNAMIC_DISPATCH=1), never a static -march.

Validation

  • -march=armv8-a on a representative f32 L2 loop emits 0 SVE / 8 NEON
    instructions; -march=armv8-a+sve emits 5 SVE — so the fix drops exactly the
    crashing SVE while retaining NEON vectorization.
  • Full rebuild with the patched Makefile: usearch + mo-service build clean;
    libusearch_c contains 0 SVE instructions; CREATE INDEX ... USING HNSW on a
    non-empty table builds and the server stays up.
  • The sed rewrite is verified on both GNU (Linux/CI) and BSD (macOS) sed.

🤖 Generated with Claude Code

…does not SIGILL on non-SVE CPUs (matrixorigin#30413)

usearch's CMakeLists compiles with -march=native, tuning the artifact to the
build host's CPU. The thirdparties Makefile already rewrites that to a haswell
baseline on x86, but the probe used (-march=haswell) only succeeds on x86, so on
arm64 the rewrite was skipped and -march=native survived.

An arm64 release/image built on an SVE-capable host (modern Graviton / Ampere /
Neoverse CI runners) then auto-vectorizes usearch's distance loops into SVE and
bakes those instructions into libusearch_c with no runtime dispatch. The binary
SIGILLs (illegal instruction, in usearch_add during HNSW build) on any arm64 CPU
without SVE -- e.g. Apple Silicon under Docker, which is NEON-only. IVFFlat is
unaffected because it uses no -march=native native kernel.

Add the matching arm64 arm: when -march=haswell is unavailable but -march=armv8-a
compiles, rewrite -march=native to -march=armv8-a. armv8-a is the AArch64 floor
(every arm64 CPU implements it) and keeps mandatory NEON vectorization while
dropping the optional SVE. SVE on genuinely-SVE hardware belongs behind SimSIMD
runtime dispatch (MO_CL_SIMSIMD=1), not a static -march.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: 16056d037faac03ea11ec65f467eb8b3a3bb2d4f

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 16056d037faac03ea11ec65f467eb8b3a3bb2d4f

already-reviewed

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-xupeng · review

Commit: 16056d037faac03ea11ec65f467eb8b3a3bb2d4f

Assessment: approve

Reviewed the complete change, vendored CMake configuration, build callers, native consumers and supplied evidence. The fix uses the existing build owner to select a portable ARM64 baseline while preserving x86 behavior. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a15209-2c6d-71e2-b8f3-aa17387fa283 · slot 2 · generation 0

Validation:

  • Compiler probes passed for GCC/Clang x86 and Clang Linux/Darwin ARM64 targets. The base-revision control retained march=native on ARM64.

  • Representative ARM64 distance-loop compilation retained NEON without SVE under armv8-a; the armv8-a+sve control emitted SVE.

  • Repository-owned usearch build passed on Linux x86_64. Verified current input/output hashes and haswell flags for both shared and static libraries.

  • Isolation preflight and all 32 reported vendored C API test cases passed against the freshly built library.

  • Frozen patch correspondence, clean source and diff checks passed. Five successful receipts and matching logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/e9932d2200fe80da6a11e940/attempt-1/validation-manifest.json.

Limitations:

  • Local ARM64 validation used cross-target compiler probes and representative assembly; no ARM64 usearch binary, non-SVE device or MatrixOne SQL-service test was run.

  • Frozen CI metadata reports successful amd64/arm64 native builds, but raw CI and author validation logs were unavailable. local_validation was empty, and the linked issue body was not supplied.

@XuPeng-SH
XuPeng-SH merged commit e34dc2c into matrixorigin:4.2-dev Oct 20, 2026
XuPeng-SH added a commit that referenced this pull request Oct 20, 2026
## What type of PR is this?

- [x] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #30231.

## What this PR does / why we need it:

Fix two independently reproduced UT flake mechanisms seen in #30609 and
#30612 on `4.2-dev`:

- Scope catalog admission hooks to the intended service, connection and
active transaction. An unrelated transaction on the same CN could
capture the barrier and leave the writer admission count at zero. Apply
the same ownership rule to the neighboring DDL-first and stale-ALTER
fixtures. Add real competing SQL before and during the paused writer;
retain all ALTER/standalone, retry, rollback, result and
neighboring-index assertions.
- Semantic-backport main's optional caller-context CN label API from
#30337, preserving the legacy three-second operational API and existing
HAKeeper execution path. Use a bounded phase context and authoritative
refresh in the IVF integration test. Remove redundant label updates and
resultless refresh polling.
- Serialize strict-boundary invalidation with cleanup. Cancel and join
the callback before restoring labels with a fresh context; attempt every
target after partial failure and report cleanup errors. Check exact CN
identities and both labels.

Validation (Go 1.26.4, Darwin/arm64, matching native libraries):

- Full `clusterservice` and operational `ctl` packages: normal and race.
- All affected Issue29715/27966 tests: normal and race.
- Ten race repetitions of ALTER/standalone late admission; three race
repetitions of the real IVF test.
- Deadline/error/identity and partial-update/refresh/cleanup unit cases;
configured incremental gofmt, vet, molint and golangci-lint.
- `gpt-6.1-sol` / `xhigh` design and overall review.

No production query-path, wire, schema or global-timeout change. This
fixes the demonstrated fixture mechanisms; it does not establish the
physical cause of the historical HAKeeper slowdown or eliminate every
possible CI flake. Linux CI remains pending.

### CI follow-up

The first Linux run exposed two additional test synchronization defects:

- Lock caller-deadline tests shared the holder's setup budget, then
asserted a lower bound on only the remaining wait. Separate setup from
the fresh caller deadline, observe real contention, and require
`context.DeadlineExceeded` rather than elapsed-time floors. Cover zero
and explicit lock timeouts and successful release; cancel, release and
join workers before restoring private hooks.
- The tenant stage/fulltext2 test polled MATCH before CDC readiness.
Wait for the durable tail before the first content query, using the same
boundary as its mutation checks. Bound tail/checksum SQL with one
30-second context per transition, report SQL errors, and stop indexed
work before closing the HTTP source. Preserve TXT/PDF/Chinese/DOCX,
mutation, compaction/HNSW and authorization assertions.

A real-SQL diagnostic probe observed an initial empty MATCH, recovery
after durable tail, and successful first MATCH on a fresh
readiness-first table. It did not reproduce a persistent stale cache or
prove the historical failure's exact cache state; no diagnostic eviction
is included in the patch.

Additional local validation: complete lockservice/embed packages in
normal and race modes; final changed lock cases in normal/race with ten
bounded repetitions; three focused readiness-root race repetitions; two
expected-failure controls rejecting premature errors and ignored caller
contexts; incremental formatting/vet/molint/lint. The `gpt-6.1-sol` /
`xhigh` review's cleanup finding was corrected and re-reviewed.

The old UT run also exhausted the outer 60-minute wrapper before
plan/report completion. These focused corrections do not establish a
whole-CI runtime improvement. PROXY's check annotation reports that its
hosted runner lost communication; its absent coverage is a consequence
of that interruption. New-head remote CI remains pending.

This branch was previously deployed

1 inactive deployment
ci — 16056d03 Deployed Oct 19, 2026 by cpegeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants