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
2 changes: 2 additions & 0 deletions changelog.d/fixed-18804-overlay-review-sandbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Kubernetes: a reload that starts from the ConfigMap seed (a first boot or reprovision on a read-only ConfigMap mount, `hive config-check`, a watcher reload of the seed path) dropped the dashboard-saved `review` block (`combined_perspectives`, `require_labels`, `perspectives_source`) and `agent_sandbox` block (`image`, `job.*`), the same shape as the cadence and work-source losses. The dashboard overlay now wins for both blocks when it carries them, and a silent overlay leaves the seed's untouched. `variables.security` stays seed-only (#18804).
- Kubernetes: a `paused: true` or `sandbox:` block an operator put in `/data/agent-configs/<name>.yaml` was replaced by the dashboard overlay's older copy of the same agent on every load that applies the overlay, so it never took effect. Those two fields are now carried forward from the agent file (#18804).
2 changes: 2 additions & 0 deletions src/docs/agent-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ During the Kubernetes **seed-plus-overlay fallback** only:
| `acmm_level` | Overlay when present; seed is a fallback, not an unconditional platform override |
| `hub.is_public` | Seed when set; the hosting hub can also reassert publication policy by heartbeat |
| GitHub App credentials | Overlay, except a real installed App in the seed is protected against a placeholder overlay wiping it |
| `review` and `agent_sandbox` blocks | Overlay when it carries the block (adopted whole, on boot and on every reload that starts from the seed); the seed is the fallback only when the overlay has none |
| `variables.security` | Seed only. The overlay's `variables` block is never adopted |

For example, changing `acmm_level` in the ConfigMap of a hive with a runtime file will not apply a new pack on restart. Use the dashboard's pack controls or the hosting hub's supported controls instead. Public-hosting policy remains the hosting administrator's responsibility, not an arbitrary agent setting.

Expand Down
2 changes: 2 additions & 0 deletions src/docs/config-layering.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Three documented exceptions where a lower layer affects the result:

Everything else: the highest layer that sets the field wins.

On a Kubernetes load that applies the dashboard overlay, the overlay's `agents.<name>` entry replaces the per-agent file's entry, except that a `paused: true` and a `sandbox:` block in `/data/agent-configs/<agent>.yaml` are carried forward over it (`/api/config/provenance` names that file as `agent-overlay`); an explicit overlay `converse` still wins. To unpause, use the dashboard, which writes both layers. The `review` and `agent_sandbox` blocks and every other top-level block are not per-agent and come from the dashboard overlay (`/data/hive.yaml.dashboard`) over the seed.

## The ConfigMap decides almost nothing, and nothing can write it

