diff --git a/changelog.d/fixed-14678-reviewer-follows-gateway-override.md b/changelog.d/fixed-14678-reviewer-follows-gateway-override.md new file mode 100644 index 0000000000..0cf9076cc2 --- /dev/null +++ b/changelog.d/fixed-14678-reviewer-follows-gateway-override.md @@ -0,0 +1 @@ +- The ACMM level pack now places the reviewer on the inference gateway the operator moved the other agents onto from the dashboard, instead of leaving it on copilot (#14678). diff --git a/src/pkg/dashboard/api_packs.go b/src/pkg/dashboard/api_packs.go index 2eeafe1832..a4f763608e 100644 --- a/src/pkg/dashboard/api_packs.go +++ b/src/pkg/dashboard/api_packs.go @@ -1173,6 +1173,16 @@ type agentBackendVote struct { // hiveAgentBackends snapshots the backend of every enabled agent, keyed by // name, for hiveGatewayBackend. +// +// An agent's backend is the one it actually runs on: a live BackendOverride +// wins over its config backend, exactly as the dashboard's agent cards and +// config dialog show it (#14678). The override is replayed from +// /data/hive-state.json before the boot-time pack apply, so a hive whose +// operator moved scanner/quality/guide onto LiteLLM through an override saw +// LiteLLM on every card while this vote still read their pack-owned copilot +// config backend, found no gateway, and left the reviewer on copilot. An +// override differing from the config backend is an explicit placement, so it +// counts as an operator pick. func (s *Server) hiveAgentBackends() map[string]agentBackendVote { backends := map[string]agentBackendVote{} for name, agent := range s.deps.Config.Agents { @@ -1180,15 +1190,32 @@ func (s *Server) hiveAgentBackends() map[string]agentBackendVote { continue } backend := strings.TrimSpace(agent.Backend) - backends[name] = agentBackendVote{ + vote := agentBackendVote{ backend: backend, operatorOwned: agent.BackendIsOperatorOwned() || s.unownedGatewayBackend(agent), packCLI: agent.BackendIsPackOwned() && config.IsCLIBackend(backend), } + if override := s.agentBackendOverride(name); override != "" && !strings.EqualFold(override, backend) { + vote = agentBackendVote{backend: override, operatorOwned: true} + } + backends[name] = vote } return backends } +// agentBackendOverride is name's live BackendOverride, or "" when the agent +// has none or is not in the manager's process table. +func (s *Server) agentBackendOverride(name string) string { + if s.deps.AgentMgr == nil { + return "" + } + proc, err := s.deps.AgentMgr.GetStatus(name) + if err != nil || proc == nil { + return "" + } + return strings.TrimSpace(proc.BackendOverride) +} + // unownedGatewayBackend reports whether agent sits on an inference backend or // configured gateway with no backend_owner stamp. A pack only ever writes a // subscription CLI, and stamps a gateway it moved an agent onto as pack-owned, diff --git a/src/pkg/dashboard/pack_gateway_model_test.go b/src/pkg/dashboard/pack_gateway_model_test.go index 20074ba669..e86946904c 100644 --- a/src/pkg/dashboard/pack_gateway_model_test.go +++ b/src/pkg/dashboard/pack_gateway_model_test.go @@ -447,3 +447,44 @@ func TestApplyPackUnownedCLIBackendsDoNotChooseGateway(t *testing.T) { t.Errorf("reviewer moved onto %q with no gateway picked", got.Backend) } } + +// TestApplyPackFollowsGatewayBackendOverrides covers the second #14678 reopen: +// the operator's agents ran on LiteLLM through a live BackendOverride (replayed +// from hive-state.json before the boot-time pack apply) while their config +// backend was still the pack's copilot. The dashboard showed LiteLLM on every +// card, but the pack read only the config backend, found no gateway, and kept +// the L2 reviewer on copilot. +func TestApplyPackFollowsGatewayBackendOverrides(t *testing.T) { + for _, tt := range []struct { + name string + reviewer *config.AgentConfig + }{ + {"reviewer created by the level", nil}, + {"pack-owned copilot reviewer repaired", &config.AgentConfig{ + ID: "reviewer", Role: "reviewer", Enabled: true, + Backend: "copilot", BackendOwner: config.FieldOwnerPack, + Model: "claude-fable-5", ModelOwner: config.FieldOwnerPack, + }}, + } { + t.Run(tt.name, func(t *testing.T) { + srv := newFullServer(t) + for _, name := range []string{"scanner", "quality", "guide"} { + a := packCLIAgent(name) + srv.deps.Config.Agents[name] = a + srv.deps.AgentMgr.AddAgent(name, a) + if err := srv.deps.AgentMgr.SetBackendOverride(name, "litellm"); err != nil { + t.Fatalf("SetBackendOverride(%s): %v", name, err) + } + } + if tt.reviewer != nil { + srv.deps.Config.Agents["reviewer"] = *tt.reviewer + } + if _, err := srv.ApplyPack(2); err != nil { + t.Fatalf("ApplyPack(2): %v", err) + } + if got := srv.deps.Config.Agents["reviewer"]; got.Backend != "litellm" || got.Model != "" { + t.Errorf("reviewer backend=%q model=%q, want litellm with no model like the agents the operator moved", got.Backend, got.Model) + } + }) + } +}