3 Commits

Author SHA1 Message Date
greatmengqi
5e1c309bd7 Merge release/2.0-rc into refactor/config-deerflow-context
Brings release/2.0-rc up to PR base. Three structural conflicts resolved:

- gateway/deps.py: kept both the new release-side persistence imports
  (FeedbackRepository, RunEventStore, RunStore, StreamBridge, TypeVar T)
  and the PR's get_config FastAPI dependency. Imports are independent;
  T is still used by _require() helper added on the release side.

- agents/middlewares/thread_data_middleware.py: release added HumanMessage
  stamping that records run_id on user-input messages. Adapted to the PR's
  typed DeerFlowContext: dropped 'from langgraph.config import get_config'
  (no longer needed) and changed runtime.context.get("run_id") to
  runtime.context.run_id (typed dataclass access).

- runtime/runs/worker.py: kept the PR's RunContext.app_config field and
  DeerFlowContext construction; passes run_id explicitly into the new
  context so the middleware above can read it.

To bridge the new HumanMessage stamping on release with PR's frozen
DeerFlowContext, this merge also adds a run_id: str | None field to
DeerFlowContext (with matching test + CLAUDE.md doc update). The field
fits the per-invocation-immutable-value-object semantics: run_id is
known at run start and never changes during the run.

Verification: backend test suite — 2372 passed, 4 skipped. One flaky
test (test_client_e2e::test_tool_call_produces_events) passes in
isolation and when its file runs alone; only fails under specific
full-suite ordering. Tracked separately; not introduced by this merge.
2026-04-26 12:30:20 +08:00
greatmengqi
84dccef230 refactor(config): Phase 2 — eliminate AppConfig.current() ambient lookup
Finish Phase 2 of the config refactor: production code no longer calls
AppConfig.current() anywhere. AppConfig now flows as an explicit parameter
down every consumer lane.

Call-site migrations
--------------------
- Memory subsystem (queue/updater/storage): MemoryConfig captured at
  enqueue time so the Timer closure survives the ContextVar boundary.
- Sandbox layer: tools.py, security.py, sandbox_provider.py, local_sandbox_provider,
  aio_sandbox_provider all take app_config explicitly. Module-level
  caching in tools.py's path helpers is removed — pure parameter flow.
- Skills layer: manager.py + loader.py + lead_agent.prompt cache refresh
  all thread app_config; cache worker closes over it.
- Community tools (tavily, jina, firecrawl, exa, ddg, image_search,
  infoquest, aio_sandbox): read runtime.context.app_config.
- Subagents registry: get_subagent_config / list_subagents /
  get_available_subagent_names require app_config.
- Runtime worker: requires RunContext.app_config; no fallback.
- Gateway routers (uploads, skills): add Depends(get_config).
- Channels feishu: uses AppConfig.from_file() (pure) at its sync boundary.
- LangGraph Server bootstrap (make_lead_agent): falls back to
  AppConfig.from_file() — pure load, not ambient lookup.

Context resolution
------------------
- resolve_context(runtime) now raises on non-DeerFlowContext runtime.context.
  Every entry point attaches typed context; dict/None shapes are rejected
  loudly instead of being papered over with an ambient AppConfig lookup.

AppConfig lifecycle
-------------------
- AppConfig.current() kept as a deprecated slot that raises RuntimeError,
  purely so legacy tests that still run `patch.object(AppConfig, "current")`
  don't trip AttributeError at teardown. Production never calls it.
- conftest autouse fixture no longer monkey-patches `current` — it only
  stubs `from_file()` so tests don't need a real config.yaml.

Design refs
-----------
- docs/plans/2026-04-12-config-refactor-plan.md (Phase 2: P2-6..P2-10)
- docs/plans/2026-04-12-config-refactor-design.md §8

All 2338 non-e2e tests pass. Zero AppConfig.current() call sites remain
in backend/packages or backend/app (docstrings in deps.py excepted).
2026-04-17 11:14:13 +08:00
greatmengqi
9040e49e4a refactor(config): eliminate global mutable state, wire DeerFlowContext into runtime 2026-04-15 21:28:15 +08:00