feat(cloud): skip MCP-busy devices in scheduler

This commit is contained in:
2026-07-21 14:37:21 +08:00
parent 9e3007e7f6
commit b0932dd398
8 changed files with 172 additions and 1 deletions
+12 -1
View File
@@ -47,6 +47,7 @@ class PooledDevice:
status: PooledDeviceStatus
capability_tags: list[str] = field(default_factory=list)
synced_at: datetime | None = None
mcp_busy: bool = False
class DevicePool:
@@ -64,6 +65,7 @@ class DevicePool:
address: str | None = None,
planner_transport: Literal["direct", "cloud"] = "direct",
allow_device_takeover: bool = False,
mcp_busy_device_ids: list[str] | None = None,
) -> None:
"""Push a host's current device snapshot into the pool.
@@ -78,7 +80,13 @@ class DevicePool:
last_seen_at=now,
planner_transport=planner_transport,
)
devices = [self._to_pooled(device, host_id, now) for device in snapshot]
busy_set = set(mcp_busy_device_ids or [])
devices = [
self._to_pooled(
device, host_id, now, mcp_busy=device.id in busy_set
)
for device in snapshot
]
if allow_device_takeover:
self.store.replace_host_devices(
host_id,
@@ -119,6 +127,8 @@ class DevicePool:
device: Device,
host_id: str,
synced_at: datetime,
*,
mcp_busy: bool = False,
) -> PooledDevice:
raw_status = (
device.status if device.status in _HOST_REPORTED_STATUSES else "idle"
@@ -131,6 +141,7 @@ class DevicePool:
status=raw_status, # type: ignore[arg-type]
capability_tags=tags,
synced_at=synced_at,
mcp_busy=mcp_busy,
)
def _is_stale(self, host: HostRegistration, now: datetime) -> bool: