Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions lib/bindings/python/tests/test_kv_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,60 @@ def __iter__(self):
service.shutdown()


@pytest.mark.skipif(
SelectionService is None,
reason="SelectionService requires the select-service Cargo feature",
)
@pytest.mark.timeout(5)
@pytest.mark.asyncio
async def test_selection_service_worker_is_eagle_rejects_non_booleans(monkeypatch):
Comment thread
glamr-agent marked this conversation as resolved.
Resolved
monkeypatch.setenv("DYN_ROUTER_USE_KV_EVENTS", "false")
service = SelectionService(indexer_threads=1)

def worker(worker_id, model_name, **extra):
return {
"worker_id": worker_id,
"model_name": model_name,
"endpoint": f"http://worker-{worker_id}",
"block_size": 4,
"max_num_batched_tokens": 1024,
**extra,
}

def stored_is_eagle(model_name):
(record,) = service.list_workers(model_name=model_name)
return record["is_eagle"]

try:
# Real booleans keep their meaning; omitted and None stay unset.
record = await service.upsert_worker(worker(1, "plain", is_eagle=False))
assert record["is_eagle"] is False
record = await service.upsert_worker(worker(2, "eagle", is_eagle=True))
assert record["is_eagle"] is True
record = await service.upsert_worker(worker(3, "omitted"))
assert record["is_eagle"] is None
record = await service.upsert_worker(worker(4, "null", is_eagle=None))
assert record["is_eagle"] is None

# Worker booleans are not coerced by truthiness, so "false" cannot enable Eagle.
for value in ["false", "true", 1, [False]]:
with pytest.raises(ValueError, match="boolean"):
await service.upsert_worker(worker(5, "malformed", is_eagle=value))
with pytest.raises(ValueError, match="boolean"):
await service.patch_worker(1, {"is_eagle": value})
assert service.list_workers(model_name="malformed") == []
assert stored_is_eagle("plain") is False

# An omitted or None patch value leaves the stored value unchanged; a real boolean replaces it.
for patch in [{}, {"is_eagle": None}]:
record = await service.patch_worker(2, patch)
assert record["is_eagle"] is True
record = await service.patch_worker(2, {"is_eagle": False})
assert record["is_eagle"] is False
finally:
await service.shutdown_async()


@pytest.mark.skipif(
SelectionService is None,
reason="SelectionService requires the select-service Cargo feature",
Expand Down
2 changes: 2 additions & 0 deletions lib/kv-router/src/services/selection/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub struct WorkerRequest {
pub max_num_batched_tokens: Option<u64>,
pub total_kv_blocks: Option<u64>,
pub stable_routing_id: Option<String>,
#[serde(default, deserialize_with = "strict_bool")]
Comment thread
glamr-agent marked this conversation as resolved.
Resolved
pub is_eagle: Option<bool>,
#[serde(default)]
pub taints: HashSet<String>,
Expand Down Expand Up @@ -363,6 +364,7 @@ pub struct WorkerPatchRequest {
pub max_num_batched_tokens: Option<u64>,
pub total_kv_blocks: Option<u64>,
pub stable_routing_id: Option<String>,
#[serde(default, deserialize_with = "strict_bool")]
pub is_eagle: Option<bool>,
pub taints: Option<HashSet<String>>,
pub topology_domains: Option<HashMap<String, String>>,
Expand Down
Loading