[HiCache] fix: resolve Mooncake local_hostname per node for runtime attach (#29668)

Co-authored-by: Teng Ma <11641725+stmatengss@users.noreply.github.com>
This commit is contained in:
Teng Ma
2026-09-17 15:51:21 +08:00
committed by GitHub
co-authored by Teng Ma
parent aebae58b8c
commit 15b256bdb0
3 changed files with 148 additions and 17 deletions
@@ -196,6 +196,10 @@ Mooncake loads configuration in the following priority order:
2. If not, Mooncake checks whether the environment variable `DEFAULT_MOONCAKE_CONFIG_PATH_ENV` is set, and loads the JSON config file from that path.
3. If neither of the above is provided, Mooncake falls back to environment variables.
For multi-node deployments that attach Mooncake at runtime via `PUT /hicache/storage-backend`, omit `local_hostname` from the attach payload and set `MOONCAKE_LOCAL_HOSTNAME` (or `LOCAL_HOSTNAME`) per node before launching SGLang. Each rank resolves `local_hostname` from its own process environment instead of a shared default.
When loading from a JSON config file, `local_hostname` follows the same per-process precedence: `MOONCAKE_LOCAL_HOSTNAME`, then `LOCAL_HOSTNAME`, then the value in the JSON file, then `"localhost"`.
**Using extra-config of sglang arguments to configure Mooncake**
```bash
@@ -106,6 +106,25 @@ class MooncakeStoreConfig:
ssd_offload_path: Optional[str] = None
tenant_id: str = DEFAULT_TENANT_ID
@staticmethod
def _resolve_local_hostname(overrides: Optional[dict] = None) -> str:
"""Resolve local_hostname for the current process.
Process environment takes precedence over config overrides so multi-node
runtime attach can broadcast shared extra_config while each node uses its
own MOONCAKE_LOCAL_HOSTNAME / LOCAL_HOSTNAME.
"""
if envs.MOONCAKE_LOCAL_HOSTNAME.is_set():
return envs.MOONCAKE_LOCAL_HOSTNAME.get()
local_hostname = os.getenv("LOCAL_HOSTNAME")
if local_hostname:
return local_hostname
if overrides is not None:
value = overrides.get("local_hostname")
if value:
return value
return envs.MOONCAKE_LOCAL_HOSTNAME.default
@staticmethod
def from_file() -> "MooncakeStoreConfig":
"""Load the config from a JSON file."""
@@ -129,9 +148,7 @@ class MooncakeStoreConfig:
)
return MooncakeStoreConfig(
local_hostname=config.get(
"local_hostname", envs.MOONCAKE_LOCAL_HOSTNAME.default
),
local_hostname=MooncakeStoreConfig._resolve_local_hostname(config),
metadata_server=config.get(
"metadata_server", envs.MOONCAKE_TE_META_DATA_SERVER.default
),
@@ -180,18 +197,8 @@ class MooncakeStoreConfig:
"Either the environment variable 'MOONCAKE_MASTER' or 'MOONCAKE_CLIENT' is not set."
)
# Special handling for local_hostname: try MOONCAKE_LOCAL_HOSTNAME first,
# then fall back to LOCAL_HOSTNAME if not set.
# This is for forward compatibility with the legacy LOCAL_HOSTNAME environment variable.
if envs.MOONCAKE_LOCAL_HOSTNAME.is_set():
local_hostname = envs.MOONCAKE_LOCAL_HOSTNAME.get()
else:
local_hostname = os.getenv(
"LOCAL_HOSTNAME", envs.MOONCAKE_LOCAL_HOSTNAME.default
)
return MooncakeStoreConfig(
local_hostname=local_hostname,
local_hostname=MooncakeStoreConfig._resolve_local_hostname(),
metadata_server=envs.MOONCAKE_TE_META_DATA_SERVER.get(),
global_segment_size=_parse_global_segment_size(
envs.MOONCAKE_GLOBAL_SEGMENT_SIZE.get()
@@ -220,9 +227,7 @@ class MooncakeStoreConfig:
)
return MooncakeStoreConfig(
local_hostname=extra_config.get(
"local_hostname", envs.MOONCAKE_LOCAL_HOSTNAME.default
),
local_hostname=MooncakeStoreConfig._resolve_local_hostname(extra_config),
metadata_server=extra_config.get(
"metadata_server", envs.MOONCAKE_TE_META_DATA_SERVER.default
),