From 74b7a7eff97f5626ed3971c53a8124ff5e060ef5 Mon Sep 17 00:00:00 2001 From: greatmengqi Date: Fri, 17 Apr 2026 00:27:29 +0800 Subject: [PATCH] refactor(config): thread AppConfig through RunContext into Worker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 2 Task P2-5 (partial, Category D): RunContext gains an optional app_config field. Gateway deps.get_run_context populates it from app.state.config. Worker builds DeerFlowContext from ctx.app_config when provided, falling back to AppConfig.current() for legacy callers. This is the key path: Gateway-mode agent runs now construct DeerFlowContext without consulting the process-global at all — app_config flows from FastAPI's app.state through RunContext to Worker to Runtime.context. Standalone providers (checkpointer/store/stream_bridge) already accept optional config parameter from P1, so they are Phase 2-ready. 59 gateway/worker/run_manager tests pass. --- backend/app/gateway/deps.py | 1 + backend/packages/harness/deerflow/runtime/runs/worker.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/gateway/deps.py b/backend/app/gateway/deps.py index f17c101d8..bed03d26e 100644 --- a/backend/app/gateway/deps.py +++ b/backend/app/gateway/deps.py @@ -149,6 +149,7 @@ def get_run_context(request: Request) -> RunContext: event_store=get_run_event_store(request), run_events_config=getattr(config, "run_events", None), thread_store=get_thread_store(request), + app_config=config, ) diff --git a/backend/packages/harness/deerflow/runtime/runs/worker.py b/backend/packages/harness/deerflow/runtime/runs/worker.py index d8dfa1c2f..8cdebd5f4 100644 --- a/backend/packages/harness/deerflow/runtime/runs/worker.py +++ b/backend/packages/harness/deerflow/runtime/runs/worker.py @@ -54,6 +54,9 @@ class RunContext: run_events_config: Any | None = field(default=None) thread_store: Any | None = field(default=None) follow_up_to_run_id: str | None = field(default=None) + # Phase 2: app-level config flows through RunContext so Worker can build + # DeerFlowContext without consulting the process-global. + app_config: Any | None = field(default=None) async def run_agent( @@ -169,7 +172,7 @@ async def run_agent( # LangGraph's astream(context=...) injects this into Runtime.context # so middleware/tools can access it via resolve_context(). deer_flow_context = DeerFlowContext( - app_config=AppConfig.current(), + app_config=ctx.app_config if ctx.app_config is not None else AppConfig.current(), thread_id=thread_id, )