Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

fix(cluster): a numeric node_id killed every topology and health request

kevin9327e0074b2a6b26
diff --git a/c/cluster.py b/c/cluster.py
index 6f0e5a53..05fa3819 100644
--- a/c/cluster.py
+++ b/c/cluster.py
@@ -33,10 +33,16 @@ class ClusterRegistry:
role = str(node["role"])
if role not in ("expert", "dense", "coordinator"):
raise ValueError("role must be expert, dense, or coordinator")
+ # The registry keys by str(node_id) and heartbeat looks it up the same
+ # way, so a numeric node_id has always registered. Store the string in
+ # the record too, or snapshot() sorts it against a string node_id and
+ # every topology/health request dies with a TypeError.
+ node_id = str(node["node_id"])
record = dict(node)
- record.update(protocol_version=PROTOCOL_VERSION, port=port, last_seen=time.time())
+ record.update(node_id=node_id, protocol_version=PROTOCOL_VERSION, port=port,
+ last_seen=time.time())
with self._lock:
- self._nodes[str(node["node_id"])] = record
+ self._nodes[node_id] = record
return record
def heartbeat(self, node_id):
diff --git a/c/tests/test_cluster.py b/c/tests/test_cluster.py
index 0f84f865..ebc487b7 100644
--- a/c/tests/test_cluster.py
+++ b/c/tests/test_cluster.py
@@ -20,6 +20,43 @@ class ClusterRegistryTests(unittest.TestCase):
self.assertEqual(registry.expert_endpoints(), ["10.0.0.2:9100"])
self.assertEqual(registry.snapshot()["protocol_version"], PROTOCOL_VERSION)
+ def test_numeric_node_id_does_not_break_discovery(self):
+ # A worker that sends "node_id": 1 registers fine (the registry keys
+ # by str(node_id) and heartbeat looks it up the same way), so the
+ # snapshot must not die sorting an int against a string node_id.
+ registry = ClusterRegistry()
+ record = registry.register({"node_id": 1, "host": "10.0.0.2", "port": 9100,
+ "role": "expert"})
+ registry.register({"node_id": "mac-b", "host": "10.0.0.3", "port": 9101,
+ "role": "expert"})
+ self.assertEqual(registry.expert_endpoints(), ["10.0.0.2:9100", "10.0.0.3:9101"])
+ self.assertEqual(registry.heartbeat(record["node_id"])["host"], "10.0.0.2")
+ self.assertEqual(registry.heartbeat(1)["host"], "10.0.0.2")
+
+ def test_http_topology_survives_a_numeric_node_id(self):
+ server = ClusterServer(("127.0.0.1", 0), ClusterRegistry())
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ try:
+ for node_id in (1, "mac-b"):
+ conn = HTTPConnection(*server.server_address)
+ body = json.dumps({"node_id": node_id, "host": "127.0.0.1",
+ "port": 9100, "role": "expert"})
+ conn.request("POST", "/v1/cluster/register", body,
+ {"Content-Type": "application/json"})
+ self.assertEqual(conn.getresponse().status, 200)
+ conn.close()
+ for path in ("/v1/cluster/topology", "/health"):
+ conn = HTTPConnection(*server.server_address)
+ conn.request("GET", path)
+ response = conn.getresponse()
+ self.assertEqual(response.status, 200, path)
+ self.assertEqual(len(json.loads(response.read())["nodes"]), 2, path)
+ conn.close()
+ finally:
+ server.shutdown()
+ server.server_close()
+
def test_http_topology_registration_and_heartbeat(self):
server = ClusterServer(("127.0.0.1", 0), ClusterRegistry())
thread = threading.Thread(target=server.serve_forever, daemon=True)