sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
@@ -29,8 +29,10 @@ from deerflow.agents.roundtable_orchestrator import (
|
||||
SeatRef,
|
||||
run_orchestration,
|
||||
)
|
||||
from deerflow.config.system_settings import get_roundtable_room_limit_settings
|
||||
from deerflow.persistence.roundtable_diagnostics import DiagnosticsRecorder, get_default_store
|
||||
from deerflow.persistence.roundtable_drafts.sql import DraftConcurrentWriteError
|
||||
from deerflow.persistence.roundtable_rooms.sql import NON_OCCUPYING_JOB_PHASES
|
||||
from deerflow.runtime.user_context import reset_current_user, set_current_user
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -67,6 +69,26 @@ _DRAFT_WRITE_RETRIES = 3
|
||||
ROUNDTABLE_BACKGROUND_REPORT_ENABLED = True
|
||||
|
||||
|
||||
def _background_step2_room_expired(row: dict[str, Any] | None) -> bool:
|
||||
"""Whether a background job exceeded the configurable Step-2 hard limit."""
|
||||
if not row or str(row.get("phase") or "") in NON_OCCUPYING_JOB_PHASES:
|
||||
return False
|
||||
raw_created = row.get("created_at")
|
||||
if isinstance(raw_created, datetime):
|
||||
created_at = raw_created
|
||||
elif isinstance(raw_created, str) and raw_created:
|
||||
try:
|
||||
created_at = datetime.fromisoformat(raw_created)
|
||||
except ValueError:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
if created_at.tzinfo is None:
|
||||
created_at = created_at.replace(tzinfo=UTC)
|
||||
max_minutes = getattr(get_roundtable_room_limit_settings(), "max_hold_minutes", 30)
|
||||
return datetime.now(UTC) >= created_at + timedelta(minutes=max_minutes)
|
||||
|
||||
|
||||
class _JobUser:
|
||||
"""最小 CurrentUser:满足 user_context 的 ``.id`` 结构协议。"""
|
||||
|
||||
@@ -439,6 +461,11 @@ class RoundtableJobExecutor:
|
||||
self._watch_cancellation(params.job_id, main_task, params.lease_owner)
|
||||
)
|
||||
try:
|
||||
# 全局设置在作业真正启动时读取并锁定;运行中修改只影响下一次会商,
|
||||
# 避免本作业在半途因配置变化突然提前或延后收口。
|
||||
max_cycles = int(
|
||||
getattr(get_roundtable_room_limit_settings(), "max_cycles", 8)
|
||||
)
|
||||
result = await run_orchestration(
|
||||
gateway=gateway,
|
||||
progress=progress,
|
||||
@@ -453,6 +480,7 @@ class RoundtableJobExecutor:
|
||||
plan=params.orchestration_plan,
|
||||
gather_first=params.gather_first,
|
||||
business_code=params.business_code,
|
||||
max_cycles=max_cycles,
|
||||
)
|
||||
finally:
|
||||
watcher.cancel()
|
||||
@@ -559,6 +587,22 @@ class RoundtableJobExecutor:
|
||||
except Exception: # noqa: BLE001 — DB 读失败不中断看门狗,下轮重试
|
||||
continue
|
||||
status = (row.get("status") or "") if row is not None else ""
|
||||
if status in {"queued", "running", "awaiting_input"} and _background_step2_room_expired(row):
|
||||
logger.info(
|
||||
"roundtable job %s reached the Step-2 room hard limit; requesting cancellation",
|
||||
job_id,
|
||||
)
|
||||
try:
|
||||
requested = await self._store.request_cancel(job_id, user_id=None)
|
||||
if requested is not None:
|
||||
row = requested
|
||||
status = str(requested.get("status") or "")
|
||||
except Exception: # noqa: BLE001
|
||||
logger.warning(
|
||||
"roundtable job %s hard-limit cancellation failed",
|
||||
job_id,
|
||||
exc_info=True,
|
||||
)
|
||||
if status == "cancel_requested":
|
||||
logger.info(
|
||||
"roundtable job %s: detected cancel_requested in DB, finalizing "
|
||||
|
||||
Reference in new issue
Block a user