This is the most important and least obvious fact about the system.
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6270,6 +6270,24 @@ func loadWithDashboardOverlay(path string, validateOpts ValidateOptions) (*Confi
// pack apply saw nothing to respect. Adopt them BEFORE the fullness guard,
// like WorkSource, so a short overlay still carries them.
adoptOperatorCadenceOverrides(cfg, &overlay)
// Review gate and agent sandbox (#18804): the dashboard saves both into
// the overlay (the Config marshals whole), but this reload used to rebuild
// them from the seed alone, so a reload that starts from the seed (the
// read-only ConfigMap mount on a first boot or reprovision, config-check,
// a watcher reload of the seed path) silently dropped
// review.combined_perspectives, review.require_labels,
// review.perspectives_source and agent_sandbox.image/job.*, the same shape
// as #5632 and the work source. Adopt each block whole when the overlay
// carries it, BEFORE the fullness guard so a short overlay still wins; an
// overlay that says nothing leaves the seed's block untouched. This is the
// same overlay-wins rule the entrypoint's boot merge applies to every
// block. Variables stays seed-only (see the invariant below).
if !reflect.DeepEqual(overlay.Review, ReviewConfig{}) {
cfg.Review = overlay.Review
}
if !reflect.DeepEqual(overlay.AgentSandbox, cruxconfig.AgentSandboxConfig{}) {
cfg.AgentSandbox = overlay.AgentSandbox
}
if len(overlay.RemovedAgents) > 0 {
cfg.RemovedAgents = overlay.RemovedAgents
cfg.PruneRemovedAgents()
Expand Down Expand Up @@ -6315,6 +6333,34 @@ func loadWithDashboardOverlay(path string, validateOpts ValidateOptions) (*Confi
for name := range agents {
cfg.ApplyAgentDefaults(name)
}
// Per-agent files (/data/agent-configs/<name>.yaml) are the higher layer
// (config-layering.md), but the whole-entry replacement above buried them
// under the overlay's older copy of the same agent, so an operator's
// `paused: true` or `sandbox:` block in the agent file never took effect
// while the overlay and runtime config still said otherwise (#18804). Carry
// those two operator-owned fields forward from the file. Not the whole
// entry: an explicit overlay `converse: false` deliberately beats the file
// (#7503), and pack-reconciled fields live in the overlay. `paused: false`
// in a file is indistinguishable from unset, so only a pause is carried;
// unpause through the dashboard, which writes both layers.
if cfg.Data.AgentsDir != "" {
if files, ferr := LoadAgentOverrides(cfg.Data.AgentsDir); ferr == nil {
for name, fa := range files {
a, ok := cfg.Agents[name]
if !ok || cfg.IsAgentRemoved(name) {
continue
}
if fa.Paused {
a.Paused = true
a.PauseOwner = fa.PauseOwner
}
if fa.Sandbox != nil {
a.Sandbox = fa.Sandbox
}
cfg.Agents[name] = a
}
}
}
if err := cfg.ApplyAgentSpecRepoScopes(); err != nil {
return cfg, err
}
Expand Down
211 changes: 211 additions & 0 deletions src/pkg/config/overlay_review_sandbox_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
package config

import (
"os"
"path/filepath"
"testing"
)

// overlayReviewSandboxSeed is a ConfigMap seed carrying a review gate and an
// agent sandbox that differ from what the dashboard later saved (#18804).
const overlayReviewSandboxSeed = `
project:
org: testorg
repos: [repo1]
github:
token: ghp_test123456789
agents:
scanner:
backend: copilot
model: claude-sonnet-4-6
review:
combined_perspectives: false
require_labels: [seed-label]
max_parallel_reviews: 3
agent_sandbox:
enabled: false
image: seed/image:1
job:
workspace_claim: seed-claim
`

// overlayReviewSandboxOverlay is a short overlay (no agents) as the dashboard
// leaves it, so the fullness guard would bail and the blocks must be adopted
// regardless.
const overlayReviewSandboxOverlay = `
project:
org: testorg
repos: [repo1]
review:
combined_perspectives: true
require_labels: [overlay-label]
max_parallel_reviews: 3
perspectives_source:
owner: testorg
repo: perspectives
path: perspectives.yaml
ref: main
agent_sandbox:
enabled: true
image: overlay/image:2
job:
workspace_claim: overlay-claim
ttl_seconds: 120
`

func setupOverlayReviewSandbox(t *testing.T, seed, overlay string) string {
t.Helper()
dir := t.TempDir()
seedPath := filepath.Join(dir, "hive.yaml")
if err := os.WriteFile(seedPath, []byte(seed), 0o644); err != nil {
t.Fatal(err)
}
overlayPath := filepath.Join(dir, "hive.yaml.dashboard")
if err := os.WriteFile(overlayPath, []byte(overlay), 0o644); err != nil {
t.Fatal(err)
}
orig := DashboardOverlayFile
DashboardOverlayFile = overlayPath
t.Cleanup(func() { DashboardOverlayFile = orig })
t.Setenv("KUBERNETES_SERVICE_HOST", "10.0.0.1")
return seedPath
}

// TestLoadWithDashboardOverlay_AdoptsReviewAndAgentSandbox: every reload entry
// point (the agent loader, the hub loader) must let the overlay win for the
// review gate and the agent sandbox, and keep the rest of the seed.
func TestLoadWithDashboardOverlay_AdoptsReviewAndAgentSandbox(t *testing.T) {
seedPath := setupOverlayReviewSandbox(t, overlayReviewSandboxSeed, overlayReviewSandboxOverlay)
loaders := map[string]func(string) (*Config, error){
"LoadWithDashboardOverlay": LoadWithDashboardOverlay,
"LoadWithDashboardOverlayForHub": LoadWithDashboardOverlayForHub,
}
for name, load := range loaders {
t.Run(name, func(t *testing.T) {
merged, err := load(seedPath)
if err != nil {
t.Fatalf("%s: %v", name, err)
}
if !merged.Review.CombinedPerspectives {
t.Errorf("review.combined_perspectives lost: overlay true, got false")
}
if got := merged.Review.RequireLabels; len(got) != 1 || got[0] != "overlay-label" {
t.Errorf("review.require_labels = %v, want [overlay-label]", got)
}
ps := merged.Review.PerspectivesSource
if ps == nil || ps.Repo != "perspectives" || ps.Path != "perspectives.yaml" {
t.Errorf("review.perspectives_source lost: %+v", ps)
}
if !merged.AgentSandbox.Enabled {
t.Errorf("agent_sandbox.enabled lost: overlay true, got false")
}
if merged.AgentSandbox.Image != "overlay/image:2" {
t.Errorf("agent_sandbox.image = %q, want overlay/image:2", merged.AgentSandbox.Image)
}
job := merged.AgentSandbox.Job
if job == nil || job.WorkspaceClaim != "overlay-claim" || job.TTLSeconds != 120 {
t.Errorf("agent_sandbox.job lost: %+v", job)
}
// The rest of the seed is intact.
if merged.Project.Org != "testorg" || merged.GitHub.Token != "ghp_test123456789" {
t.Errorf("seed project/github clobbered: %+v %q", merged.Project, merged.GitHub.Token)
}
if _, ok := merged.Agents["scanner"]; !ok {
t.Errorf("seed agents clobbered: %v", merged.Agents)
}
})
}
}

// TestLoadWithDashboardOverlay_SilentOverlayKeepsSeedReviewAndAgentSandbox: an
// overlay that carries neither block must not blank the seed's.
func TestLoadWithDashboardOverlay_SilentOverlayKeepsSeedReviewAndAgentSandbox(t *testing.T) {
seedPath := setupOverlayReviewSandbox(t, overlayReviewSandboxSeed, "project:\n org: testorg\n repos: [repo1]\n")
merged, err := LoadWithDashboardOverlay(seedPath)
if err != nil {
t.Fatalf("LoadWithDashboardOverlay: %v", err)
}
if got := merged.Review.RequireLabels; len(got) != 1 || got[0] != "seed-label" {
t.Errorf("seed review.require_labels clobbered by silent overlay: %v", got)
}
if merged.AgentSandbox.Image != "seed/image:1" {
t.Errorf("seed agent_sandbox.image clobbered by silent overlay: %q", merged.AgentSandbox.Image)
}
}

// TestLoadWithDashboardOverlay_OverlayVariablesStaySeedOnly pins the security
// invariant next to the new adoption: widening the adopted blocks must never
// widen into variables.security.
func TestLoadWithDashboardOverlay_OverlayVariablesStaySeedOnly(t *testing.T) {
overlay := overlayReviewSandboxOverlay + `
variables:
security:
allow_exec: true
`
seedPath := setupOverlayReviewSandbox(t, overlayReviewSandboxSeed, overlay)
merged, err := LoadWithDashboardOverlay(seedPath)
if err != nil {
t.Fatalf("LoadWithDashboardOverlay: %v", err)
}
if merged.Variables.Security.AllowExec {
t.Errorf("overlay variables.security.allow_exec was adopted; it must stay seed-only")
}
}

// TestLoadWithDashboardOverlay_AgentFileOutranksDashboardOverlay reproduces the
// standalone OpenShift report: an operator set `paused: true` and a `sandbox:`
// block in /data/agent-configs/reviewer.yaml, but the dashboard overlay's
// older copy of agents.reviewer (paused false, sandbox disabled) replaced it
// on load. The agent file is the higher layer and must win; other agents the
// file does not name keep the overlay's values.
func TestLoadWithDashboardOverlay_AgentFileOutranksDashboardOverlay(t *testing.T) {
dir := t.TempDir()
agentsDir := filepath.Join(dir, "agent-configs")
if err := os.MkdirAll(agentsDir, 0o755); err != nil {
t.Fatal(err)
}
seed := "project:\n org: testorg\n repos: [repo1]\ngithub:\n token: ghp_test123456789\ndata:\n agents_dir: " + agentsDir + "\nagents:\n reviewer:\n backend: copilot\n model: claude-sonnet-4-6\n scanner:\n backend: copilot\n model: claude-sonnet-4-6\n"
overlay := `
project:
org: testorg
repos: [repo1]
agents:
reviewer:
backend: copilot
model: claude-sonnet-4-6
paused: false
pause_owner: operator
sandbox:
enabled: false
scanner:
backend: copilot
model: overlay-model
`
file := `
backend: copilot
model: claude-sonnet-4-6
paused: true
pause_owner: operator
sandbox:
enabled: true
image: reviewer/sandbox:1
`
if err := os.WriteFile(filepath.Join(agentsDir, "reviewer.yaml"), []byte(file), 0o644); err != nil {
t.Fatal(err)
}
seedPath := setupOverlayReviewSandbox(t, seed, overlay)
merged, err := LoadWithDashboardOverlay(seedPath)
if err != nil {
t.Fatalf("LoadWithDashboardOverlay: %v", err)
}
r := merged.Agents["reviewer"]
if !r.Paused {
t.Errorf("agent file paused: true lost to the dashboard overlay")
}
if r.Sandbox == nil || r.Sandbox.Image != "reviewer/sandbox:1" || r.Sandbox.Enabled == nil || !*r.Sandbox.Enabled {
t.Errorf("agent file sandbox block lost to the dashboard overlay: %+v", r.Sandbox)
}
if got := merged.Agents["scanner"].Model; got != "overlay-model" {
t.Errorf("agent without a file must keep the overlay value, got %q", got)
}
}
Loading