fix(worker): 固定异步准入候选避免执行槽空转

异步任务在调度器准入后,Worker 会再次按实时负载排序候选;排序变化会让已准入任务退回 waiting,同时继续占用 River 执行槽,导致高并发吞吐塌陷。

执行前复用已持久化的 admitted 候选并稳定置顶,候选失效时仍保留原有重选路径;增加候选固定与非准入场景单测。

验证:Go 全量测试、runner race、go vet、OpenAPI 生成一致性、迁移安全检查通过。
This commit is contained in:
2026-07-31 07:06:06 +08:00
parent 3d9ae74b87
commit 238798e47c
3 changed files with 109 additions and 10 deletions
@@ -61,3 +61,57 @@ func TestAcceptanceAdmissionScopesLeaveProductionPolicyUnchanged(t *testing.T) {
t.Fatalf("production admission policy changed: %+v", got[0])
}
}
func TestPinCandidatesToTaskAdmissionPreservesAdmittedCandidate(t *testing.T) {
input := []store.RuntimeModelCandidate{
{PlatformID: "platform-a", PlatformModelID: "model-a"},
{PlatformID: "platform-b", PlatformModelID: "model-b"},
{PlatformID: "platform-c", PlatformModelID: "model-c"},
}
admission := &store.TaskAdmission{
Status: "admitted",
PlatformID: "platform-b",
PlatformModelID: "model-b",
}
got, pinned := pinCandidatesToTaskAdmission(input, admission)
if !pinned {
t.Fatal("expected admitted candidate to be pinned")
}
if got[0].PlatformModelID != "model-b" || got[1].PlatformModelID != "model-a" || got[2].PlatformModelID != "model-c" {
t.Fatalf("unexpected candidate order: %+v", got)
}
if input[0].PlatformModelID != "model-a" {
t.Fatalf("candidate pinning mutated the caller slice: %+v", input)
}
}
func TestPinCandidatesToTaskAdmissionIgnoresWaitingOrMissingCandidate(t *testing.T) {
input := []store.RuntimeModelCandidate{
{PlatformID: "platform-a", PlatformModelID: "model-a"},
{PlatformID: "platform-b", PlatformModelID: "model-b"},
}
for name, admission := range map[string]*store.TaskAdmission{
"waiting": {
Status: "waiting",
PlatformID: "platform-b",
PlatformModelID: "model-b",
},
"missing": {
Status: "admitted",
PlatformID: "platform-c",
PlatformModelID: "model-c",
},
} {
t.Run(name, func(t *testing.T) {
got, pinned := pinCandidatesToTaskAdmission(input, admission)
if pinned {
t.Fatalf("unexpected candidate pin for %s: %+v", name, got)
}
if got[0].PlatformModelID != "model-a" {
t.Fatalf("candidate order changed for %s: %+v", name, got)
}
})
}
}