Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-14678-unowned-gateway-backends.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion src/docs/agent-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/pkg/dashboard/api_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/pkg/dashboard/api_governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
28 changes: 24 additions & 4 deletions src/pkg/dashboard/api_packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "".
Expand Down
48 changes: 48 additions & 0 deletions src/pkg/dashboard/pack_gateway_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading