Skip to content

refactor(runtime): add run DDD boundary skeleton#3331

Open
rayhpeng wants to merge 2 commits into
mainfrom
codex/refactor-run-runtime-ddd-boundaries
Open

refactor(runtime): add run DDD boundary skeleton#3331
rayhpeng wants to merge 2 commits into
mainfrom
codex/refactor-run-runtime-ddd-boundaries

Conversation

@rayhpeng
Copy link
Copy Markdown
Collaborator

@rayhpeng rayhpeng commented Jun 1, 2026

背景

这是 Run Runtime DDD 重构的第一步。本 PR 先建立 deerflow.runtime.runs 内部的分层结构和领域模型骨架,为后续拆分 Application、Repository、Stream、Execution 以及移动 app infrastructure 实现做准备。

本 PR 不迁移 SQL、Gateway 装配或现有 API 行为。

修改内容

  • 新增 deerflow.runtime.runs.domain

    • 增加 Run 聚合根。
    • 增加 RunStatusDisconnectModeRunScopeEventSeq 等领域值对象。
    • 增加 RunCreatedRunStartedRunCompletedRunFailedRunCancelled 等领域事件。
    • 增加 InvalidRunTransition,显式约束 Run 状态流转。
  • 新增 DDD 分层骨架

    • application/:命令、查询、DTO、RunsApplicationService 边界。
    • repositories/RunRepositoryRunEventLog 协议。
    • streams/RunStreamBroker 协议。
    • execution/RunExecutionSchedulerRunSupervisorRunExecutor 协议。
  • 保持兼容导出

    • runtime/runs/schemas.py 继续导出 RunStatusDisconnectMode,但来源切换为 domain。
    • runtime/runs/__init__.py 增加新的 domain 类型导出。
    • 现有 RunManagerRunRecordrun_agent 路径保持不变。
  • 新增领域测试

    • 覆盖 Run 创建事件。
    • 覆盖 pending -> running -> success 状态流转。
    • 覆盖失败、取消事件。
    • 覆盖终态不可再次流转。
    • 覆盖 EventSeq 和空 ID 校验。

不包含

  • 不移动 deerflow.persistence 中的 SQL 实现。
  • 不改 Gateway API 行为。
  • 不替换现有 RunManager 执行路径。
  • 不迁移 stream_bridgeRunStreamBroker,只先定义新协议边界。

验证

已通过:

  • uv run ruff check packages/harness/deerflow/runtime/runs tests/test_run_domain.py
  • uv run pytest tests/test_run_domain.py tests/test_run_manager.py
  • git diff --check

结果:51 passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant