fix(config): complete the reloadable allowlist and pin it against ForTask
The allowlist drifted before the chunk shipped. ForTask (config.go:457-465) is the authoritative per-dispatch snapshot and carries Models, Budgets, Dispatch, DiffCapLines, Notify and Forge.Host -- I allowlisted only three. And the poll path reads cfg.Label and cfg.BotUser live per cycle (daemon.go:359,390 and :368,381) off the same per-poll config as Dispatch.Trigger. Five fields would have reported 'requires a restart' while actually taking effect immediately: the safe direction, but exactly the warning-fatigue failure that kills the feature (an operator who is told to restart for a label change that already applied learns the warning is noise). The fix is enforcement, not a bigger list: TestReloadableFieldsCoverForTaskSnapshot reflects over TaskConfig and fails if any field ForTask carries is not in the allowlist (Forge maps to the Forge.Host sub-field entry). A field added to ForTask later now fails the test instead of silently producing a wrong warning. Label and BotUser are not carried by ForTask -- they come off the poll path -- so they are allowlisted by hand with a comment, and the same test pins them explicitly. Also documents on webui.Server.Cfg that in production it is the daemon's OWN Holder (web.Cfg = d.Cfg), so Set publishes to the running daemon: a config-mutating handler must apply to a copy, validate the materialised config, persist, then Set -- never Set directly. task check clean.
This commit is contained in:
1 parent
d8d4c93239
commit
31fdbddd61
3 files changed
+74
-12
No files matched your search
+17
-6
@@ -92,22 +92,33 @@ var reloadableFields = map[string]bool{
|
||||
"PollInterval": true,
|
||||
// Poll loops re-read per cycle (daemon.go poll / pollForIdentity).
|
||||
"Repos": true,
|
||||
// Per-task snapshot: configFor -> executionFor -> d.Cfg.Get() at
|
||||
// dispatch, carried by TaskConfig (config.go ForTask).
|
||||
// Per-task snapshot: ForTask carries these into every dispatched
|
||||
// TaskContext (config.go ForTask), built fresh from d.Cfg.Get() at
|
||||
// dispatch. Pinned by TestReloadableFieldsCoverForTaskSnapshot so a
|
||||
// field added to ForTask cannot silently drift out of this list.
|
||||
"DiffCapLines": true,
|
||||
"Budgets": true,
|
||||
// Dispatch is read per poll (daemon.go pollIssuesWithConfig switch)
|
||||
// and carried per task like DiffCapLines.
|
||||
"Dispatch": true,
|
||||
"Dispatch": true,
|
||||
"Models": true,
|
||||
"Notify": true,
|
||||
// Per-poll reads off the live config in pollIssuesWithConfig:
|
||||
// cfg.Label feeds IssuesWithLabel (daemon.go:359,390), cfg.BotUser
|
||||
// feeds AssignedIssues (:368,381). Not carried by ForTask, so
|
||||
// pinned by hand in TestReloadableFieldsCoverForTaskSnapshot.
|
||||
"Label": true,
|
||||
"BotUser": true,
|
||||
}
|
||||
|
||||
// reloadableSubFields are sub-fields of structs that are otherwise
|
||||
// startup-built. VolumeTTL and MaxConcurrency are re-read per cycle
|
||||
// (cleanupExpiredStorage, drainSQLite/drainNATS); everything else in
|
||||
// Containers (Image, Enabled, MaxUptime, PullPolicy, Network) is frozen
|
||||
// in the startup-built container pool.
|
||||
// in the startup-built container pool. Forge.Host is carried into
|
||||
// TaskContext by ForTask (display/link building only); the forge client
|
||||
// itself is startup-built, so Type/Token/TokenEnv stay requires-restart.
|
||||
var reloadableSubFields = map[string]map[string]bool{
|
||||
"Containers": {"VolumeTTL": true, "MaxConcurrency": true},
|
||||
"Forge": {"Host": true},
|
||||
}
|
||||
|
||||
// changedNonReloadableFields compares old and new and returns the
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
@@ -146,23 +147,27 @@ func TestChangedNonReloadableFields(t *testing.T) {
|
||||
t.Fatalf("unchanged: got %v, want []", got)
|
||||
}
|
||||
|
||||
// Reloadable-only changes (PollInterval, Repos, Budgets, Dispatch,
|
||||
// DiffCapLines) -> empty.
|
||||
// Reloadable-only changes -> empty.
|
||||
reloadableOnly := base
|
||||
reloadableOnly.PollInterval = config.Duration(60 * time.Second)
|
||||
reloadableOnly.Repos = []config.Repo{{Owner: "x", Name: "z"}}
|
||||
reloadableOnly.Budgets = config.Budgets{MaxSteps: 99}
|
||||
reloadableOnly.Dispatch = config.Dispatch{Trigger: "label"}
|
||||
reloadableOnly.DiffCapLines = 1234
|
||||
reloadableOnly.Models = map[string]string{"builder": "provider/model"}
|
||||
reloadableOnly.Notify = config.Notify{Webhook: "https://notify.example/hook"}
|
||||
reloadableOnly.Label = "archie"
|
||||
reloadableOnly.BotUser = "new-bot"
|
||||
reloadableOnly.Forge = config.Forge{Host: "https://new-forge.example"}
|
||||
if got := changedNonReloadableFields(base, reloadableOnly); len(got) != 0 {
|
||||
t.Fatalf("reloadable-only: got %v, want []", got)
|
||||
}
|
||||
|
||||
// A non-reloadable change is named.
|
||||
// A non-reloadable change is named (Agent builds the startup runner).
|
||||
nonReloadable := base
|
||||
nonReloadable.BotUser = "b"
|
||||
if got := changedNonReloadableFields(base, nonReloadable); len(got) != 1 || got[0] != "BotUser" {
|
||||
t.Fatalf("BotUser change: got %v, want [BotUser]", got)
|
||||
nonReloadable.Agent = config.Agent{Mode: "subprocess"}
|
||||
if got := changedNonReloadableFields(base, nonReloadable); len(got) != 1 || got[0] != "Agent" {
|
||||
t.Fatalf("Agent change: got %v, want [Agent]", got)
|
||||
}
|
||||
|
||||
// Containers sub-field granularity: Image change warns, MaxConcurrency
|
||||
@@ -192,4 +197,44 @@ func TestChangedNonReloadableFields(t *testing.T) {
|
||||
if got := changedNonReloadableFields(base, natsChanged); len(got) != 1 || got[0] != "NATS" {
|
||||
t.Fatalf("NATS change: got %v, want [NATS]", got)
|
||||
}
|
||||
|
||||
// Forge.Host is reloadable but Forge.Type is not: only the host is
|
||||
// carried into TaskContext by ForTask.
|
||||
forgeTypeChanged := base
|
||||
forgeTypeChanged.Forge = config.Forge{Type: "gitea"}
|
||||
if got := changedNonReloadableFields(base, forgeTypeChanged); len(got) != 1 || got[0] != "Forge.Type" {
|
||||
t.Fatalf("Forge.Type change: got %v, want [Forge.Type]", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestReloadableFieldsCoverForTaskSnapshot pins the allowlist against
|
||||
// the per-dispatch snapshot: every field ForTask carries into a
|
||||
// TaskContext is re-read at dispatch, so a reload applies to new tasks.
|
||||
// If a field is added to ForTask later, this test fails until the
|
||||
// allowlist is updated -- a hand-maintained list that mirrors ForTask
|
||||
// otherwise drifts silently into a wrong 'requires a restart' warning.
|
||||
func TestReloadableFieldsCoverForTaskSnapshot(t *testing.T) {
|
||||
tt := reflect.TypeFor[config.TaskConfig]()
|
||||
for field := range tt.Fields() {
|
||||
name := field.Name
|
||||
if name == "Forge" {
|
||||
// TaskConfig.Forge is TaskForge{Host}; it maps to the
|
||||
// Config.Forge.Host sub-field allowlist entry.
|
||||
if !reloadableSubFields["Forge"]["Host"] {
|
||||
t.Errorf("ForTask field Forge (Host) is not allowlisted as reloadable")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !reloadableFields[name] {
|
||||
t.Errorf("ForTask field %s is not allowlisted as reloadable", name)
|
||||
}
|
||||
}
|
||||
// The poll-path fields (Label, BotUser) are not carried by ForTask;
|
||||
// pin them explicitly so a refactor that moves their read site does
|
||||
// not silently drop the allowlist entry.
|
||||
for _, name := range []string{"Label", "BotUser"} {
|
||||
if !reloadableFields[name] {
|
||||
t.Errorf("poll-path field %s is not allowlisted as reloadable", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,12 @@ type Server struct {
|
||||
// dashboard degrades to task data alone when it is nil. Held through a
|
||||
// Holder so a reload swaps the snapshot atomically across handler
|
||||
// goroutines that would otherwise race on the raw shared pointer.
|
||||
//
|
||||
// In production this is the daemon's OWN Holder (main.go wires
|
||||
// web.Cfg = d.Cfg), so Set here publishes to the running daemon. A
|
||||
// config-mutating handler must never call Set directly: it goes
|
||||
// through the same path as reload -- apply to a copy, validate the
|
||||
// materialised config, persist, then Set.
|
||||
Cfg *config.Holder
|
||||
|
||||
// Workflows is the executable registry snapshot supplied by composition.
|
||||
|
||||
Reference in new issue
Block a user