Fix control status: do not treat /health as fleet (missing positions).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -51,10 +51,6 @@ def _raise_node_error(code: int, data: Any) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _health_looks_like_fleet(health: Any) -> bool:
|
|
||||||
return isinstance(health, dict) and "strategy" in health and "mode" in health
|
|
||||||
|
|
||||||
|
|
||||||
async def _collect_one_status(
|
async def _collect_one_status(
|
||||||
node: dict[str, Any],
|
node: dict[str, Any],
|
||||||
*,
|
*,
|
||||||
@@ -63,10 +59,10 @@ async def _collect_one_status(
|
|||||||
probe = await probe_health(node, timeout=timeout)
|
probe = await probe_health(node, timeout=timeout)
|
||||||
item: dict[str, Any] = {**_public_node(node), **probe}
|
item: dict[str, Any] = {**_public_node(node), **probe}
|
||||||
if probe.get("online") and node.get("token_sealed"):
|
if probe.get("online") and node.get("token_sealed"):
|
||||||
health = probe.get("health")
|
# /health 也有 mode+strategy,但不能当 fleet(无持仓详情)。
|
||||||
# probe_health 在 /health 失败时可能已用 fleet/status 回填到 health
|
# 仅当 probe 已用 fleet 回退时复用,否则必须再拉 /api/fleet/status。
|
||||||
if _health_looks_like_fleet(health):
|
if probe.get("from_fleet") and isinstance(probe.get("health"), dict):
|
||||||
code, data = 200, health
|
code, data = 200, probe["health"]
|
||||||
else:
|
else:
|
||||||
code, data = await call_node(
|
code, data = await call_node(
|
||||||
node, "GET", "/api/fleet/status", timeout=timeout
|
node, "GET", "/api/fleet/status", timeout=timeout
|
||||||
|
|||||||
@@ -74,13 +74,23 @@ async def probe_health(
|
|||||||
node, "GET", "/health", require_token=False, timeout=timeout
|
node, "GET", "/health", require_token=False, timeout=timeout
|
||||||
)
|
)
|
||||||
if code == 200 and isinstance(data, dict):
|
if code == 200 and isinstance(data, dict):
|
||||||
return {"online": True, "health": data, "error": None}
|
return {
|
||||||
|
"online": True,
|
||||||
|
"health": data,
|
||||||
|
"error": None,
|
||||||
|
"from_fleet": False,
|
||||||
|
}
|
||||||
# fallback fleet status if health blocked
|
# fallback fleet status if health blocked
|
||||||
code2, data2 = await call_node(
|
code2, data2 = await call_node(
|
||||||
node, "GET", "/api/fleet/status", require_token=True, timeout=timeout
|
node, "GET", "/api/fleet/status", require_token=True, timeout=timeout
|
||||||
)
|
)
|
||||||
if code2 == 200 and isinstance(data2, dict):
|
if code2 == 200 and isinstance(data2, dict):
|
||||||
return {"online": True, "health": data2, "error": None}
|
return {
|
||||||
|
"online": True,
|
||||||
|
"health": data2,
|
||||||
|
"error": None,
|
||||||
|
"from_fleet": True,
|
||||||
|
}
|
||||||
detail = ""
|
detail = ""
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
detail = str(data.get("detail") or "")
|
detail = str(data.get("detail") or "")
|
||||||
@@ -88,4 +98,5 @@ async def probe_health(
|
|||||||
"online": False,
|
"online": False,
|
||||||
"health": None,
|
"health": None,
|
||||||
"error": detail or f"HTTP {code}",
|
"error": detail or f"HTTP {code}",
|
||||||
|
"from_fleet": False,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user