fix(host-agent): distinguish connected devices from busy-with-task in console
Tests / Test failed: 2, passed: 693

DeviceManager marks a device "busy" as soon as an Appium/WDA session is
connected, which is unrelated to whether a task is currently executing on
it. The Host Agent's local console displayed this raw status, making
connected-but-idle devices look permanently busy. Cross-reference the
device id against AgentStatusTracker's current_assignment (already
tracked via mark_assignment_started/finished) to show "connected" unless
a task is actually running on that device.
This commit is contained in:
2026-07-14 11:48:33 +08:00
parent bead6e58ac
commit c049c3c1b1
2 changed files with 66 additions and 2 deletions
+17 -2
View File
@@ -108,6 +108,17 @@ def _login_page(
return HTMLResponse(_chrome("Login", body, session=None))
def _device_display_status(device: Any, *, busy_device_id: str | None) -> str:
"""Connected-but-idle devices report "busy" at the DeviceManager layer
(an active Appium/WDA session is required to reuse it), which is not the
same as a task currently running on that device. Only the device actually
bound to the current assignment should read as "busy" here.
"""
if device.status == "busy" and device.id != busy_device_id:
return "connected"
return device.status
def _dashboard_body(
*,
identity: HostIdentityState | None,
@@ -118,6 +129,7 @@ def _dashboard_body(
heartbeat = snapshot.get("last_heartbeat")
assignment = snapshot.get("current_assignment")
policy = snapshot.get("host_policy")
busy_device_id = assignment["device_id"] if assignment else None
heartbeat_text = (
f"{'ok' if heartbeat['ok'] else 'failed'} at {heartbeat['at']} "
f"({heartbeat['device_count']} devices)"
@@ -143,7 +155,8 @@ def _dashboard_body(
)
device_rows = "".join(
f"<tr><td>{escape(device.id)}</td><td>{escape(device.name or '')}</td>"
f"<td>{escape(device.driver_type)}</td><td>{escape(device.status)}</td></tr>"
f"<td>{escape(device.driver_type)}</td>"
f"<td>{escape(_device_display_status(device, busy_device_id=busy_device_id))}</td></tr>"
for device in devices
)
return f"""
@@ -403,12 +416,14 @@ def create_console_app(
session: SessionState = Depends(require_session),
) -> JSONResponse:
snapshot = status_tracker.snapshot()
current_assignment = snapshot.get("current_assignment")
busy_device_id = current_assignment["device_id"] if current_assignment else None
devices = [
{
"id": device.id,
"name": device.name,
"driver_type": device.driver_type,
"status": device.status,
"status": _device_display_status(device, busy_device_id=busy_device_id),
}
for device in manager.list_devices()
]