diff --git a/changelog.d/fixed-14678-unowned-gateway-backends.md b/changelog.d/fixed-14678-unowned-gateway-backends.md new file mode 100644 index 0000000000..a69ae847a7 --- /dev/null +++ b/changelog.d/fixed-14678-unowned-gateway-backends.md @@ -0,0 +1 @@ +- A pack agent such as the L2 `reviewer` now follows the hive's inference gateway even when the operator's agents were put on that gateway without a `backend_owner` stamp (set in `hive.yaml`, on a hive older than ownership stamping, or via `POST /api/config/governor/agents`). Before, only operator-owned backends counted, so no gateway was found and the reviewer stayed on copilot. An unowned CLI backend still neither picks nor vetoes the gateway, and `POST /api/config/governor/agents` now stamps an explicitly named backend/model as operator-owned (#14678). diff --git a/src/docs/agent-configuration.md b/src/docs/agent-configuration.md index 636bce3b99..cf773637f4 100644 --- a/src/docs/agent-configuration.md +++ b/src/docs/agent-configuration.md @@ -657,7 +657,7 @@ backends: Names compare case-insensitively; an empty `backend:` (the hive default) is always allowed. The list is enforced where placements are decided: - **ACMM pack apply** never places an agent on a disallowed backend. A pack agent whose pack backend is disallowed gets the first allowed `allow` entry instead (or the hive default when `allow` is empty), without the pack's model, so the replacement backend uses its own default model. A pack-owned agent already on a now-disallowed backend is moved the same way on the next apply. Backends an operator explicitly chose (operator-owned) are left alone. -- **ACMM pack agents follow the hive's inference gateway** ([#14678](https://github.com/hivecommons/hive/issues/14678)). When every backend you picked yourself (operator-owned) names the same inference backend or configured gateway, and more than half of the other enabled agents already run on it, a pack agent whose pack backend is a subscription CLI is placed on that gateway instead, with no `model:` so the gateway's default model applies. This applies to agents a level creates and, on every apply (each restart), to existing agents whose backend is still pack-owned — so after an upgrade the L2 `supervisor`/`brainstorm` may move from `copilot` onto your LiteLLM gateway alongside the new `reviewer`. An operator-owned `backend:` or a legacy `backend:` without an owner is never moved, a hive with an operator-picked CLI agent or with only a minority of agents on a gateway is left as is, and a pack that itself names a gateway or whose backend the `backends:` list replaced is not redirected. +- **ACMM pack agents follow the hive's inference gateway** ([#14678](https://github.com/hivecommons/hive/issues/14678)). When every backend you picked yourself (operator-owned — and any inference backend or gateway name with no `backend_owner`, e.g. one written straight into `hive.yaml`, since a pack never writes one) names the same inference backend or configured gateway, and more than half of the other enabled agents already run on it, a pack agent whose pack backend is a subscription CLI is placed on that gateway instead, with no `model:` so the gateway's default model applies. This applies to agents a level creates and, on every apply (each restart), to existing agents whose backend is still pack-owned — so after an upgrade the L2 `supervisor`/`brainstorm` may move from `copilot` onto your LiteLLM gateway alongside the new `reviewer`. An operator-owned `backend:` or a legacy `backend:` without an owner is never moved, a hive with an operator-picked CLI agent or with only a minority of agents on a gateway is left as is, and a pack that itself names a gateway or whose backend the `backends:` list replaced is not redirected. - **`PUT /api/config/agent/{name}/models`** rejects a placement onto a disallowed backend with `400` and a message naming it. ### Changing backend and model together: use the atomic endpoint diff --git a/src/pkg/dashboard/api_coverage_test.go b/src/pkg/dashboard/api_coverage_test.go index 9645754073..000bf3f625 100644 --- a/src/pkg/dashboard/api_coverage_test.go +++ b/src/pkg/dashboard/api_coverage_test.go @@ -2365,6 +2365,21 @@ func TestHandleGovernorAddAgent_WithModel(t *testing.T) { t.Error("agent not added") } else if agentCfg.Model != "gpt-4" { t.Errorf("model = %q, want gpt-4", agentCfg.Model) + } else if !agentCfg.BackendIsOperatorOwned() || !agentCfg.ModelIsOperatorOwned() { + t.Errorf("backend_owner=%q model_owner=%q, want both operator: the operator named them (#14678)", agentCfg.BackendOwner, agentCfg.ModelOwner) + } +} + +// TestHandleGovernorAddAgent_DefaultBackendUnowned: the "claude" the endpoint +// fills in when no backend is given is not an operator pick. +func TestHandleGovernorAddAgent_DefaultBackendUnowned(t *testing.T) { + s, deps := apiServer(t) + rec := doPost(s, "/api/config/governor/agents", map[string]string{"name": "new-agent"}) + if rec.Code != http.StatusOK { + t.Fatalf("status = %d, want 200", rec.Code) + } + if got := deps.Config.Agents["new-agent"]; got.Backend != "claude" || got.BackendOwner != "" { + t.Errorf("backend=%q owner=%q, want claude with no owner", got.Backend, got.BackendOwner) } } diff --git a/src/pkg/dashboard/api_governor.go b/src/pkg/dashboard/api_governor.go index d8a8c98f92..01e63507a4 100644 --- a/src/pkg/dashboard/api_governor.go +++ b/src/pkg/dashboard/api_governor.go @@ -2712,7 +2712,8 @@ func (s *Server) handleGovernorAddAgent(w http.ResponseWriter, r *http.Request) return } - if body.Backend == "" { + backendPicked := body.Backend != "" + if !backendPicked { body.Backend = "claude" } // Reject an unsupported backend before the agent is created, rather than @@ -2727,6 +2728,15 @@ func (s *Server) handleGovernorAddAgent(w http.ResponseWriter, r *http.Request) Model: body.Model, Enabled: true, } + // A backend the operator named is their pick, like every other dashboard + // backend write: the pack apply on each restart must not move it, and it + // counts when the pack decides which gateway the hive is on (#14678). + if backendPicked { + agentCfg.BackendOwner = config.FieldOwnerOperator + } + if body.Model != "" { + agentCfg.ModelOwner = config.FieldOwnerOperator + } // An explicit re-add is the operator changing their mind, and it is the // only signal that lifts a deletion tombstone. Without this the agent // would be added now and pruned again by the next config reload. diff --git a/src/pkg/dashboard/api_packs.go b/src/pkg/dashboard/api_packs.go index 1302237119..51717f3933 100644 --- a/src/pkg/dashboard/api_packs.go +++ b/src/pkg/dashboard/api_packs.go @@ -1176,22 +1176,42 @@ func (s *Server) hiveAgentBackends() map[string]agentBackendVote { if !agent.Enabled || s.deps.Config.IsAgentRemoved(name) { continue } + backend := strings.TrimSpace(agent.Backend) backends[name] = agentBackendVote{ - backend: strings.TrimSpace(agent.Backend), - operatorOwned: agent.BackendIsOperatorOwned(), - packCLI: agent.BackendIsPackOwned() && config.IsCLIBackend(strings.TrimSpace(agent.Backend)), + backend: backend, + operatorOwned: agent.BackendIsOperatorOwned() || s.unownedGatewayBackend(agent), + packCLI: agent.BackendIsPackOwned() && config.IsCLIBackend(backend), } } return backends } +// 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, +// so an unowned gateway backend is the operator's own choice — set in hive.yaml, +// through an endpoint that does not stamp ownership, or before ownership +// stamping existed. It counts as an operator pick for hiveGatewayBackend +// (#14678): a hive whose operator moved every agent onto LiteLLM that way had +// no operator-owned picks, so no gateway was found and the reviewer stayed on +// copilot. An unowned CLI is not counted either way: it may be a legacy pack +// placement, which must not veto the move it is the subject of. +func (s *Server) unownedGatewayBackend(agent config.AgentConfig) bool { + backend := strings.TrimSpace(agent.Backend) + if agent.BackendOwner != "" || backend == "" { + return false + } + return s.agentOnForeignGatewayBackend(backend, "") +} + // hiveGatewayBackend is the inference gateway the operator moved the hive // onto, or "" when there is no such gateway. The agents considered are the // enabled ones in backends other than except, the pack agent being placed, so // its own placement is not counted against the move. // // The rule, in order: -// 1. Unanimity: the operator-owned backends among those agents must all name +// 1. Unanimity: the operator-owned backends among those agents (including an +// unowned gateway backend, see unownedGatewayBackend) must all name // the same inference backend or configured gateway. Any operator pick of // a subscription CLI, of the hive default or of a different gateway, or no // operator pick at all, yields "". diff --git a/src/pkg/dashboard/pack_gateway_model_test.go b/src/pkg/dashboard/pack_gateway_model_test.go index dcef064141..20074ba669 100644 --- a/src/pkg/dashboard/pack_gateway_model_test.go +++ b/src/pkg/dashboard/pack_gateway_model_test.go @@ -399,3 +399,51 @@ func TestApplyPackRepairsTwoLateAddedPackAgents(t *testing.T) { } } } + +// TestApplyPackFollowsUnownedGatewayBackends covers the #14678 reopen: the +// operator's agents were on the LiteLLM gateway without a backend_owner stamp +// (hive.yaml, a pre-ownership hive, or POST /api/config/governor/agents), so +// no agent counted as an operator pick, no gateway was found, and the L2 +// reviewer stayed on copilot even with the #14777 fix. +func TestApplyPackFollowsUnownedGatewayBackends(t *testing.T) { + srv := gatewayHive(t, "litellm") + for _, name := range []string{"scanner", "quality", "guide"} { + a := srv.deps.Config.Agents[name] + a.BackendOwner = "" + srv.deps.Config.Agents[name] = a + } + srv.deps.Config.Agents["reviewer"] = config.AgentConfig{ + ID: "reviewer", Role: "reviewer", Enabled: true, + Backend: "copilot", BackendOwner: config.FieldOwnerPack, + Model: "claude-fable-5", ModelOwner: config.FieldOwnerPack, + } + 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", got.Backend, got.Model) + } + for _, name := range []string{"scanner", "quality", "guide"} { + if got := srv.deps.Config.Agents[name]; got.Backend != "litellm" || got.BackendOwner != "" { + t.Errorf("%s backend=%q owner=%q, want its unowned litellm left as is", name, got.Backend, got.BackendOwner) + } + } +} + +// TestApplyPackUnownedCLIBackendsDoNotChooseGateway: an unowned CLI backend +// may be a legacy pack placement, so it neither picks a gateway nor vetoes +// one; with only unowned CLI agents there is no gateway to follow. +func TestApplyPackUnownedCLIBackendsDoNotChooseGateway(t *testing.T) { + srv := gatewayHive(t, "copilot") + for _, name := range []string{"scanner", "quality", "guide"} { + a := srv.deps.Config.Agents[name] + a.BackendOwner = "" + srv.deps.Config.Agents[name] = a + } + if _, err := srv.ApplyPack(2); err != nil { + t.Fatalf("ApplyPack(2): %v", err) + } + if got := srv.deps.Config.Agents["reviewer"]; got.Backend == "litellm" { + t.Errorf("reviewer moved onto %q with no gateway picked", got.Backend) + } +}