Skip to content

Auto-load the native runtime for SDK/embedded serving on startup - #1018

Closed
michaelneale wants to merge 1 commit into
mainfrom
fix/sdk-embedded-native-runtime-bootstrap
Closed

Auto-load the native runtime for SDK/embedded serving on startup#1018
michaelneale wants to merge 1 commit into
mainfrom
fix/sdk-embedded-native-runtime-bootstrap

Conversation

@michaelneale

@michaelneale michaelneale commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

What you can now do

If you embed MeshLLM as a library (mesh-llm-sdk with the serving feature —
start_embedded_node / start_embedded_serve / MeshNode), the correct native
runtime is now loaded — and auto-installed if missing — automatically when the
embedded node starts. When you bump your mesh-llm-sdk dependency to a new
version, the matching upgraded native runtime is fetched and loaded on the next
start, just like it already is for the shipped mesh-llm binary. You no longer
have to call install_native_runtime() yourself before serving.

The problem

Native runtimes are release artifacts selected by exact Skippy ABI +
platform/backend, and the compiled-in release version drives the versioned
release-manifest URL and cache layout. The bootstrap that makes upgrades "just
work" (initialize_host_runtime_with_config) loads a compatible cached runtime
or does a one-shot auto-install of the right one.

The shipped binary runs that bootstrap before serving. The SDK/embedded serving
path (start_embedded_noderun_embedded_runtimerun_runtime_cli) never
did — it only reset tracing and the shutdown flag. So an app that upgraded its
mesh-llm-sdk dependency linked a new Skippy ABI / release version but never
loaded or auto-installed the matching runtime, and serving failed later at the
Skippy FFI load unless the app manually installed the runtime first (as the SDK
README documented).

Fixes #1016.

Change

run_embedded_runtime now runs the same initialize_host_runtime_with_config
bootstrap as the binary before serving, deriving the config path from the
embedded options so a configured [runtime.native_runtime] override still
applies. The call is routed through a small injectable seam
(bootstrap_embedded_native_runtime) so behavior can be unit-tested without
standing up a full runtime.

Validation

  • cargo fmt --all --check — clean
  • cargo clippy -p mesh-llm-host-runtime --all-targets -- -D warnings — clean
  • cargo clippy -p mesh-llm --all-targets -- -D warnings — clean
  • cargo test -p mesh-llm-host-runtime --lib embedded_native_runtime_bootstrap — 3 new tests pass
    • forwards the embedded config path to the initializer
    • forwards an absent config path
    • propagates initializer failure (embedded serving fails startup instead of failing later at FFI load)

Summary by CodeRabbit

  • Bug Fixes
    • Embedded and SDK serving now correctly initialize the configured native runtime before startup.
    • Runtime configuration overrides are consistently honored during embedded startup.
    • Startup failures from native runtime initialization are surfaced correctly.

Embedded/SDK serving (mesh-llm-sdk "serving" feature, start_embedded_node/
start_embedded_serve) went through run_embedded_runtime, which never ran the
native-runtime bootstrap that the shipped binary runs before serving. As a
result, an application that upgraded its mesh-llm-sdk dependency linked a new
Skippy ABI / release version but never loaded or auto-installed the matching
native runtime, so serving failed later at the Skippy FFI load unless the app
manually called install_native_runtime() first.

run_embedded_runtime now performs the same initialize_host_runtime_with_config
bootstrap as the binary, honoring the embedded config so a configured
[runtime.native_runtime] override still applies. The call is routed through a
small injectable seam (bootstrap_embedded_native_runtime) so the config-path
and failure-propagation contract is covered by unit tests.

Fixes #1016
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The embedded serving path now bootstraps the native runtime before invoking run_runtime_cli, forwarding any configured path. Tests cover configured and absent paths, plus initializer failure propagation.

Changes

Embedded runtime startup

