[Core] Make prefix-cache NONE_HASH deterministic by default (#51875)

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Russell Bryant
2026-08-18 23:14:39 +00:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 8f4a7f45c5
commit ef47a897e2
10 changed files with 204 additions and 77 deletions
+35 -16
View File
@@ -15,6 +15,8 @@ from types import SimpleNamespace
import numpy as np
import pytest
from vllm.utils.hashing import sha256
from vllm.v1.core.kv_cache_utils import DEFAULT_NONE_HASH_SEED, init_none_hash
from vllm.v1.kv_offload.base import LookupResult, ReqContext, ScheduleEndContext
from vllm.v1.kv_offload.tiering.base import JobResult, TransferJob
from vllm.v1.kv_offload.tiering.p2p import manager as manager_module
@@ -123,23 +125,12 @@ def _init_offloading_spec() -> SimpleNamespace:
# ---------------------------------------------------------------------------
# Tests for __init__ PYTHONHASHSEED assertion
# Tests for __init__ hash seed resolution
# ---------------------------------------------------------------------------
class TestInitHashSeedAssertion:
def test_missing_pythonhashseed_raises(self, monkeypatch):
"""P2P instance refuses to start when PYTHONHASHSEED is unset."""
monkeypatch.delenv("PYTHONHASHSEED", raising=False)
with pytest.raises(ValueError, match="PYTHONHASHSEED"):
P2PSecondaryTierManager(
offloading_spec=_init_offloading_spec(),
primary_kv_view=memoryview(bytearray(16)),
)
def test_pythonhashseed_set_succeeds(self, monkeypatch):
"""With PYTHONHASHSEED set, __init__ records it for the handshake."""
monkeypatch.setenv("PYTHONHASHSEED", "12345")
class TestInitHashSeed:
def _build(self, monkeypatch) -> P2PSecondaryTierManager:
monkeypatch.setattr(manager_module, "NixlTransport", lambda *a, **k: object())
monkeypatch.setattr(manager_module, "ZmqTransport", lambda *a, **k: object())
monkeypatch.setattr(
@@ -147,11 +138,39 @@ class TestInitHashSeedAssertion:
"from_offloading_spec",
lambda **k: SimpleNamespace(get_run_config=lambda: {}),
)
mgr = P2PSecondaryTierManager(
return P2PSecondaryTierManager(
offloading_spec=_init_offloading_spec(),
primary_kv_view=memoryview(bytearray(16)),
)
assert mgr._hash_seed == "12345"
def test_missing_pythonhashseed_uses_default(self, monkeypatch):
"""P2P falls back to the deterministic default seed when unset."""
monkeypatch.delenv("PYTHONHASHSEED", raising=False)
mgr = self._build(monkeypatch)
init_none_hash(sha256)
assert mgr._get_hash_seed() == DEFAULT_NONE_HASH_SEED
def test_pythonhashseed_set_succeeds(self, monkeypatch):
"""With PYTHONHASHSEED set, the handshake advertises it."""
monkeypatch.setenv("PYTHONHASHSEED", "12345")
mgr = self._build(monkeypatch)
init_none_hash(sha256)
assert mgr._get_hash_seed() == "12345"
def test_seed_resolved_after_init_none_hash(self, monkeypatch):
"""The seed is read lazily, not at construction time.
This tier is built before init_none_hash runs, and a non-cryptographic
hash algorithm seeds NONE_HASH randomly, so resolving in __init__ would
advertise a value that does not match the NONE_HASH actually in use.
"""
monkeypatch.delenv("PYTHONHASHSEED", raising=False)
mgr = self._build(monkeypatch)
assert mgr._hash_seed is None
monkeypatch.setattr(
manager_module, "get_none_hash_seed", lambda: "random-seed-abc"
)
assert mgr._get_hash_seed() == "random-seed-abc"
# ---------------------------------------------------------------------------