Skip to content

refactor: split server application and execution orchestration#378

Merged
liujuanjuan1984 merged 2 commits intomainfrom
chore/374-375-modularization-review
Apr 2, 2026
Merged

refactor: split server application and execution orchestration#378
liujuanjuan1984 merged 2 commits intomainfrom
chore/374-375-modularization-review

Conversation

@liujuanjuan1984
Copy link
Copy Markdown
Collaborator

@liujuanjuan1984 liujuanjuan1984 commented Apr 2, 2026

背景

  • 实施 #374,收敛 server.application 的 app 装配、middleware 与 runtime 资源生命周期边界
  • 实施 #375,收敛 execution.executor 的执行协调与 tool orchestration 边界
  • 保持现有对外行为、测试契约与兼容导出面不变,优先做最小可验证拆分

Server 模块拆分

  • 新增 src/opencode_a2a/server/client_manager.py,迁出 A2AClientManager
  • 新增 src/opencode_a2a/server/middleware.py,集中 auth、agent card cache、request body guard、payload logging 等 HTTP middleware
  • 新增 src/opencode_a2a/server/lifespan.py,迁出 runtime lifespan 初始化与清理逻辑
  • src/opencode_a2a/server/application.py 收敛为更明确的 composition root,并保留既有常量与导出表面

Execution 模块拆分

  • 新增 src/opencode_a2a/execution/coordinator.py,迁出 ExecutionCoordinatorPreparedExecution 与 session binding context 构造逻辑
  • 新增 src/opencode_a2a/execution/tool_orchestration.py,迁出 A2A tool call 探测、执行与 streamed output merge 逻辑
  • 新增 src/opencode_a2a/execution/metrics.py,收敛 metric log helper
  • src/opencode_a2a/execution/executor.py 保留 OpencodeAgentExecutor 对外适配面,并以薄包装维持历史 helper export / method surface

Compatibility

  • 保持 server payload logging 与 execution metric log 的既有 logger surface,不在本 PR 中改变现有观测面契约
  • 保持 execution.executor 的历史 helper export 兼容,避免测试面与现有内部调用在本轮拆分中漂移

Tests

  • 更新 tests/server/test_a2a_client_manager.py,把 client manager 测试边界对齐到新模块
  • 更新 tests/execution/test_opencode_agent_session_binding.py,把直接依赖的 client manager 引用切到新模块
  • 执行 ./scripts/doctor.sh
  • 结果:478 passed,总覆盖率 91.39%

Issue 关联

@liujuanjuan1984 liujuanjuan1984 changed the title refactor: modularize server and execution internals refactor: split server application and execution orchestration Apr 2, 2026
@liujuanjuan1984
Copy link
Copy Markdown
Collaborator Author

本轮已基于 PR diff 完成自审,结论如下。

代码变动审查

  • 未发现阻塞性问题。
  • #374 的实现方向是合理的:server.application 现在明显更接近 composition root,A2AClientManager、HTTP middleware、lifespan 资源清理边界都被迁到了更自然的模块里,后续继续做 #371 / #376 时,不再需要在同一个千行文件里同时改装配和中间件逻辑。
  • #375 的实现方式也是稳健的:ExecutionCoordinator、tool orchestration、metric helper 都迁出了 executor.py,而 OpencodeAgentExecutor 仍保留为对外适配层,符合“先拆内部职责,不改外部行为”的目标。
  • 兼容性处理是本 PR 的一个优点:保留了 execution.executor 的历史 helper export,以及 payload logging / metric log 的既有 logger surface,避免这轮重构顺手改变测试与观测面契约。
  • 当前没有看到对需求的明显偏差、遗漏或冗余实现;拆分粒度控制在合理范围内,没有演变成额外抽象层堆叠。

风险与残余观察

  • 本 PR 仍保留了一层兼容导出与兼容 logger 路径,这是有意为之,不是设计残留。它的代价是 executor.py 还承担一部分历史 export hub 角色,但这比在同一轮重构里顺手改变导入面更稳妥。
  • 后续如果继续做 #371#376#277,建议继续沿着新模块边界演进,而不是回到 application.py / executor.py 中追加逻辑。

PR 标题与描述审查

  • 当前标题 refactor: split server application and execution orchestration 与代码主线一致,采用了英文 commit message 风格,准确性比初版更高。
  • 当前描述已按 Server 模块拆分Execution 模块拆分CompatibilityTests 分区,能够覆盖本 PR 的主要代码与验证动作,结构清晰。

Issue 关联审查

  • Closes #374 准确。
  • Closes #375 准确。
  • Related #367 也准确;#367 仍是 umbrella issue,不应由本 PR 关闭。
  • 目前没有发现需要修正的 related / closes 关系。

结论

  • 当前 PR 的改动是合理且稳健的,可以进入正常评审流程。

@liujuanjuan1984 liujuanjuan1984 marked this pull request as ready for review April 2, 2026 11:55
@liujuanjuan1984 liujuanjuan1984 merged commit 2b10c47 into main Apr 2, 2026
3 checks passed
@liujuanjuan1984 liujuanjuan1984 deleted the chore/374-375-modularization-review branch April 2, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant