refactor(runtime): relocate trace store and break dependency cycle
This commit is contained in:
1 parent
584bb2d09c
commit
05459d040d
21 files changed
+134
-64
No files matched your search
@@ -15,6 +15,8 @@
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from artemis.runtime import trace_store
|
||||
|
||||
try:
|
||||
from admin_console.database.connection import db_session
|
||||
except ImportError:
|
||||
@@ -309,8 +311,6 @@ class SessionRepository:
|
||||
)
|
||||
count += cursor.rowcount
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
if trace_store.read_status(str(row["session_id"])):
|
||||
trace_store.update_trace_status(
|
||||
str(row["session_id"]),
|
||||
@@ -410,3 +410,11 @@ class SessionRepository:
|
||||
|
||||
|
||||
session_repo = SessionRepository()
|
||||
|
||||
# Give the base runtime package access to orphan-session reconciliation without
|
||||
# letting it import this application-layer module (inverted dependency): any
|
||||
# process that loads the admin console DB layer -- the server itself, or an
|
||||
# entry point stopping one -- thereby arms stop_server()'s post-kill cleanup.
|
||||
from artemis.runtime.server_lifecycle import register_session_reconciler # noqa: E402
|
||||
|
||||
register_session_reconciler(session_repo.reconcile_orphaned_sessions)
|
||||
@@ -19,6 +19,7 @@ from uuid import UUID
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from artemis.config import DB_PATH, TRACES_PATH
|
||||
from artemis.runtime import trace_store
|
||||
|
||||
try:
|
||||
from admin_console.core.state import state
|
||||
@@ -149,8 +150,6 @@ def _list_sessions_sync():
|
||||
harvested = session_repo.harvest_orphaned_sessions(orphaned_ids)
|
||||
print(f"[list_sessions] Auto-harvested {harvested} orphaned running session(s).")
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
for o_id in orphaned_ids:
|
||||
if trace_store.read_status(str(o_id)):
|
||||
trace_store.update_trace_status(
|
||||
|
||||
@@ -45,6 +45,7 @@ from artemis.runtime import (
|
||||
DeviceExecutionLock,
|
||||
current_adb_endpoint,
|
||||
process_supervisor,
|
||||
trace_store,
|
||||
)
|
||||
|
||||
|
||||
@@ -510,8 +511,6 @@ class TaskQueueService:
|
||||
}
|
||||
if sess_id:
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
st = trace_store.read_status(str(sess_id))
|
||||
if st:
|
||||
st["pid"] = proc.pid
|
||||
@@ -536,8 +535,6 @@ class TaskQueueService:
|
||||
log_path = None
|
||||
if sess_id:
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
log_path = trace_store.get_trace_stdout_log_path(str(sess_id))
|
||||
except Exception:
|
||||
log_path = None
|
||||
@@ -580,8 +577,6 @@ class TaskQueueService:
|
||||
f"status '{new_status}'"
|
||||
)
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
if trace_store.read_status(str(sess_id)):
|
||||
canonical_mcp_status = "completed" if new_status in ("completed", "success") else new_status
|
||||
trace_store.update_trace_status(
|
||||
@@ -870,8 +865,6 @@ class TaskQueueService:
|
||||
if sid:
|
||||
session_repo.update_session_status(str(sid), "cancelled", time.time())
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
is_mcp = bool(dev_owner and dev_owner.ingress == "mcp")
|
||||
if is_mcp or trace_store.read_status(str(sid)):
|
||||
trace_store.update_trace_status(
|
||||
@@ -1133,8 +1126,6 @@ class TaskQueueService:
|
||||
str(stopped_session_id), "cancelled", time.time()
|
||||
)
|
||||
try:
|
||||
from mcp_server.utils import trace_store
|
||||
|
||||
is_mcp = bool(owner and owner.ingress == "mcp")
|
||||
if is_mcp or trace_store.read_status(str(stopped_session_id)):
|
||||
trace_store.update_trace_status(
|
||||
|
||||
Reference in new issue
Block a user