fix(dispatcher,mcp-go): 配置拉取改为后台重试,根治启动竞态
此前 dispatcher(chat)/mcp-go(embedding) 启动时一次性请求控制面配置,3s 扑空即 降级,且只能干等热更新广播——若消费方早于 gateway 启动,会全程降级(LLM 跑桩、 RAG 无向量),必须手动重启才恢复。 改为:先订阅热更新,再后台 RequestConfigWithRetry(重试至拿到配置,容忍 gateway 晚启)。新增 shared/bus.RequestConfigWithRetry + dispatcher Subscriber 包装。 验收:故意先起 dispatcher/mcp-go、后起 gateway,二者自动重试拿到 chat/embedding 配置,无需手动重启;make test-go 全绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
sharedbus "github.com/sundynix/sundynix-shared/bus"
|
||||
"github.com/sundynix/sundynix-shared/contract"
|
||||
@@ -70,22 +69,16 @@ func main() {
|
||||
ragEngine.SetChat(cfg.BaseURL, cfg.APIKey, cfg.Model)
|
||||
}
|
||||
}
|
||||
cctx, ccancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
if cfg, _ := b.RequestConfig(cctx, contract.ConfigKindEmbedding); cfg != nil {
|
||||
applyEmbed(cfg)
|
||||
} else {
|
||||
log.Println("[mcp_go] 未取到 embedding 控制面配置(用 env 或降级)")
|
||||
}
|
||||
if cfg, _ := b.RequestConfig(cctx, contract.ConfigKindChat); cfg != nil {
|
||||
applyChat(cfg)
|
||||
}
|
||||
ccancel()
|
||||
// 先订阅热更新(控制台改配置即生效)。
|
||||
if _, err := b.SubscribeConfigUpdated(contract.ConfigKindChat, applyChat); err != nil {
|
||||
log.Printf("[mcp_go] subscribe chat config: %v", err)
|
||||
}
|
||||
if _, err := b.SubscribeConfigUpdated(contract.ConfigKindEmbedding, applyEmbed); err != nil {
|
||||
log.Printf("[mcp_go] subscribe embedding config: %v", err)
|
||||
}
|
||||
// 后台重试拉初始配置:容忍 gateway 晚于本服务启动(避免一次性扑空致 RAG 长期降级)。
|
||||
go b.RequestConfigWithRetry(ctx, contract.ConfigKindEmbedding, applyEmbed)
|
||||
go b.RequestConfigWithRetry(ctx, contract.ConfigKindChat, applyChat)
|
||||
|
||||
gw := mcp.NewGateway(b, engine, mem, hist, ragEngine)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user