Layer / File(s) Summary
Bootstrap before embedded serving
crates/mesh-llm-host-runtime/src/runtime/mod.rs
run_embedded_runtime invokes a config-aware native-runtime bootstrap before continuing to run_runtime_cli.
Bootstrap input and error tests
crates/mesh-llm-host-runtime/src/runtime/mod.rs
Test helpers and Tokio tests verify config-path forwarding and propagation of initializer failures.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Mesh-LLM/mesh-llm#869: Both changes modify native-runtime initialization ordering and async startup behavior.

Suggested reviewers: ndizazzo, i386

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: auto-loading the native runtime during SDK/embedded serving startup.
Linked Issues check ✅ Passed The change fulfills #1016 by bootstrapping host runtime before embedded serving, honoring config overrides, and failing startup on bootstrap errors.
Out of Scope Changes check ✅ Passed The diff stays focused on embedded runtime bootstrap behavior and its tests, with no obvious unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sdk-embedded-native-runtime-bootstrap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/mesh-llm-host-runtime/src/runtime/mod.rs`:
- Around line 3585-3601: Extract bootstrap_embedded_native_runtime and its
associated embedded-runtime tests from the runtime module into a dedicated
embedded module, such as embedded.rs, and expose or import the symbols needed by
the existing callers. Preserve the current initializer injection, config_path
propagation, behavior, and test coverage while reducing the oversized runtime
file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 47c72b48-d30b-4379-90c5-9e193a914017

📥 Commits

Reviewing files that changed from the base of the PR and between b84dd14 and 2388cee.

📒 Files selected for processing (1)
  • crates/mesh-llm-host-runtime/src/runtime/mod.rs

Comment on lines +3585 to +3601
/// Run the native-runtime bootstrap for the embedded/SDK serving path, deriving
/// the config path from the embedded options so a configured
/// `[runtime.native_runtime]` override is honored.
///
/// The initializer is injected so the ordering/config-path contract can be
/// exercised in tests without standing up a full runtime.
async fn bootstrap_embedded_native_runtime<Init, Fut>(
options: &EmbeddedRuntimeOptions,
initialize: Init,
) -> Result<()>
where
Init: FnOnce(Option<PathBuf>) -> Fut,
Fut: std::future::Future<Output = Result<()>>,
{
initialize(options.config_path.clone()).await
}

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.

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Extract this logic into a new module to comply with file size limits.

As per coding guidelines, "Do not add Rust source files over 2,000 lines. If a file is approaching that size, split it by responsibility into an owning module instead of adding more code to the oversized file." This file is currently over 3,800 lines.

Please extract this embedded runtime logic and its associated tests into a separate module (e.g., crates/mesh-llm-host-runtime/src/runtime/embedded.rs) to prevent this file from growing further.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/mesh-llm-host-runtime/src/runtime/mod.rs` around lines 3585 - 3601,
Extract bootstrap_embedded_native_runtime and its associated embedded-runtime
tests from the runtime module into a dedicated embedded module, such as
embedded.rs, and expose or import the symbols needed by the existing callers.
Preserve the current initializer injection, config_path propagation, behavior,
and test coverage while reducing the oversized runtime file.

Source: Coding guidelines

@michaelneale

Copy link
Copy Markdown
Collaborator Author

Closing. On review this isn't needed: real SDK consumers (e.g. buzz) already handle upgrades correctly by checking the cache for a runtime matching CURRENT_MESH_VERSION and failing with a clear message + explicit install step. The original auto-download-on-startup approach was wrong (a library shouldn't do implicit network I/O on startup), and the revised deny-by-default variant is only a minor DX nicety, not a fix for any real breakage. Not worth the config-schema addition and cross-crate plumbing.

@michaelneale
michaelneale deleted the fix/sdk-embedded-native-runtime-bootstrap branch July 17, 2026 15:40
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.

SDK docs: document native-runtime version-check pattern; clearer error on embedded serve

1 participant