Skip to content

fix(android cpp): Versioned GenAI Android AAR cache to avoid old cache - #960

Open
sheetalarkadam wants to merge 3 commits into
mainfrom
fix/genai-aar-cache-staleness
Open

fix(android cpp): Versioned GenAI Android AAR cache to avoid old cache#960
sheetalarkadam wants to merge 3 commits into
mainfrom
fix/genai-aar-cache-staleness

Conversation

@sheetalarkadam

@sheetalarkadam sheetalarkadam commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Produce a build that silently disagrees with the pinned version if old file is present

  • Scope both the archive and the extracted tree by version, so a bump fetches its own copy and cannot collide.
  • Newer version need to target libmat.so

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview Aug 11, 2026 4:30am

Request Review

@sheetalarkadam
sheetalarkadam force-pushed the fix/genai-aar-cache-staleness branch from 8f2547f to 83396a9 Compare August 7, 2026 20:52
@sheetalarkadam
sheetalarkadam force-pushed the fix/genai-aar-cache-staleness branch from 83396a9 to 4ee100b Compare August 10, 2026 18:04
@sheetalarkadam
sheetalarkadam force-pushed the fix/genai-aar-cache-staleness branch from 4ee100b to caf8783 Compare August 10, 2026 19:43
@sheetalarkadam
sheetalarkadam force-pushed the fix/genai-aar-cache-staleness branch from caf8783 to b126b31 Compare August 10, 2026 19:44
@sheetalarkadam sheetalarkadam changed the title fix(cpp): scope the GenAI Android AAR cache by version and never cache a failed download fix(android cpp): Versioned GenAI Android AAR cache to avoid old cache Aug 10, 2026
@sheetalarkadam
sheetalarkadam requested a balanced review from Copilot August 10, 2026 20:16

Copilot AI 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.

Pull request overview

Versions Android GenAI AAR caches and includes the required libmat.so runtime dependency.

Changes:

  • Scopes downloaded and extracted AARs by GenAI version.
  • Uses temporary files for safer downloads.
  • Copies libmat.so into build outputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
sdk_v2/cpp/CMakeLists.txt Copies the GenAI libmat.so dependency.
sdk_v2/cpp/cmake/FindOnnxRuntimeGenAI.cmake Adds versioned Android AAR caching and download handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sdk_v2/cpp/cmake/FindOnnxRuntimeGenAI.cmake
Comment thread sdk_v2/cpp/cmake/FindOnnxRuntimeGenAI.cmake Outdated
sheetalarkadam and others added 3 commits August 10, 2026 21:30
GenAI 0.15.0 split most of libonnxruntime-genai.so's implementation into a
separate libmat.so (31 MB arm64 / 30 MB x86_64), and the former now lists it
as a DT_NEEDED:

    libonnxruntime-genai.so -> NEEDED libmat.so

The POST_BUILD copy only ever staged libonnxruntime-genai.so, so an Android
build produced a bin/ that cannot be loaded: libfoundry_local.so resolves
libonnxruntime-genai.so, which then fails on the missing libmat.so.

This is Android-only. GenAI ships Android as a GitHub Releases AAR, and only
that artifact is split; the Microsoft.ML.OnnxRuntimeGenAI.Foundry NuGet
package used by Windows/Linux/macOS is still monolithic and contains no
libmat at all. The copy is therefore guarded on file existence rather than on
ANDROID, which also leaves 0.14.x builds (single monolithic library, no such
dependency) working unchanged.

The Android CI staging step is updated to match, so the published artifact is
a self-contained set.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 24ef037b-246f-4fea-a1a3-4fae5223cb0c
Two independent caching defects in the Android AAR path, both of which
produce a build that silently disagrees with the pinned version.

Stale reuse: the archive was stored as onnxruntime-genai-android.aar and
extracted to a single genai-android-aar/ directory, neither of which
included the version. Both steps are guarded by EXISTS, so bumping
ORT_GENAI_VERSION reused whichever AAR had been downloaded first while
logging the new version. A warm build directory therefore produced binaries
from the old release. CI never saw this because every run starts from a
fresh binary directory; developers hit it on every bump. Scoping both the
archive and the extracted tree by version makes a bump fetch its own copy.

Poisoned entry: file(DOWNLOAD) writes its destination even when the transfer
fails. An unpublished release returns HTTP 404, which yields status 22 and a
0-byte file. The FATAL_ERROR left that file in place, so the next configure
saw EXISTS, skipped the download, and failed inside ARCHIVE_EXTRACT instead
- permanently, until it was deleted by hand. Downloading to a temporary path
and renaming only on success means a failed fetch leaves no cache entry.

The error message now names the version and URL and points at the likely
cause, since a missing Android AAR on an otherwise healthy release is the
common failure.

Verified: 404 leaves no cache entry and retries cleanly; 0.15.0 downloads,
hits cache on re-run, and does not collide with 0.14.0; a clean Android
arm64 build against the GitHub AAR links with a complete DT_NEEDED closure.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 24ef037b-246f-4fea-a1a3-4fae5223cb0c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 93a7e930-97d3-4c68-832e-c449f3768cab
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.

2 participants