Skip to content

fix(memory): download ONNX Runtime from NuGet when GitHub returns 404 - #38

Open
MasterErik wants to merge 1 commit into
codegraph-ai:mainfrom
MasterErik:fix/onnxruntime-nuget-fallback
Open

MasterErik wants to merge 1 commit into
codegraph-ai:mainfrom
MasterErik:fix/onnxruntime-nuget-fallback

Conversation

@MasterErik

Copy link
Copy Markdown

Summary

Windows builds cannot start the ONNX embedding models. microsoft/onnxruntime was
removed from GitHub in mid-November 2026, so the release URL baked into
ensure_ort_dll() now returns 404:

VectorEngine initialization failed: Model("Failed to download ONNX Runtime:
https://github.com/microsoft/onnxruntime/releases/download/v1.20.0/onnxruntime-win-x64-1.20.0.zip:
status code 404")

The vector engine dies in MemoryManager::initialize, so symbol_search silently
degrades to name matching while embedding_status still reports "Embeddings are
building in the background" — a message that is never true. Structural tools keep
working, which makes the failure easy to miss.

This change adds a NuGet fallback: when the GitHub download fails for any reason,
the same ORT_VERSION is fetched from Microsoft.ML.OnnxRuntime and
runtimes/win-x64/native/onnxruntime.dll is extracted into the existing cache path.

Motivation

Semantic search is the main reason to run the engine, and on Windows it is dead
until someone places onnxruntime.dll by hand. Every Windows user who enables
bge-small (the default), jina-code-v2 or granite-97m hits this. NuGet still
serves the identical binaries and is the fallback other projects adopted after the
repository was removed.

Changes

  • ensure_ort_dll() keeps the GitHub release zip as the primary source and retries
    from https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/{ORT_VERSION}/microsoft.ml.onnxruntime.{ORT_VERSION}.nupkg
    on failure, logging the GitHub error at warn level instead of aborting.
  • Extraction is split into extract_member_from_zip(), so member lookup and the
    error text are testable without network access; extract_zip_member() keeps the
    download and temp-file cleanup.
  • Two unit tests (Windows-only, matching the code path):
    • extracts_the_requested_member_only — builds a small archive, extracts one
      member, asserts the bytes and that the other entry is ignored;
    • missing_member_is_an_error — asserts the diagnostic for a missing member.
  • CHANGELOG.md: entry under [Unreleased].

No new dependencies: ureq and zip are already dependencies of this crate on
Windows. Everything is inside #[cfg(target_os = "windows")], so macOS and Linux
builds are unaffected.

Why the same version, and why NuGet

The NuGet package carries the same binaries that used to ship in the GitHub release
archive. Reusing ORT_VERSION for both sources keeps the DLL in lockstep with the
ort crate version pinned by fastembed — mixing ONNX Runtime versions is a much
worse failure mode than a 404. A DLL already present next to the executable or in
~/.codegraph/fastembed_cache/ort/ is still preferred, so working installs are not
touched.

Testing

Verified on Windows 11, x86_64-pc-windows-msvc, rustc 1.94.1 (the repo toolchain):

  • rustfmt --check on the touched file — clean.
  • cargo clippy -p codegraph-memory --all-targets — no warnings from the changed
    code (the two reported lints are pre-existing, in src/docs.rs).
  • cargo build --release -p codegraph-server — succeeds.
  • End-to-end with the ORT cache emptied, so the fallback had to run: the server
    downloaded the nupkg itself, extracted onnxruntime.dll
    (11,567,648 bytes, sha256 52f8ebe8f08f369a44fed6d1cb680c7c89169795e1c2949ee25b88b538ef0948),
    logged Saved 714 symbol vectors … model=BGE-Small-EN-v1.5 (384d, 512-tok context),
    and symbol_search answered match_reason: "Semantic" (11 ms).
  • MCP session against the rebuilt binary: initialize + tools/list 0.93 s, 42
    tools listed.

Caveat, stated openly: cargo test -p codegraph-memory --lib cannot LINK on this
machine — LNK2005: … already defined in libcpmt.lib (static/dynamic CRT mix in
the memory crate's test binary). The same failure reproduces on the unmodified
tree (git stash → same error), so it is a pre-existing MSVC environment issue,
not a regression from this change. The new tests are therefore expected to run in
CI rather than locally.

CodeGraph PR review (self-check)

Generated with the repository's own tooling (--graph-only --run-tool codegraph_pr_context):

## 🔍 CodeGraph PR Review

2 files changed (+133/−24, 0 functions) · Risk: low

### Suggested reviewers
anvanster (2 lines), er.ivanov (2 lines)

Reading that honestly: the "0 functions" and "0 tests cover the changes" lines are
limitations of the graph diff — the changed functions are ensure_ort_dll() and the
new extract_member_from_zip(), and the change does add tests. Risk is rated low
because the edit is confined to one Windows-only code path.

Notes for the maintainer

  • Happy to flip the order (NuGet first, GitHub as fallback) — NuGet is the source
    that is still maintained; GitHub first keeps the upstream archive authoritative if
    it ever comes back.
  • If you would rather verify the nupkg checksum before extraction, say so and I will
    pin it.
  • No version bump: ORT_VERSION is unchanged, so stored vectors stay valid.

microsoft/onnxruntime was removed from GitHub in November 2026, so the release
URL baked into ensure_ort_dll() returns 404 and the ONNX embedding models
(bge-small, jina-code-v2, granite-97m) cannot start: VectorEngine
initialization fails in MemoryManager::initialize and semantic search silently
degrades to name matching while embedding_status still claims the embeddings
are "building in the background".

Keep the GitHub release zip as the primary source, and retry the same
ORT_VERSION from the Microsoft.ML.OnnxRuntime nupkg, extracting
runtimes/win-x64/native/onnxruntime.dll into the existing cache path.
Extraction is split into extract_member_from_zip() so member lookup and its
diagnostic can be tested without network access; two unit tests cover the
extraction and the missing-member case. CHANGELOG gets an [Unreleased] entry.

Verified on Windows 11 x64 with the cache emptied: the server downloaded the
nupkg itself, cached onnxruntime.dll (11,567,648 bytes, sha256
52f8ebe8f08f369a44fed6d1cb680c7c89169795e1c2949ee25b88b538ef0948), then
reported "Saved 714 symbol vectors ... model=BGE-Small-EN-v1.5 (384d,
512-tok context)" and symbol_search answered match_reason "Semantic".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant