Skip to content

refactor(hub): dispatch 家族收敛为 dispatchsvc 包并去 Setter 装配 - #1671

Open
DeliciousBuding wants to merge 1 commit into
masterfrom
refactor/hub-dispatchsvc
Open

refactor(hub): dispatch 家族收敛为 dispatchsvc 包并去 Setter 装配#1671
DeliciousBuding wants to merge 1 commit into
masterfrom
refactor/hub-dispatchsvc

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

Summary

hub Top 1:agent_dispatch 8 文件散装(~1500 行)从平铺 service 包收敛到 internal/service/dispatchsvc

  1. 包边界:DispatchService 家族整体平移(git mv 保留历史),DispatchTask / RedispatchDelivery 显式导出作为跨包缝;AgentService 对外 API 不变(handler/app 层零改动)。
  2. 传输层去耦(hub Top 3 联动):ManagerPort/ConnPort/FramePort/DeliveryResultPort 取代直接引用 *ws.Conn/ws.Frame/ws.DeliveryResult 的 dispatchWS 端口——dispatchsvc 不再 import internal/ws;service 层新增 wsManagerAdapter 映射。RelayPort(仅返回 error)取代 relayDispatcher,relayServiceAdapter 丢弃 dispatch 不消费的命令元数据。
  3. 装配收敛:删除 DispatchService 的 5 个 Setter(SetBus/SetCache/SetManager/SetOutbox/SetRelay,零生产调用点),构造函数一次性注入。
  4. 归属收拢resolveDispatchCache/isNilCache/redispatchTarget 随家族迁入 dispatchsvc;dispatchRedispatcher 适配器走导出 RedispatchDelivery 缝。
  5. 测试随迁:breaker/edge_http 测试与端口 mock 迁入 dispatchsvc 包(白盒访问保留),service 侧集成测试改用导出缝。

lint 欠账顺带清偿:auth_test.go 夹具变量重命名消除 G101(#1670 清偿后从 max-same-issues 封顶浮出的下一处);hub-lint-baseline 对移动的 gocognit 条目做外科式路径更新(2 行 diff,刻意不整表重建——本地 Windows lint 输出与 CI 基线环境有差异,见 Wave-10 注释)。

Test plan

  • go build / go vet / staticcheck 全绿
  • go test ./... -count=1 -short -race -coverprofile 通过(CI 同款);dispatchsvc 包全过
  • 门禁:hub-layering / hub-pure-packages / outbound-hygiene / dto / openapi / lint-ratchet 全部 PASS;git diff --check 干净

后续队列(依赖本 PR 的收尾)

  • AgentService 懒门面(dispatchService()/deliveryOutboxService()/runEventService())删除——需要把 ~60 处测试结构体字面量改为构造装配,单独立项
  • app/events.go pending 重放下沉(hub Top 2)
  • DispatchTask 复杂度 98 拆分(gocognit 记账在案,随下一步路由拆解一并偿还)

hub Top 1:agent_dispatch 8 文件散装(~1500 行)从平铺 service 包
收敛到 internal/service/dispatchsvc:

1. 包边界:DispatchService 家族整体平移(git mv 保留历史),
   DispatchTask / RedispatchDelivery 显式导出作为跨包缝,AgentService
   保持原有对外 API 不变(handler/app 层零改动)。

2. 传输层去耦(hub Top 3 联动):
   - ManagerPort/ConnPort/FramePort/DeliveryResultPort 取代原来直接
     引用 *ws.Conn / ws.Frame / ws.DeliveryResult 的 dispatchWS 端口,
     dispatchsvc 不再 import internal/ws;service 层新增 wsManagerAdapter
     完成映射。
   - RelayPort(CreateCommand 仅返回 error)取代 relayDispatcher,
     relayServiceAdapter 丢弃 dispatch 不消费的命令元数据。

3. 装配收敛:删除 DispatchService 的 5 个 Setter(SetBus/SetCache/
   SetManager/SetOutbox/SetRelay,零生产调用点),构造函数一次性注入;
   端口组合测试改写为构造注入断言。

4. 归属收拢:resolveDispatchCache/isNilCache、redispatchTarget 随家族
   迁入 dispatchsvc;dispatchRedispatcher 适配器走导出 RedispatchDelivery
   缝。

5. 测试随迁:breaker/edge_http 测试与端口 mock 迁入 dispatchsvc 包
   (白盒访问保留),service 侧集成测试改用导出缝。

lint 欠账顺带清偿:auth_test.go 夹具变量重命名消除 G101(#1670 清偿
后从 max-same-issues 封顶浮出的下一处);hub-lint-baseline 对移动的
gocognit 条目做外科式路径更新(2 行 diff,不整表重建以保持 CI 环境
基线稳定)。

验证:go build/vet/staticcheck 全绿;go test ./... -short -race 通过;
hub-layering / hub-pure-packages / outbound-hygiene / dto / openapi /
lint-ratchet 全部 PASS;git diff --check 干净。

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
Copilot AI lite review requested due to automatic review settings August 13, 2026 04:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@DeliciousBuding, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 41623202-a327-44eb-b7db-94991f20d1f5

📥 Commits

Reviewing files that changed from the base of the PR and between ca41223 and cb4244a.

📒 Files selected for processing (25)
  • hub-server/internal/middleware/auth_test.go
  • hub-server/internal/service/agent.go
  • hub-server/internal/service/agent_dispatch_facade.go
  • hub-server/internal/service/agent_logic_test.go
  • hub-server/internal/service/agent_test.go
  • hub-server/internal/service/cache_fallback.go
  • hub-server/internal/service/cache_fallback_test.go
  • hub-server/internal/service/delivery_outbox_model.go
  • hub-server/internal/service/delivery_outbox_retry.go
  • hub-server/internal/service/delivery_outbox_test.go
  • hub-server/internal/service/dispatch_adapters.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_breaker.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_breaker_test.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_context.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_edge_http.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_edge_http_test.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_lifecycle.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_ports.go
  • hub-server/internal/service/dispatchsvc/agent_dispatch_target_bound.go
  • hub-server/internal/service/dispatchsvc/cache_port.go
  • hub-server/internal/service/dispatchsvc/cache_port_test.go
  • hub-server/internal/service/dispatchsvc/doc.go
  • hub-server/internal/service/dispatchsvc/ports_test.go
  • scripts/verify/hub-lint-baseline.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

2 participants