feat: auto heartbeat governor (elastic backoff)
(cherry picked from commit 2d1d691879)
This commit is contained in:
committed by
Abhimanyu Saharan
parent
fa445127d9
commit
2a3b1022c2
@@ -544,7 +544,7 @@ class GatewayControlPlane(ABC):
|
||||
@abstractmethod
|
||||
async def patch_agent_heartbeats(
|
||||
self,
|
||||
entries: list[tuple[str, str, dict[str, Any]]],
|
||||
entries: list[tuple[str, str, dict[str, Any] | None]],
|
||||
) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -684,7 +684,7 @@ class OpenClawGatewayControlPlane(GatewayControlPlane):
|
||||
|
||||
async def patch_agent_heartbeats(
|
||||
self,
|
||||
entries: list[tuple[str, str, dict[str, Any]]],
|
||||
entries: list[tuple[str, str, dict[str, Any] | None]],
|
||||
) -> None:
|
||||
base_hash, raw_list, config_data = await _gateway_config_agent_list(self._config)
|
||||
entry_by_id = _heartbeat_entry_map(entries)
|
||||
@@ -732,8 +732,8 @@ async def _gateway_config_agent_list(
|
||||
|
||||
|
||||
def _heartbeat_entry_map(
|
||||
entries: list[tuple[str, str, dict[str, Any]]],
|
||||
) -> dict[str, tuple[str, dict[str, Any]]]:
|
||||
entries: list[tuple[str, str, dict[str, Any] | None]],
|
||||
) -> dict[str, tuple[str, dict[str, Any] | None]]:
|
||||
return {
|
||||
agent_id: (workspace_path, heartbeat) for agent_id, workspace_path, heartbeat in entries
|
||||
}
|
||||
@@ -741,7 +741,7 @@ def _heartbeat_entry_map(
|
||||
|
||||
def _updated_agent_list(
|
||||
raw_list: list[object],
|
||||
entry_by_id: dict[str, tuple[str, dict[str, Any]]],
|
||||
entry_by_id: dict[str, tuple[str, dict[str, Any] | None]],
|
||||
) -> list[object]:
|
||||
updated_ids: set[str] = set()
|
||||
new_list: list[object] = []
|
||||
@@ -758,16 +758,20 @@ def _updated_agent_list(
|
||||
workspace_path, heartbeat = entry_by_id[agent_id]
|
||||
new_entry = dict(raw_entry)
|
||||
new_entry["workspace"] = workspace_path
|
||||
new_entry["heartbeat"] = heartbeat
|
||||
if heartbeat is None:
|
||||
new_entry.pop("heartbeat", None)
|
||||
else:
|
||||
new_entry["heartbeat"] = heartbeat
|
||||
new_list.append(new_entry)
|
||||
updated_ids.add(agent_id)
|
||||
|
||||
for agent_id, (workspace_path, heartbeat) in entry_by_id.items():
|
||||
if agent_id in updated_ids:
|
||||
continue
|
||||
new_list.append(
|
||||
{"id": agent_id, "workspace": workspace_path, "heartbeat": heartbeat},
|
||||
)
|
||||
entry = {"id": agent_id, "workspace": workspace_path}
|
||||
if heartbeat is not None:
|
||||
entry["heartbeat"] = heartbeat
|
||||
new_list.append(entry)
|
||||
|
||||
return new_list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user