Align Responses cache affinity across execution and summary calls, preserve required checks and evidence uncertainty, and allow safe deletion of inactive explorations while retaining independent reruns. Validation: backend suite passed except intentional prompt golden drift, then all 17 transcript tests passed after snapshot refresh; 268 frontend tests and production build passed; Ruff, quality ratchet and core type checks passed.
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""Delete an inactive conversation while keeping independently executed reruns."""
|
|
|
|
import shutil
|
|
from uuid import UUID
|
|
|
|
from apps.admin_console.core.state import state
|
|
from apps.admin_console.services import report_export
|
|
from artemis.data_engine.storage import StorageManager
|
|
from artemis.exploration.store import ExplorationConflict, ExplorationStore
|
|
from artemis.runtime.process_probe import pid_is_alive
|
|
from artemis.runtime.task_control import read_state
|
|
|
|
|
|
def _check_runs(runs: list[dict]) -> None:
|
|
queued = {
|
|
item.get("session_id")
|
|
for item in state.queue_items
|
|
if item.get("status") in {"pending", "queued", "running"}
|
|
}
|
|
for run in runs:
|
|
run_id = run["id"]
|
|
if (
|
|
run_id in state.active_runs
|
|
or run_id in queued
|
|
or pid_is_alive(read_state(run_id).get("pid"))
|
|
):
|
|
raise ExplorationConflict("探索工作进程尚未结束,请停止任务并稍后重试删除")
|
|
|
|
|
|
def delete_exploration(repository: ExplorationStore, exploration_id: str) -> list[str]:
|
|
runs = repository.begin_delete(exploration_id, _check_runs)
|
|
# Validation sessions and batch copies remain ordinary Flash/Pro history.
|
|
deleted = [run["id"] for run in runs if run["kind"] == "exploration"]
|
|
storage = StorageManager(repository.database.path, report_export.TRACES_PATH)
|
|
with report_export.EXPORT_LOCK:
|
|
for run_id in deleted:
|
|
safe_id = str(UUID(run_id))
|
|
storage.delete_session(UUID(safe_id))
|
|
repository.database.delete_history(safe_id)
|
|
for root in (
|
|
report_export.EXPORT_ROOT,
|
|
report_export.EXPORT_ROOT.parent / "mcp_exports",
|
|
):
|
|
folder = (root / "sessions" / safe_id).resolve()
|
|
if folder.is_relative_to(root.resolve()) and folder.is_dir():
|
|
shutil.rmtree(folder)
|
|
repository.finish_delete(exploration_id)
|
|
return deleted
|