diff --git a/changelog.d/fixed-16438-boot-safety-gates.md b/changelog.d/fixed-16438-boot-safety-gates.md new file mode 100644 index 0000000000..17b8bbb4b2 --- /dev/null +++ b/changelog.d/fixed-16438-boot-safety-gates.md @@ -0,0 +1 @@ +- Warn before boot recovery drops safety gates from prior runtime or dashboard config, retain the warning in status and settings, and allow operators to refuse startup with `config.refuse_gate_regression: true`; `hive config diff` shows the same gate deltas ([#16438](https://github.com/hivecommons/hive/issues/16438)). diff --git a/src/cmd/hive/config_diff.go b/src/cmd/hive/config_diff.go new file mode 100644 index 0000000000..21edd01b4d --- /dev/null +++ b/src/cmd/hive/config_diff.go @@ -0,0 +1,51 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io" + "os" + + "github.com/hivecommons/hive/pkg/config" +) + +// runConfigDiff starts nothing: the entrypoint calls it before snapshot writes. +// Positional paths override the conventional prior layers for operator use. +func runConfigDiff(args []string, stdout, stderr io.Writer) int { + fs := flag.NewFlagSet("config diff", flag.ContinueOnError) + fs.SetOutput(stderr) + defaultPath := os.Getenv("HIVE_CONFIG") + if defaultPath == "" { + defaultPath = "/etc/hive/hive.yaml" + } + path := fs.String("config", defaultPath, "effective config path") + asJSON := fs.Bool("json", false, "emit boot warnings as JSON") + if err := fs.Parse(args); err != nil { + return 1 + } + previous := fs.Args() + if len(previous) == 0 { + previous = []string{config.RuntimeConfigFile, config.RuntimeConfigFile + ".bak", config.RuntimeConfigFileLegacy, config.DashboardOverlayFile} + } + warnings, strict, err := config.SafetyGateDiff(*path, previous) + if err != nil { + fmt.Fprintln(stderr, err) + return 1 + } + for _, warning := range warnings { + fmt.Fprintln(stderr, "WARN", warning) + } + if *asJSON { + if err := json.NewEncoder(stdout).Encode(warnings); err != nil { + return 1 + } + } else if len(warnings) == 0 { + fmt.Fprintln(stdout, "No safety gate regressions") + } + if strict && len(warnings) > 0 { + fmt.Fprintln(stderr, "refusing to start: config.refuse_gate_regression is enabled; restore the safety gates or explicitly disable strict mode") + return 1 + } + return 0 +} diff --git a/src/cmd/hive/config_diff_test.go b/src/cmd/hive/config_diff_test.go new file mode 100644 index 0000000000..496a596dda --- /dev/null +++ b/src/cmd/hive/config_diff_test.go @@ -0,0 +1,44 @@ +package main + +import ( + "bytes" + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" +) + +func TestConfigDiffDispatchAndStrictMode(t *testing.T) { + for _, strict := range []bool{false, true} { + t.Run(map[bool]string{false: "warn", true: "refuse"}[strict], func(t *testing.T) { + dir := t.TempDir() + seed, prior := filepath.Join(dir, "seed"), filepath.Join(dir, "prior") + body := "project: {org: example}\n" + if strict { + body += "config: {refuse_gate_regression: true}\n" + } + if err := os.WriteFile(seed, []byte(body), 0600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(prior, []byte("review: {require_labels: [hive-review]}\n"), 0600); err != nil { + t.Fatal(err) + } + var stdout, stderr bytes.Buffer + handled, code := dispatchSubcommand([]string{"config", "diff", "--config", seed, "--json", prior}, &stdout, &stderr) + if !handled || (code != 0) != strict { + t.Fatalf("handled=%v code=%d: %s", handled, code, stderr.String()) + } + var warnings []string + if err := json.Unmarshal(stdout.Bytes(), &warnings); err != nil || len(warnings) != 1 { + t.Fatalf("warnings=%v err=%v stdout=%s", warnings, err, stdout.String()) + } + if !strings.Contains(stderr.String(), "WARN safety gate dropped: review.require_labels") { + t.Fatal(stderr.String()) + } + if strings.Contains(stderr.String(), "refusing to start") != strict { + t.Fatal(stderr.String()) + } + }) + } +} diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 39a994c32b..f5c74bdd0c 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -7113,6 +7113,12 @@ func dispatchSubcommand(args []string, stdout, stderr io.Writer) (bool, int) { case "--version", "version": fmt.Fprintf(stdout, "hive %s (commit %s, branch %s)\n", reportedVersion(), gitShort, gitBranch) return true, 0 + case "config": + if len(args) > 1 && args[1] == "diff" { + return true, runConfigDiff(args[2:], stdout, stderr) + } + fmt.Fprintln(stderr, "usage: hive config diff [-config path] [-json] [previous paths...]") + return true, 1 case "validate", "--config-check": return true, runConfigCheck(args[1:], stdout, stderr) case "agy-turn": diff --git a/src/deploy/entrypoint.sh b/src/deploy/entrypoint.sh index ab9c357b83..70be767316 100644 --- a/src/deploy/entrypoint.sh +++ b/src/deploy/entrypoint.sh @@ -962,6 +962,16 @@ hive_write_system_gitconfig() { echo "[entrypoint] agents commit as ${_hwsg_name} <${_hwsg_email}> (system gitconfig)" } +# Capture safety deltas BEFORE snapshot writes erase the prior runtime config. +# The exported JSON survives the root -> dev re-exec and config reloads, keeping +# recovery warnings visible in /api/status for the entire boot. +hive_check_safety_gates() { + if [ -z "${HIVE_BOOT_SAFETY_WARNINGS:-}" ]; then + HIVE_BOOT_SAFETY_WARNINGS="$(hive config diff --config "${HIVE_CONFIG:-$HIVE_CONFIG_PATH}" --json)" || return 1 + export HIVE_BOOT_SAFETY_WARNINGS + fi +} + # Detect Kubernetes vs Docker environment IS_KUBERNETES=false if [ -n "${KUBERNETES_SERVICE_HOST:-}" ] || [ -f /var/run/secrets/kubernetes.io/serviceaccount/token ]; then @@ -1141,6 +1151,7 @@ PYEOF echo "[entrypoint] K8s mode — dashboard overlay invalid, using ConfigMap seed as-is" fi fi + hive_check_safety_gates # Write the (merged) config as the disaster-recovery snapshot. Always # under the new name; the legacy file is left untouched on the PVC. cp "$HIVE_CONFIG_PATH" "$HIVE_CONFIG_RUNTIME" 2>/dev/null || true @@ -1203,6 +1214,8 @@ else fi fi +hive_check_safety_gates + # ── Cleanup stale stderr logs from previous agent launches ──────────── STDERR_LOG_MAX_AGE_MINUTES=60 find /tmp -maxdepth 1 -name '.hive-launch-stderr-*.log' -mmin +"$STDERR_LOG_MAX_AGE_MINUTES" -delete 2>/dev/null || true diff --git a/src/deploy/test_entrypoint_runtime_config.sh b/src/deploy/test_entrypoint_runtime_config.sh index 4f97399d2c..6d192077a4 100755 --- a/src/deploy/test_entrypoint_runtime_config.sh +++ b/src/deploy/test_entrypoint_runtime_config.sh @@ -231,4 +231,49 @@ else trap - EXIT fi +# #16438: execute the actual recovery branch, including its snapshot write. +# A fake diff command controls the verdict; Go tests exercise the comparator. +SAFETY_HELPER="$(sed -n '/^hive_check_safety_gates() {/,/^}/p' "$ENTRYPOINT")" +BOOT_BLOCK="$(sed -n '/^# Detect Kubernetes vs Docker environment/,/^# ── Cleanup stale stderr logs/{ /^# ── Cleanup stale stderr logs/d; p; }' "$ENTRYPOINT")" +exercise_safety_boot() ( + set -e + local verdict="$1" dir + dir="$(mktemp -d)" + trap 'rm -rf "$dir"' EXIT + HIVE_CONFIG_PATH="$dir/seed" + HIVE_CONFIG_RUNTIME="$dir/runtime" + HIVE_CONFIG_RUNTIME_LEGACY="$dir/legacy" + HIVE_CONFIG_BOOT="" + HIVE_CONFIG="" + HIVE_BOOT_SAFETY_WARNINGS="" + KUBERNETES_SERVICE_HOST=probe + printf 'project: {org: probe}\n' > "$HIVE_CONFIG_PATH" + # Resolve no boot input, simulating an operator moving runtime aside. + hive_runtime_config_read() { :; } + hive_harden_runtime_config() { :; } + hive() { + if [ "$verdict" = refuse ]; then return 1; fi + printf '["safety gate dropped: review.require_labels"]\n' + } + # Use a separate shell so set -e remains active even when this harness + # captures its exit status in an if statement. + export HIVE_CONFIG_PATH HIVE_CONFIG_RUNTIME HIVE_CONFIG_RUNTIME_LEGACY + export KUBERNETES_SERVICE_HOST HIVE_CONFIG HIVE_BOOT_SAFETY_WARNINGS verdict + export -f hive_runtime_config_read hive_harden_runtime_config hive + local status=0 + BOOT_BLOCK="${BOOT_BLOCK//\/data\/hive.yaml.dashboard/$dir/dashboard}" + bash -ec "$SAFETY_HELPER +$BOOT_BLOCK +[ -n \"\$HIVE_BOOT_SAFETY_WARNINGS\" ]" >"$dir/log" 2>&1 || status=$? + if [ "$verdict" = refuse ]; then + [ "$status" != 0 ] && [ ! -e "$HIVE_CONFIG_RUNTIME" ] && echo refused-before-snapshot + else + [ "$status" = 0 ] && cmp -s "$HIVE_CONFIG_PATH" "$HIVE_CONFIG_RUNTIME" && echo warned-and-snapshotted + fi +) +check "strict gate regression refuses before runtime snapshot" \ + "refused-before-snapshot" "$(exercise_safety_boot refuse)" +check "normal recovery keeps boot warning across second guard call" \ + "warned-and-snapshotted" "$(exercise_safety_boot warn)" + hive_test_report diff --git a/src/hive.yaml.example b/src/hive.yaml.example index 57158a8f59..de0bb7c553 100644 --- a/src/hive.yaml.example +++ b/src/hive.yaml.example @@ -1,3 +1,9 @@ +# Compare boot safety gates with surviving runtime/backup/dashboard config. +# Warn by default; true refuses startup before replacing the runtime snapshot. +# Inspect deltas manually with: hive config diff --config /path/to/hive.yaml +config: + refuse_gate_regression: false + # Hive v2 Configuration # All values support ${ENV_VAR} interpolation for secrets. # Copy this file to hive.yaml and customize for your setup. diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index bca9a76240..fdf5ff75a6 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -74,8 +74,9 @@ func notifySaveObserver() { var dashboardAuthTokenFile = "/secrets/dashboard-token" type Config struct { - Project ProjectConfig `yaml:"project"` - Policies PoliciesConfig `yaml:"policies"` + Config *ConfigLoadPolicy `yaml:"config,omitempty" json:"config,omitempty"` + Project ProjectConfig `yaml:"project"` + Policies PoliciesConfig `yaml:"policies"` // AgentRuntimeConfig groups the keys the agent runtime (Crux, // hivecommons/hive#13536) owns. It is inlined so the YAML shape is // unchanged: `agents:`, `backends:`, ... stay top-level. diff --git a/src/pkg/config/safety_gates.go b/src/pkg/config/safety_gates.go new file mode 100644 index 0000000000..c8ad4af0a6 --- /dev/null +++ b/src/pkg/config/safety_gates.go @@ -0,0 +1,132 @@ +package config + +import ( + "encoding/json" + "fmt" + "os" + "sort" + "strings" + + "gopkg.in/yaml.v3" +) + +// BootSafetyWarningsEnv carries the pre-snapshot comparison across the +// entrypoint's privilege-drop re-exec. It contains only gate diagnostics, +// never config contents or credentials, and lasts for this process's boot. +const BootSafetyWarningsEnv = "HIVE_BOOT_SAFETY_WARNINGS" + +// ConfigLoadPolicy controls startup diagnostics; it does not change gate enforcement. +type ConfigLoadPolicy struct { + RefuseGateRegression bool `yaml:"refuse_gate_regression,omitempty" json:"refuse_gate_regression,omitempty"` +} + +// BootSafetyWarnings returns warnings captured before the entrypoint replaced +// the runtime snapshot. Reading them here keeps reloads from erasing boot evidence. +func BootSafetyWarnings() []string { + var warnings []string + _ = json.Unmarshal([]byte(os.Getenv(BootSafetyWarningsEnv)), &warnings) + return warnings +} + +// gateSnapshot deliberately reads only safety settings. Recovery diagnostics +// must work even when an unrelated agent field makes a full config invalid. +type gateSnapshot struct { + Config ConfigLoadPolicy `yaml:"config"` + Review struct { + RequireLabels []string `yaml:"require_labels"` + } `yaml:"review"` + Project struct { + Org string `yaml:"org"` + PausedRepos []struct { + Repo string `yaml:"repo"` + } `yaml:"paused_repos"` + IssueFilter struct { + RequireLabels []string `yaml:"require_labels"` + } `yaml:"issue_filter"` + } `yaml:"project"` + Writeback struct { + PerRepo map[string]struct { + Mode string `yaml:"mode"` + } `yaml:"per_repo"` + } `yaml:"writeback"` +} + +func readGateSnapshot(path string) (gateSnapshot, error) { + var cfg gateSnapshot + data, err := os.ReadFile(path) + if err == nil { + err = yaml.Unmarshal([]byte(expandEnvVars(string(data))), &cfg) + } + return cfg, err +} + +// SafetyGateDiff compares an effective boot config against all surviving prior +// layers, before any of them are overwritten. Missing layers mean first boot; +// unreadable or malformed layers are explicit diagnostics rather than silence. +// The bool is the effective config's strict-mode setting. +func SafetyGateDiff(path string, previous []string) ([]string, bool, error) { + effective, err := readGateSnapshot(path) + if err != nil { + return nil, false, fmt.Errorf("reading effective safety gates: %w", err) + } + warnings := []string{} + for _, priorPath := range previous { + prior, err := readGateSnapshot(priorPath) + if os.IsNotExist(err) { + continue + } + if err != nil { + // Do not print parser errors: they can contain unrelated secret values. + warnings = append(warnings, fmt.Sprintf("safety gate comparison unavailable: %s (unreadable or invalid YAML)", priorPath)) + continue + } + dropped := func(key string, was any) { + value, _ := json.Marshal(was) + warnings = append(warnings, fmt.Sprintf("safety gate dropped: %s (was %s) — effective config has none or a weaker restriction (previous: %s)", key, value, priorPath)) + } + if len(nonemptyLabels(prior.Review.RequireLabels)) > 0 && len(nonemptyLabels(effective.Review.RequireLabels)) == 0 { + dropped("review.require_labels", prior.Review.RequireLabels) + } + if len(nonemptyLabels(prior.Project.IssueFilter.RequireLabels)) > 0 && len(nonemptyLabels(effective.Project.IssueFilter.RequireLabels)) == 0 { + dropped("project.issue_filter.require_labels", prior.Project.IssueFilter.RequireLabels) + } + paused := map[string]bool{} + for _, p := range effective.Project.PausedRepos { + paused[repoPauseKey(effective.Project.Org, p.Repo)] = true + } + for _, p := range prior.Project.PausedRepos { + if p.Repo != "" && !paused[repoPauseKey(prior.Project.Org, p.Repo)] { + dropped("project.paused_repos", p.Repo) + } + } + modes := map[string]string{} + for repo, override := range effective.Writeback.PerRepo { + modes[strings.ToLower(strings.TrimSpace(repo))] = override.Mode + } + repos := make([]string, 0, len(prior.Writeback.PerRepo)) + for repo := range prior.Writeback.PerRepo { + repos = append(repos, repo) + } + sort.Strings(repos) + for _, repo := range repos { + mode := prior.Writeback.PerRepo[repo].Mode + current := modes[strings.ToLower(strings.TrimSpace(repo))] + // off is strictly stronger than either partial-write mode. The partial + // modes allow different kinds, so switching between them is a delta too. + if (mode == "off" || mode == "issues-only" || mode == "labels-only") && current != mode && current != "off" { + dropped("writeback.per_repo."+repo+".mode", mode) + } + } + } + return warnings, effective.Config.RefuseGateRegression, nil +} + +func nonemptyLabels(labels []string) []string { + var out []string + for _, label := range labels { + if strings.TrimSpace(label) != "" { + out = append(out, label) + } + } + return out +} diff --git a/src/pkg/config/safety_gates_test.go b/src/pkg/config/safety_gates_test.go new file mode 100644 index 0000000000..15afbcc300 --- /dev/null +++ b/src/pkg/config/safety_gates_test.go @@ -0,0 +1,115 @@ +package config + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "gopkg.in/yaml.v3" +) + +func writeGateConfig(t *testing.T, dir, name, body string) string { + t.Helper() + path := filepath.Join(dir, name) + if err := os.WriteFile(path, []byte(body), 0600); err != nil { + t.Fatal(err) + } + return path +} + +func TestSafetyGateDiffRecovery(t *testing.T) { + dir := t.TempDir() + seed := writeGateConfig(t, dir, "seed", "project: {org: example}\n") + priorBody := `review: {require_labels: [hive-review]} +project: + org: example + paused_repos: [{repo: held, by: operator, reason: private-reason}] + issue_filter: {require_labels: [accepted]} +writeback: + per_repo: + example/held: {mode: off} +github: {token: private-token} +` + for _, name := range []string{"hive.yaml.runtime", "hive.yaml.runtime.bak", "hive.yaml.bak", "hive.yaml.dashboard"} { + t.Run(name, func(t *testing.T) { + prior := writeGateConfig(t, dir, name, priorBody) + warnings, strict, err := SafetyGateDiff(seed, []string{prior}) + if err != nil || strict || len(warnings) != 4 { + t.Fatalf("warnings=%v strict=%v err=%v", warnings, strict, err) + } + joined := strings.Join(warnings, "\n") + for _, key := range []string{"review.require_labels", "project.paused_repos", "project.issue_filter.require_labels", "writeback.per_repo.example/held.mode", "hive-review", prior} { + if !strings.Contains(joined, key) { + t.Errorf("missing %q in %s", key, joined) + } + } + if strings.Contains(joined, "private-") { + t.Fatal("diagnostics exposed unrelated config or pause metadata") + } + // Comparison is read-only even when recovery discovers a regression. + got, err := os.ReadFile(prior) + if err != nil || string(got) != priorBody { + t.Fatal("prior config was modified") + } + }) + } +} + +func TestSafetyGateDiffPreservedAndStronger(t *testing.T) { + dir := t.TempDir() + prior := writeGateConfig(t, dir, "prior", `review: {require_labels: [hive-review]} +project: + org: Example + paused_repos: [{repo: Held}] + issue_filter: {require_labels: [accepted]} +writeback: {per_repo: {example/held: {mode: issues-only}}} +`) + effective := writeGateConfig(t, dir, "effective", `review: {require_labels: [hive-review]} +project: + org: example + paused_repos: [{repo: example/held, reason: changed}, {repo: another}] + issue_filter: {require_labels: [accepted]} +writeback: {per_repo: {Example/Held: {mode: off}}} +`) + warnings, _, err := SafetyGateDiff(effective, []string{prior}) + if err != nil || len(warnings) != 0 { + t.Fatalf("%v, %v", warnings, err) + } +} + +func TestSafetyGateDiffPartialLossAndFirstBoot(t *testing.T) { + dir := t.TempDir() + effective := writeGateConfig(t, dir, "effective", "project: {org: org, paused_repos: [{repo: kept}]}\nwriteback: {per_repo: {org/kept: {mode: off}}}\n") + warnings, _, err := SafetyGateDiff(effective, []string{filepath.Join(dir, "missing")}) + if err != nil || len(warnings) != 0 { + t.Fatalf("first boot: %v, %v", warnings, err) + } + prior := writeGateConfig(t, dir, "prior", "project: {org: org, paused_repos: [{repo: kept}, {repo: lost}]}\nwriteback: {per_repo: {org/kept: {mode: off}, org/lost: {mode: labels-only}}}\n") + warnings, _, err = SafetyGateDiff(effective, []string{prior}) + if err != nil || len(warnings) != 2 { + t.Fatalf("partial loss: %v, %v", warnings, err) + } +} + +func TestSafetyGateDiffInvalidBaselineAndStrictPersistence(t *testing.T) { + dir := t.TempDir() + effective := writeGateConfig(t, dir, "effective", "config: {refuse_gate_regression: true}\n") + prior := writeGateConfig(t, dir, "prior", "review: [broken\nprivate-token") + warnings, strict, err := SafetyGateDiff(effective, []string{prior}) + if err != nil || !strict || len(warnings) != 1 || strings.Contains(warnings[0], "private-token") { + t.Fatalf("%v, %v, %v", warnings, strict, err) + } + var cfg Config + if err := yaml.Unmarshal([]byte("config: {refuse_gate_regression: true}"), &cfg); err != nil { + t.Fatal(err) + } + data, err := yaml.Marshal(cfg) + if err != nil || !strings.Contains(string(data), "refuse_gate_regression: true") { + t.Fatalf("strict mode lost on save: %v", err) + } + t.Setenv(BootSafetyWarningsEnv, `["safety gate dropped: review.require_labels"]`) + if got := BootSafetyWarnings(); len(got) != 1 { + t.Fatalf("boot evidence lost: %v", got) + } +} diff --git a/src/pkg/dashboard/config_safety_warnings_test.go b/src/pkg/dashboard/config_safety_warnings_test.go new file mode 100644 index 0000000000..0937e73dc4 --- /dev/null +++ b/src/pkg/dashboard/config_safety_warnings_test.go @@ -0,0 +1,28 @@ +package dashboard + +import ( + "encoding/json" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/governor" +) + +func TestStatusRetainsBootSafetyWarnings(t *testing.T) { + t.Setenv(config.BootSafetyWarningsEnv, `["safety gate dropped: review.require_labels"]`) + // A newly loaded config has no knowledge of the overwritten prior snapshot. + // The boot diagnostic must survive such reloads in the status JSON. + for i := 0; i < 2; i++ { + cfg := &config.Config{} + gov := governor.New(cfg.Governor, cfg.Agents, nil) + payload := BuildFrontendStatus(gov.GetState(), nil, nil, cfg, nil, gov, nil, nil, nil, nil) + body, err := json.Marshal(payload) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(body), `"configSafetyWarnings":["safety gate dropped: review.require_labels"]`) { + t.Fatalf("boot safety warning missing from status: %s", body) + } + } +} diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index 2ab315d0c7..e5e3bc21e0 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -551,9 +551,10 @@ type Server struct { // StatusPayload matches the JSON contract the dashboard frontend render() expects. type StatusPayload struct { - OverviewBands *OverviewBands `json:"overview_bands,omitempty"` - OverviewTotals FrontendOverviewTotals `json:"overviewTotals"` - ActionableNow FrontendActionableNow `json:"actionableNow"` + ConfigSafetyWarnings []string `json:"configSafetyWarnings,omitempty"` + OverviewBands *OverviewBands `json:"overview_bands,omitempty"` + OverviewTotals FrontendOverviewTotals `json:"overviewTotals"` + ActionableNow FrontendActionableNow `json:"actionableNow"` // OpenItems is the canonical open-items set the Overview tile, its // sidebar pill and the Hive activity monitor all count (open_items.go). OpenItems FrontendOpenItems `json:"openItems"` diff --git a/src/pkg/dashboard/static-src/js/config-tabs.js b/src/pkg/dashboard/static-src/js/config-tabs.js index 117ed0a479..69503a4350 100644 --- a/src/pkg/dashboard/static-src/js/config-tabs.js +++ b/src/pkg/dashboard/static-src/js/config-tabs.js @@ -35,7 +35,9 @@ // agent's kick history over the selected time window. if (tabId === AGENT_PROMPTS_TAB) initAgentPromptHistory(); } else { - body.innerHTML = renderGovernorTab(tabId); + const gateWarnings = (window._lastStatus || {}).configSafetyWarnings || []; + const gateBanner = gateWarnings.length ? '