feat: add global device queue and readiness tracking
This commit is contained in:
1 parent
a62ac4aef1
commit
42b8988661
57 files changed
+3606
-716
No files matched your search
@@ -56,14 +56,19 @@ from mcp_server.base import mcp
|
||||
|
||||
# 2. Import tools to register them
|
||||
import mcp_server.tools # noqa: F401
|
||||
from artemis.runtime import shutdown_awake_service, start_awake_service
|
||||
|
||||
|
||||
def main(transport: str = "stdio", host: str = "127.0.0.1", port: int = 8001):
|
||||
"""Main entrypoint to run the Artemis Mobile Agent MCP server."""
|
||||
if transport.lower() == "sse":
|
||||
mcp.run(transport="sse", host=host, port=port)
|
||||
else:
|
||||
mcp.run(transport="stdio")
|
||||
start_awake_service()
|
||||
try:
|
||||
if transport.lower() == "sse":
|
||||
mcp.run(transport="sse", host=host, port=port)
|
||||
else:
|
||||
mcp.run(transport="stdio")
|
||||
finally:
|
||||
shutdown_awake_service()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -257,6 +257,7 @@ def mobile_manage_task(
|
||||
}
|
||||
|
||||
try:
|
||||
DeviceExecutionLock.cancel_reservation(status_data.get("queue_ticket"))
|
||||
if sys.platform == "win32":
|
||||
if not process_supervisor.terminate_tree(pid):
|
||||
import psutil
|
||||
|
||||
@@ -21,6 +21,7 @@ import uuid
|
||||
|
||||
from mcp_server.base import mcp
|
||||
from mcp_server.utils import env_utils, trace_store
|
||||
from artemis.runtime import DeviceExecutionLock
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
@@ -139,6 +140,11 @@ def mobile_run_task(
|
||||
# 3. Resolve project root, python executable, and background runner module
|
||||
project_root = env_utils.get_project_root()
|
||||
python_exe = env_utils.resolve_python_executable(project_root)
|
||||
queue_ticket = DeviceExecutionLock.reserve(
|
||||
description=f"MCP task: {task_desc[:120]}",
|
||||
session_id=trace_id,
|
||||
ingress="mcp",
|
||||
)
|
||||
|
||||
# 4. Spawn the background task runner as an independent subprocess
|
||||
try:
|
||||
@@ -164,6 +170,8 @@ def mobile_run_task(
|
||||
|
||||
env = os.environ.copy()
|
||||
env["ARTEMIS_SESSION_ID"] = trace_id
|
||||
env["ARTEMIS_TASK_INGRESS"] = "mcp"
|
||||
env[DeviceExecutionLock.QUEUE_TICKET_ENV] = queue_ticket
|
||||
|
||||
proc_kwargs = env_utils.get_detached_process_kwargs()
|
||||
proc = subprocess.Popen(
|
||||
@@ -172,11 +180,19 @@ def mobile_run_task(
|
||||
cwd=project_root,
|
||||
**proc_kwargs,
|
||||
)
|
||||
DeviceExecutionLock.transfer_reservation(
|
||||
queue_ticket,
|
||||
proc.pid,
|
||||
description=f"MCP task: {task_desc[:120]}",
|
||||
session_id=trace_id,
|
||||
ingress="mcp",
|
||||
)
|
||||
|
||||
# 5. Record the PID of the spawned subprocess
|
||||
status_data = trace_store.read_status(trace_id)
|
||||
if status_data:
|
||||
status_data["pid"] = proc.pid
|
||||
status_data["queue_ticket"] = queue_ticket
|
||||
trace_store.write_status(trace_id, status_data)
|
||||
|
||||
trace_dir = trace_store.get_trace_dir(trace_id)
|
||||
@@ -195,6 +211,7 @@ def mobile_run_task(
|
||||
return response_dict
|
||||
|
||||
except Exception as e:
|
||||
DeviceExecutionLock.cancel_reservation(queue_ticket)
|
||||
trace_store.update_trace_status(
|
||||
trace_id, "failed", error=f"Failed to spawn background runner: {e}"
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user