Skip to content

feat: Implement Rust-based Native Remote Backend for High-Performance I/O#2607

Draft
maobaolong wants to merge 2 commits intoLMCache:devfrom
maobaolong:remote_backend_rust
Draft

feat: Implement Rust-based Native Remote Backend for High-Performance I/O#2607
maobaolong wants to merge 2 commits intoLMCache:devfrom
maobaolong:remote_backend_rust

Conversation

@maobaolong
Copy link
Copy Markdown
Collaborator

@maobaolong maobaolong commented Feb 16, 2026

What this PR does / why we need it

This PR introduces an experimental native remote backend for LMCache, implemented in Rust, designed to significantly reduce Python GIL contention during I/O operations and provide a modular architecture for integrating diverse storage solutions.

Key Features:

  • Native Rust Backend: Leverages Rust for performance-critical I/O operations with minimal Python GIL overhead
  • C ABI Connector Interface: Enables seamless integration of native shared libraries (C, C++, Rust) as storage backends
  • Reference Filesystem Connector: Includes a fully functional filesystem-based storage connector as reference implementation
  • PyO3 Integration: Provides Python bindings for transparent interoperability with existing LMCache infrastructure

If applicable

  • this PR contains user facing changes - docs added
  • this PR contains unit tests

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @maobaolong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new, experimental native remote backend for LMCache, leveraging Rust for performance-critical I/O operations. By allowing direct interaction with native shared libraries through a C ABI, it significantly reduces Python GIL contention during data transfers and offers a modular approach for integrating diverse storage solutions. The changes include the core Rust backend, a reference filesystem connector, Python bindings, updated documentation, and necessary development tooling.

Highlights

  • New Rust Remote Backend: Introduced an experimental RustRemoteBackend storage plugin, enabling LMCache to delegate I/O operations to native shared libraries (C, C++, Rust) via a C ABI. This aims to reduce Python GIL overhead and support flexible, plugin-style connector deployments.
  • Built-in Filesystem Connector: Provided a reference filesystem connector (lmcache_connector_fs) implemented in Rust, demonstrating how to build native connectors that adhere to the defined C ABI.
  • Python Integration with PyO3: Developed a Python wrapper (lmcache_rust_remote_backend_io) using PyO3 to seamlessly integrate the Rust backend, handling dynamic loading of native connectors, metadata management, and GIL-released I/O calls.
  • Developer Documentation: Added comprehensive documentation for the Native Remote Backend, detailing its architecture, the C ABI for connectors, steps for writing custom connectors, configuration, prerequisites, and current limitations.
  • Pre-commit Hooks and Tests: Integrated new pre-commit hooks for Rust formatting and clippy checks, and added unit tests to validate the functionality of the RustRemoteBackend and its interaction with the native filesystem connector.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .pre-commit-config.yaml
    • Added pre-commit hooks for Rust formatting and clippy checks for the new remote_backend and connector_fs modules.
  • docs/source/developer_guide/extending_lmcache/index.rst
    • Updated the developer guide to include a reference to the new native_remote_backend documentation.
  • docs/source/developer_guide/extending_lmcache/native_remote_backend.rst
    • Added new documentation outlining the Native Remote Backend, its architecture, C ABI, custom connector development, configuration, and limitations.
  • lmcache/v1/storage_backend/plugins/rust_remote_backend.py
    • Added the RustRemoteBackend Python class, implementing the StoragePluginInterface to interact with the native Rust extension.
    • Implemented logic for loading native connectors, managing metadata, and orchestrating asynchronous I/O operations.
  • rust/connector_fs/Cargo.toml
    • Added the Cargo manifest for the lmcache_connector_fs Rust crate, configured as a cdylib.
  • rust/connector_fs/src/lib.rs
    • Added the Rust source code for the lmcache_connector_fs filesystem connector, implementing the C ABI for file operations (create, destroy, exists, put, get, remove, file_size, list_keys).
    • Included support for O_DIRECT and atomic rename for crash-safety.
  • rust/remote_backend/Cargo.toml
    • Added the Cargo manifest for the lmcache_rust_remote_backend_io Rust crate, configured as a cdylib with pyo3 dependencies.
  • rust/remote_backend/include/connector_api.h
    • Added the C header file defining the standard C ABI for LMCache remote connectors.
  • rust/remote_backend/pyproject.toml
    • Added the pyproject.toml file for the lmcache_rust_remote_backend_io Python package, configuring maturin for building the PyO3 extension.
  • rust/remote_backend/src/lib.rs
    • Added the Rust source code for the lmcache_rust_remote_backend_io PyO3 extension, handling dynamic loading of native connectors and exposing Python-callable I/O functions.
    • Implemented internal state management for metadata indexing and put-task deduplication, with GIL-released native calls.
  • tests/v1/storage_backend/test_rust_remote_backend.py
    • Added unit tests for the RustRemoteBackend, verifying put/get roundtrips, contains, remove, and multiple key operations.
