Skip to content

[Store] Fix with_hard_pin failure in python API#1873

Merged
stmatengss merged 4 commits intokvcache-ai:mainfrom
0oshowero0:fix_hard_pin_python
Apr 12, 2026
Merged

[Store] Fix with_hard_pin failure in python API#1873
stmatengss merged 4 commits intokvcache-ai:mainfrom
0oshowero0:fix_hard_pin_python

Conversation

@0oshowero0
Copy link
Copy Markdown
Contributor

@0oshowero0 0oshowero0 commented Apr 12, 2026

Description

While PR #1728 introduced the with_hard_pin capability to the C++ core, the corresponding Python interface was missing.

Currently, attempting to configure with_hard_pin via the Python API results in the following error:

from mooncake.store import ReplicateConfig
config = ReplicateConfig()
config.with_hard_pin = True
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'mooncake.store.ReplicateConfig' object has no attribute 'with_hard_pin'

Root Cause & Solution:

The with_hard_pin attribute was not registered in the pybind11 module (store_py.cpp). This PR fixes the issue by explicitly exposing with_hard_pin via pybind11, aligning the Python API with the underlying C++ ReplicateConfig struct.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Other

How Has This Been Tested?

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • I have updated the documentation.
  • I have added tests to prove my changes are effective.

Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>

fix

Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
@0oshowero0 0oshowero0 requested a review from ykwd as a code owner April 12, 2026 08:37
Copilot AI review requested due to automatic review settings April 12, 2026 08:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns the Mooncake Store client-facing APIs with the C++ core’s ReplicateConfig.with_hard_pin capability by exposing the flag in bindings.

Changes:

  • Expose ReplicateConfig.with_hard_pin in the Python pybind11 module.
  • Extend the C API replicate config (mooncake_replicate_config_t) and map it into the C++ ReplicateConfig.

Reviewed changes

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

File Description
mooncake-store/src/store_c.cpp Maps the C replicate config into the C++ ReplicateConfig, including with_hard_pin.
mooncake-store/include/store_c.h Adds with_hard_pin to the public C API replicate config struct.
mooncake-integration/store/store_py.cpp Exposes with_hard_pin to Python via pybind11.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 27 to 31
struct mooncake_replicate_config {
size_t replica_num;
int with_soft_pin;
int with_hard_pin;
const char **preferred_segments;
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

Adding with_hard_pin into mooncake_replicate_config changes the struct layout/size for the public C API. Existing callers compiled against the old header will pass a smaller/differently-laid-out struct, and the library will misinterpret preferred_segments as with_hard_pin (and shift the remaining fields), which can cause UB or unintended hard-pinning. Consider introducing a versioned config struct (e.g., mooncake_replicate_config_v2 + new entrypoints) or adding an explicit struct_size/version field so the callee can detect whether with_hard_pin is present; also update downstream language bindings that construct this struct by field name (e.g., the Rust wrapper currently uses a struct literal).

Copilot uses AI. Check for mistakes.
Comment on lines 46 to 49
config.replica_num = c_config->replica_num;
config.with_soft_pin = c_config->with_soft_pin != 0;
config.with_hard_pin = c_config->with_hard_pin != 0;
if (c_config->preferred_segments &&
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

to_replicate_config() now unconditionally reads c_config->with_hard_pin. With the current C API change, any caller compiled against an older store_c.h (without the new field / different layout) can trigger incorrect reads (e.g., interpreting preferred_segments as the flag) and potentially crash or silently enable hard pinning. If backward compatibility is required, the C API needs a way to communicate the config struct version/size before this field is read.

Copilot uses AI. Check for mistakes.
Comment on lines 1398 to 1401
.def_readwrite("replica_num", &ReplicateConfig::replica_num)
.def_readwrite("with_soft_pin", &ReplicateConfig::with_soft_pin)
.def_readwrite("with_hard_pin", &ReplicateConfig::with_hard_pin)
.def_readwrite("preferred_segments",
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

The new Python-exposed with_hard_pin flag should be covered by the existing Python wheel tests that validate ReplicateConfig property access (e.g., default value and assignment), otherwise this regression can reappear unnoticed.

Copilot uses AI. Check for mistakes.
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 new configuration option "with_hard_pin" to the ReplicateConfig structure. The changes include updating the C header definition, the conversion logic in the C++ implementation, and exposing the field via Python bindings. I have no feedback to provide.

Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mooncake-integration/store/store_py.cpp 0.00% 1 Missing ⚠️
mooncake-store/src/store_c.cpp 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@stmatengss
Copy link
Copy Markdown
Collaborator

LGTM

@stmatengss stmatengss merged commit d3ace8f into kvcache-ai:main Apr 12, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants