fix(llm): Agent 绑定优先于任务 LLM 配置链

任务内各角色解析 LLM 的顺序由「任务链 → Agent 绑定 → 全局」改为
「Agent 绑定 → 任务链 → 全局」:显式绑定了模型的角色始终跑在该模型上,
未绑定的角色才落到任务链,任务链为空时再落到全局配置。

- 拆分 fallbackProviderForAgent 为 agentBindingProvider / globalProvider,
  让三个层级可按新顺序自由组合
- current()、CompactionWindow()、taskRuntimeAvailable() 统一按新顺序解析;
  taskRuntimeAvailable 改为逐角色判断,有可用绑定的角色在任务链耗尽时仍可运行
- resolveTaskRoleLLM(UI 展示)与前端 mock 同步对调,避免显示与实际调用不一致

保留两处既有语义:绑定/全局路径仍返回 profileID=0,不推进任务链故障转移
(绑定自身的转移仍由 poolForBinding + llm_pool_bind_fallback 负责);未绑定
角色遇到任务链耗尽仍是硬停止,不静默降级到全局。

Claude-Session: https://claude.ai/code/session_01Q8nhYZfS4H8fsSCBJXxbSy
This commit is contained in:
Autumn-27 committed 2026-08-22 06:14:18 -04:00
1 parent 476a44577c
commit adc8e3521d
5 files changed
+175 -49

No files matched your search

+69
View File
@@ -571,6 +571,75 @@ func TestTaskLLMResolutionRejectsInvalidExplicitProfile(t *testing.T) {
}
}
// An Agent binding outranks the task's LLM chain; roles left unbound keep using
// the chain, so binding one role does not move the others off it.
func TestTaskLLMResolutionPrefersAgentBindingOverTaskChain(t *testing.T) {
m, err := NewManager(t.TempDir(), "")
if err != nil {
t.Skipf("postgres unavailable (%v) - skipping", err)
}
defer m.Close()
stamp := time.Now().UnixNano()
boundID, err := m.pg.SaveProfile(&db.LLMProfile{
Name: fmt.Sprintf("bound-resolution-%d", stamp), Format: "openai",
Model: "bound-model", APIKey: "test-key",
})
if err != nil {
t.Fatal(err)
}
chainID, err := m.pg.SaveProfile(&db.LLMProfile{
Name: fmt.Sprintf("chain-resolution-%d", stamp), Format: "openai",
Model: "chain-model", APIKey: "test-key",
})
if err != nil {
_ = m.pg.DeleteProfile(boundID)
t.Fatal(err)
}
task, err := m.CreateTaskWithOptions("binding precedence", "prefer the bound profile", db.TaskCreateOptions{
LLMProfileIDs: []int64{chainID},
})
if err != nil {
_ = m.pg.DeleteProfile(boundID)
_ = m.pg.DeleteProfile(chainID)
t.Fatal(err)
}
defer func() {
_, _ = m.DeleteTask(task.ID, DeleteTaskOptions{})
_ = m.pg.SetAgentLLMProfile("worker", nil)
_ = m.pg.DeleteProfile(boundID)
_ = m.pg.DeleteProfile(chainID)
}()
s := &Server{m: m, provByProfile: map[int64]*provEntry{}}
got, err := s.resolveTaskRoleLLM(task, "worker")
if err != nil {
t.Fatal(err)
}
if got.Source != "task_chain" || got.Model != "chain-model" {
t.Fatalf("resolution=%+v, want the task chain while no binding exists", got)
}
if err := m.pg.SetAgentLLMProfile("worker", &boundID); err != nil {
t.Fatal(err)
}
got, err = s.resolveTaskRoleLLM(task, "worker")
if err != nil {
t.Fatal(err)
}
if !got.Available || got.Source != "agent_binding" || got.Model != "bound-model" {
t.Fatalf("resolution=%+v, want the agent binding to outrank the task chain", got)
}
got, err = s.resolveTaskRoleLLM(task, "planner")
if err != nil {
t.Fatal(err)
}
if got.Source != "task_chain" || got.Model != "chain-model" {
t.Fatalf("resolution=%+v, want an unbound role to keep using the task chain", got)
}
}
func TestTaskLLMResolutionReportsDatabaseFailure(t *testing.T) {
m, err := NewManager(t.TempDir(), "")
if err != nil {