sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
@@ -78,15 +78,14 @@ async def _enter_runtime_backend_or_fallback[BackendT](
|
||||
return await stack.enter_async_context(context_manager)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"%s initialization failed; continuing Gateway startup with an "
|
||||
"in-memory fallback",
|
||||
"%s initialization failed; continuing Gateway startup with an in-memory fallback",
|
||||
label,
|
||||
)
|
||||
return fallback_factory()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
async def langgraph_runtime(app: FastAPI, *, background: bool = True) -> AsyncGenerator[None, None]:
|
||||
"""Bootstrap and tear down all LangGraph runtime singletons.
|
||||
|
||||
Usage in ``app.py``::
|
||||
@@ -158,6 +157,10 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
app.state.thread_store,
|
||||
)
|
||||
|
||||
from deerflow.persistence.task_deeplink_details import make_task_deeplink_detail_store
|
||||
|
||||
app.state.task_deeplink_detail_store = make_task_deeplink_detail_store(sf)
|
||||
|
||||
from deerflow.persistence.artifact_library import make_artifact_library_store
|
||||
|
||||
app.state.artifact_library_store = make_artifact_library_store(sf)
|
||||
@@ -186,6 +189,10 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
app.state.tool_metrics_store = make_tool_metrics_store(sf)
|
||||
|
||||
from deerflow.persistence.stream_truncation import make_stream_truncation_store
|
||||
|
||||
app.state.stream_truncation_store = make_stream_truncation_store(sf)
|
||||
|
||||
from deerflow.persistence.agents import make_agent_store
|
||||
|
||||
app.state.agent_store = make_agent_store(sf)
|
||||
@@ -251,7 +258,7 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
app.state.ai_writing_job_executor = AIWritingJobExecutor(app)
|
||||
# 进程重启续跑:把仍标记为 background 的会话重新拉起驱动(best-effort,不阻塞启动)。
|
||||
if app.state.ai_writing_session_store is not None:
|
||||
if background and app.state.ai_writing_session_store is not None:
|
||||
from app.gateway.ai_writing_job_executor import STATUS_BACKGROUND
|
||||
|
||||
async def _reconcile_ai_writing_background() -> None:
|
||||
@@ -342,9 +349,7 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
try:
|
||||
await app.state.position_role_store.ensure_seed(POSITION_ROLE_SEED)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Position-role seeding failed at startup; continuing without seed refresh"
|
||||
)
|
||||
logger.exception("Position-role seeding failed at startup; continuing without seed refresh")
|
||||
|
||||
from deerflow.persistence.business_mapping import make_business_mapping_store
|
||||
|
||||
@@ -380,7 +385,7 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
app.state.report_collaboration_executor = None
|
||||
app.state.report_collaboration_dispatcher = None
|
||||
rc_cfg = getattr(config, "report_collaboration", None)
|
||||
if rc_cfg is not None and rc_cfg.enabled and rc_cfg.worker_enabled:
|
||||
if background and rc_cfg is not None and rc_cfg.enabled and rc_cfg.worker_enabled:
|
||||
from app.report_collaboration.agentscope_runtime.member_kernel import AgentScopeMemberKernel
|
||||
from app.report_collaboration.execution.dispatcher import ReportCollaborationDispatcher
|
||||
from app.report_collaboration.execution.executor import ReportCollaborationExecutor
|
||||
@@ -440,23 +445,17 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
app.state.upload_policy_store = make_upload_policy_store(sf)
|
||||
fallback_upload_policy = default_upload_policy()
|
||||
try:
|
||||
upload_policy_row = await app.state.upload_policy_store.ensure_seed(
|
||||
fallback_upload_policy
|
||||
)
|
||||
upload_policy_row = await app.state.upload_policy_store.ensure_seed(fallback_upload_policy)
|
||||
set_runtime_upload_policy(upload_policy_row["policy"])
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Upload-policy seeding failed at startup; using process-local defaults"
|
||||
)
|
||||
logger.exception("Upload-policy seeding failed at startup; using process-local defaults")
|
||||
set_runtime_upload_policy(fallback_upload_policy)
|
||||
|
||||
from deerflow.persistence.knowledge_retrieval_settings import (
|
||||
make_knowledge_retrieval_settings_store,
|
||||
)
|
||||
|
||||
app.state.knowledge_retrieval_settings_store = (
|
||||
make_knowledge_retrieval_settings_store(sf)
|
||||
)
|
||||
app.state.knowledge_retrieval_settings_store = make_knowledge_retrieval_settings_store(sf)
|
||||
|
||||
from deerflow.persistence.task_analysis import make_task_analysis_store
|
||||
|
||||
@@ -466,6 +465,12 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
app.state.analysis_project_store = AnalysisProjectStore(sf)
|
||||
|
||||
from deerflow.persistence.knowledge_research import (
|
||||
make_knowledge_research_store,
|
||||
)
|
||||
|
||||
app.state.knowledge_research_store = make_knowledge_research_store(sf)
|
||||
|
||||
from app.gateway.analysis_project_memory import (
|
||||
AnalysisProjectMemoryDispatcher,
|
||||
AnalysisProjectMemoryExecutor,
|
||||
@@ -501,7 +506,7 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
app.state.assistant_knowledge_store = make_assistant_knowledge_store(sf)
|
||||
register_assistant_knowledge_store(app.state.assistant_knowledge_store)
|
||||
app.state.skill_knowledge_store = make_skill_knowledge_store(sf)
|
||||
if app.state.skill_knowledge_store is not None and app.state.assistant_knowledge_store is not None:
|
||||
if background and app.state.skill_knowledge_store is not None and app.state.assistant_knowledge_store is not None:
|
||||
from app.gateway.skill_knowledge_job_dispatcher import SkillKnowledgeJobDispatcher
|
||||
from app.gateway.skill_knowledge_job_executor import SkillKnowledgeJobExecutor
|
||||
|
||||
@@ -544,7 +549,8 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
# Start only after the optional embedding runtime is ready. Otherwise
|
||||
# persisted jobs reclaimed during startup would be permanently stored
|
||||
# as lexical-only even when phase-two vector recall is configured.
|
||||
app.state.analysis_project_memory_dispatcher.start()
|
||||
if background:
|
||||
app.state.analysis_project_memory_dispatcher.start()
|
||||
|
||||
from deerflow.persistence.taskcop_tasks import make_taskcop_task_store
|
||||
|
||||
@@ -575,6 +581,10 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
)
|
||||
|
||||
app.state.roundtable_job_store = make_roundtable_job_store(sf)
|
||||
|
||||
from deerflow.persistence.roundtable_rooms import make_roundtable_room_store
|
||||
|
||||
app.state.roundtable_room_store = make_roundtable_room_store(sf)
|
||||
# 让 LangGraph Server 路径下的圆桌编排图节点能跨 app/harness 边界拿到 repo
|
||||
# (Phase 2 后台编排图写进度用)。
|
||||
_register_roundtable_job_default_store(app.state.roundtable_job_store)
|
||||
@@ -659,7 +669,8 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
draft_store=getattr(app.state, "roundtable_draft_store", None),
|
||||
task_draft_store=getattr(app.state, "roundtable_task_draft_store", None),
|
||||
)
|
||||
app.state.roundtable_job_dispatcher.start()
|
||||
if background:
|
||||
app.state.roundtable_job_dispatcher.start()
|
||||
else:
|
||||
app.state.roundtable_job_executor = None
|
||||
app.state.roundtable_job_dispatcher = None
|
||||
@@ -727,7 +738,8 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
app.state.deep_research_job_store,
|
||||
app.state.deep_research_executor,
|
||||
)
|
||||
app.state.deep_research_dispatcher.start()
|
||||
if background:
|
||||
app.state.deep_research_dispatcher.start()
|
||||
else:
|
||||
app.state.deep_research_executor = None
|
||||
app.state.deep_research_dispatcher = None
|
||||
@@ -758,7 +770,8 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
live_publisher=app.state.workflow_live_hub.publish,
|
||||
config=workflow_cfg,
|
||||
)
|
||||
app.state.workflow_dispatcher.start()
|
||||
if background:
|
||||
app.state.workflow_dispatcher.start()
|
||||
from app.gateway.workflow_retention import WorkflowRetentionCleaner
|
||||
|
||||
app.state.workflow_retention = WorkflowRetentionCleaner(
|
||||
@@ -766,7 +779,8 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
app.state.workflow_event_store,
|
||||
config=workflow_cfg,
|
||||
)
|
||||
app.state.workflow_retention.start()
|
||||
if background:
|
||||
app.state.workflow_retention.start()
|
||||
else:
|
||||
app.state.workflow_live_hub = None
|
||||
app.state.workflow_executor = None
|
||||
@@ -779,6 +793,8 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
# RunManager with store backing for persistence
|
||||
app.state.run_manager = RunManager(store=app.state.run_store)
|
||||
retention = config.runtime_contention
|
||||
app.state.run_manager.start_retention(retention_seconds=retention.completed_run_retention_seconds, interval_seconds=retention.run_sweep_seconds)
|
||||
from deerflow.runtime import make_redis_concurrency_gate
|
||||
|
||||
app.state.concurrency_gate = make_redis_concurrency_gate(config)
|
||||
@@ -786,12 +802,11 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
await app.state.run_manager.aclose()
|
||||
# Project-memory extraction can use the shared local Wiki encoder.
|
||||
# Stop its jobs before retiring that runtime to avoid an embedding
|
||||
# call racing shutdown.
|
||||
analysis_project_memory_dispatcher = getattr(
|
||||
app.state, "analysis_project_memory_dispatcher", None
|
||||
)
|
||||
analysis_project_memory_dispatcher = getattr(app.state, "analysis_project_memory_dispatcher", None)
|
||||
if analysis_project_memory_dispatcher is not None:
|
||||
await analysis_project_memory_dispatcher.stop()
|
||||
from app.gateway.assistant_file_ingest import stop_file_jobs
|
||||
@@ -894,6 +909,14 @@ def get_task_deeplink_thread_store(request: Request):
|
||||
return val
|
||||
|
||||
|
||||
def get_task_deeplink_detail_store(request: Request):
|
||||
"""Return the external task-detail store used by task deep links."""
|
||||
val = getattr(request.app.state, "task_deeplink_detail_store", None)
|
||||
if val is None:
|
||||
raise HTTPException(status_code=503, detail="Task deep-link detail store not available")
|
||||
return val
|
||||
|
||||
|
||||
def get_scheduled_task_store(request: Request) -> ScheduledTaskStore:
|
||||
"""Return the scheduled-task store."""
|
||||
val = getattr(request.app.state, "scheduled_task_store", None)
|
||||
@@ -917,6 +940,11 @@ def get_tool_metrics_store(request: Request):
|
||||
return getattr(request.app.state, "tool_metrics_store", None)
|
||||
|
||||
|
||||
def get_stream_truncation_store(request: Request):
|
||||
"""Return the stream-truncation event store, or None when not configured."""
|
||||
return getattr(request.app.state, "stream_truncation_store", None)
|
||||
|
||||
|
||||
def get_agent_store(request: Request) -> AgentStore:
|
||||
"""Return the custom-agent store."""
|
||||
val = getattr(request.app.state, "agent_store", None)
|
||||
@@ -1125,7 +1153,10 @@ async def get_current_user_from_request(request: Request):
|
||||
detail=AuthErrorResponse(code=token_error_to_code(payload), message=f"Token error: {payload.value}").model_dump(),
|
||||
)
|
||||
|
||||
if policy_error := session_policy_error(payload):
|
||||
# Scoped service tokens are authorized by AuthMiddleware's strict path
|
||||
# allow-list. They are intentionally not accepted by the separate
|
||||
# LangGraph auth path, which still applies session_policy_error directly.
|
||||
if payload.auth_method != "service" and (policy_error := session_policy_error(payload)):
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail=AuthErrorResponse(code=AuthErrorCode.TOKEN_INVALID, message=policy_error).model_dump(),
|
||||
|
||||
Reference in new issue
Block a user