Activity
  • A new RustRemoteBackend has been introduced, providing a native, GIL-free path for storage I/O.
  • A built-in filesystem connector in Rust (lmcache_connector_fs) was added as a reference implementation.
  • Python bindings via PyO3 (lmcache_rust_remote_backend_io) were created to bridge Python with the native Rust backend.
  • Comprehensive documentation for the new native remote backend has been added to the developer guide.
  • Pre-commit hooks were updated to include formatting and linting for the new Rust code.
  • Unit tests were added to ensure the correctness and functionality of the new Rust remote backend.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@maobaolong maobaolong changed the title Introduce rust remote backend Introduce rust remote backendfeat: Implement Rust-based Native Remote Backend for High-Performance I/O Feb 16, 2026
@maobaolong maobaolong changed the title Introduce rust remote backendfeat: Implement Rust-based Native Remote Backend for High-Performance I/O feat: Implement Rust-based Native Remote Backend for High-Performance I/O Feb 16, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant new feature: a Rust-based remote backend, designed to offload I/O to native code for improved performance by avoiding the Python GIL. However, it introduces critical security risks due to arbitrary library loading from configuration-defined paths and potential path traversal vulnerabilities in the built-in filesystem connector from a lack of proper path validation. These security concerns require immediate attention through strict validation of library paths and configuration parameters. Furthermore, the review identified areas for improvement in resource management, requiring an explicit close method for deterministic cleanup, enhanced API and documentation clarity for the connector C ABI and its thread-safety, and robustness improvements in the Python wrapper against mismatched inputs.

Comment thread lmcache/v1/storage_backend/plugins/rust_remote_backend.py
Comment thread rust/connector_fs/src/lib.rs
Comment thread docs/source/developer_guide/extending_lmcache/native_remote_backend.rst Outdated
Comment thread rust/remote_backend/src/lib.rs
Comment thread lmcache/v1/storage_backend/plugins/rust_remote_backend.py Outdated
Comment thread rust/remote_backend/include/connector_api.h Outdated
Fix security and code quality issues:

1. Security: Add connector library path validation to prevent arbitrary library loading
   - Check for path traversal sequences
   - Verify file exists and is a regular file
   - Ensure paths are properly resolved

2. Security: Add path validation in FsConnector to prevent path traversal attacks
   - Validate base_path and tmp_subdir for '..' sequences
   - Use proper path sanitization

3. Documentation: Clarify thread-safety requirement for connectors
   - Update docs to explicitly state connectors must be thread-safe
   - Remove misleading 'recommended but not required' language

4. Resource management: Improve connector lifecycle with Arc
   - Use Arc<ConnectorHandle> for thread-safe shared ownership
   - Connector is automatically cleaned up when all references drop
   - close() method maintained for API compatibility

5. Code robustness: Change zip strict parameter to True
   - Catch mismatched keys/objs lists early

6. API clarity: Improve connector_list_keys documentation
   - Clarify that keys are newline-separated, not NUL-terminated

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
@maobaolong maobaolong marked this pull request as draft February 17, 2026 04:14
@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had activity within 60 days. It will be automatically closed if no further activity occurs within 30 days.

@github-actions github-actions Bot added the stale label Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant