fix(config): share one config Holder between daemon and dashboard; re-apply model catalog on reload
Adversarial review findings (fresh reviewer, no memory of the code): 1. (major) web.Cfg was a second Holder the reload never swapped, so /api/config showed boot-time values forever after the first reload while the daemon ran the new config -- the exact 'code means something different from what it says' failure. web and d now share one Holder (web.Cfg = d.Cfg after construction), so a reload swaps both views atomically. 2. (minor) the model catalog merge ran once at boot; publishing the raw reloaded document dropped catalog-discovered providers from the running config even though the file was unchanged. The apply closure re-runs applyModelCatalog on the reloaded document before publishing (idempotent; a catalog that failed to load merges to identity). 3. (minor) changedNonReloadableFields parameter 'new' shadowed the predeclared identifier (predeclared lint finding). Renamed to 'next'; the finding is gone from the branch diff. Also: tightened --no-config-overlay help text to state the file -config-overlay still applies (it gates the future DB overlay only), and documented that the controller's apply callback must be non-nil. task check clean; -race clean on cmd/archied and internal/daemon.
This commit is contained in:
1 parent
f544dd0978
commit
d8d4c93239
2 files changed
+17
-4
No files matched your search
+13
-1
@@ -313,7 +313,7 @@ func run() int {
|
||||
defaultCfg := filepath.Join(configHome(), "archie", "config.toml")
|
||||
cfgPath := flag.String("config", defaultCfg, "path to a TOML/YAML config file or configuration directory")
|
||||
overlayPath := flag.String("config-overlay", "", "path to a TOML/YAML overlay file or configuration directory applied on top of -config")
|
||||
noConfigOverlay := flag.Bool("no-config-overlay", false, "ignore the runtime config overlay (recovery hatch: boots on file config alone)")
|
||||
noConfigOverlay := flag.Bool("no-config-overlay", false, "skip the runtime config overlay (recovery hatch for the DB overlay; the -config-overlay file overlay still applies)")
|
||||
once := flag.Bool("once", false, "run a single poll+process cycle and exit (systemd timer / testing)")
|
||||
requeue := flag.Int64("requeue", 0, "requeue a parked/waiting task by id (keeps its workflow), then exit unless -once is also set")
|
||||
flag.Parse()
|
||||
@@ -979,6 +979,12 @@ func run() int {
|
||||
TaskLogs: taskLogs,
|
||||
}
|
||||
web.TaskStopper = d
|
||||
// web and the daemon must share ONE Holder: a reload swaps d.Cfg and
|
||||
// the dashboard reads the running config from the same snapshot. The
|
||||
// webui Holder seeded in the literal above is replaced here; after
|
||||
// this point /api/config and the daemon can never disagree about the
|
||||
// published config.
|
||||
web.Cfg = d.Cfg
|
||||
|
||||
// SIGHUP re-loads the config from disk and republishes it. The apply
|
||||
// closure swaps the daemon's Holder and the dashboard's provenance;
|
||||
@@ -986,6 +992,12 @@ func run() int {
|
||||
// an operator never has to read the source to find out whether their
|
||||
// edit took effect. web.LastReload exposes the outcome to /api/config.
|
||||
reloadController := newReloadController(loader, *cfgPath, *overlayPath, func(doc *configuration.Document) {
|
||||
// Boot merges catalog-discovered providers into cfg before the
|
||||
// Holders are seeded; publishing the raw reloaded document would
|
||||
// drop them from the running config even though the file is
|
||||
// unchanged. Re-apply the same merge (idempotent: a catalog that
|
||||
// failed to load merges to identity).
|
||||
applyModelCatalog(&doc.Config, catalog)
|
||||
old := d.Cfg.Get()
|
||||
d.Cfg.Set(doc.Config)
|
||||
provenance := make([]webui.ConfigOrigin, 0, len(doc.Provenance.Origins))
|
||||
|
||||
@@ -25,7 +25,8 @@ type ReloadController struct {
|
||||
|
||||
// apply receives a freshly loaded, validated Document. It is the
|
||||
// composition root's job to wire this to whatever owns the running
|
||||
// config (the daemon's Holder, the dashboard's provenance).
|
||||
// config (the daemon's Holder, the dashboard's provenance). Must be
|
||||
// non-nil; newReloadController requires it.
|
||||
apply func(*configuration.Document)
|
||||
|
||||
status atomic.Pointer[config.ReloadStatus]
|
||||
@@ -115,9 +116,9 @@ var reloadableSubFields = map[string]map[string]bool{
|
||||
// operator knows their edit did not take effect until a restart --
|
||||
// the alternative is an operator who believes a reloaded poll interval
|
||||
// changed the forge token, and burns an hour discovering it did not.
|
||||
func changedNonReloadableFields(old, new config.Config) []string {
|
||||
func changedNonReloadableFields(old, next config.Config) []string {
|
||||
var changed []string
|
||||
ov, nv := reflect.ValueOf(old), reflect.ValueOf(new)
|
||||
ov, nv := reflect.ValueOf(old), reflect.ValueOf(next)
|
||||
ot := reflect.TypeFor[config.Config]()
|
||||
for i := 0; i < ot.NumField(); i++ {
|
||||
f := ot.Field(i)
|
||||
|
||||
Reference in new issue
Block a user