feat(host-agent): fail-fast cloud assignment when MCP holds device
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from cloud.internal_api.models import AssignmentModel
|
||||
from core.models import Task
|
||||
@@ -11,6 +11,9 @@ from host_agent.planner_context import bind_planner_execution_context
|
||||
from host_agent.progress import TaskProgressHolder, TaskProgressSnapshot
|
||||
from runtime.task import is_cancellation_reason
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from host_agent.mcp_lock import McpBusyTracker
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class AssignmentExecutionResult:
|
||||
@@ -20,9 +23,15 @@ class AssignmentExecutionResult:
|
||||
|
||||
|
||||
class AssignmentExecutor:
|
||||
def __init__(self, factories: ExecutionFactories) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
factories: ExecutionFactories,
|
||||
*,
|
||||
mcp_busy_tracker: McpBusyTracker | None = None,
|
||||
) -> None:
|
||||
self.factories = factories
|
||||
self._progress = TaskProgressHolder()
|
||||
self._mcp_busy_tracker = mcp_busy_tracker
|
||||
|
||||
def latest_progress(self) -> TaskProgressSnapshot | None:
|
||||
"""Latest step progress reported by the currently-running assignment."""
|
||||
@@ -36,6 +45,16 @@ class AssignmentExecutor:
|
||||
stop_reason: Callable[[], str | None] | None = None,
|
||||
) -> AssignmentExecutionResult:
|
||||
self._progress.clear()
|
||||
if self._mcp_busy_tracker is not None and (
|
||||
assignment.device_id in self._mcp_busy_tracker.busy_device_ids()
|
||||
):
|
||||
return AssignmentExecutionResult(
|
||||
status="failed",
|
||||
failure_reason=(
|
||||
f"device {assignment.device_id} is held by an active "
|
||||
"MCP session"
|
||||
),
|
||||
)
|
||||
with bind_planner_execution_context(assignment):
|
||||
if should_stop is not None and should_stop():
|
||||
reason = stop_reason() if stop_reason is not None else None
|
||||
|
||||
Reference in New Issue
Block a user