Improve local agent chat and device health detection
This commit is contained in:
@@ -60,6 +60,8 @@ class HeartbeatSynchronizer:
|
||||
self.status_tracker.mark_host_policy(self.policy)
|
||||
|
||||
async def sync_once(self) -> HeartbeatResponse:
|
||||
self.probe_connected_devices()
|
||||
self.connect_devices()
|
||||
snapshot = build_device_snapshot(self.manager)
|
||||
mcp_busy_ids = (
|
||||
self.mcp_busy_tracker.busy_device_ids()
|
||||
@@ -108,9 +110,19 @@ class HeartbeatSynchronizer:
|
||||
|
||||
def connect_devices(self) -> None:
|
||||
for device in self.manager.list_devices():
|
||||
if device.status != "idle":
|
||||
if device.status not in {"idle", "offline", "error"}:
|
||||
continue
|
||||
try:
|
||||
self.manager.connect(device.id)
|
||||
except DeviceRuntimeError:
|
||||
continue
|
||||
|
||||
def probe_connected_devices(self) -> None:
|
||||
active_id: str | None = None
|
||||
if self.status_tracker is not None:
|
||||
current = self.status_tracker.snapshot().get("current_assignment")
|
||||
if isinstance(current, dict) and isinstance(current.get("device_id"), str):
|
||||
active_id = current["device_id"]
|
||||
for device in self.manager.list_devices():
|
||||
if device.id != active_id and device.status == "busy":
|
||||
self.manager.probe(device.id)
|
||||
|
||||
Reference in New Issue
Block a user