refactor(config): delete the runtime config overlay

The control plane replaces this, rather than extending it
(docs/prds/runtime-control-plane.md, "First implementation"). Until now both
paths existed: overlay kept dashboard edits in its own SQLite file beside
archie.db and layered them over the file config at boot and on every reload,
which is the duplicate configuration authority the PRD set out to remove.

Gone with it: the --no-config-overlay flag and ARCHIE_SKIP_CONFIG_OVERLAY
recovery hatch, which existed because a bad overlay row could brick the boot;
ReloadStatus.OverlayUnavailable; and the reload controller's overlay source.
The -config-overlay file overlay is a different thing and stays.

The dashboard's three write seams went too. UpdateConfig, ResetConfig and
UpdateRepoField were assigned only in internal/webui's own tests, so in
production they answered 503 and ConfigView.Editable was permanently false
(archie-core-j28m). Removing Editable would otherwise have flipped the SPA's
controls on, since configEditable read a missing field as true, so the config
pages become what they already were in practice: a read of what each process
is running with. Configuration is written through the control plane.

apply.go survives this deliberately; archie-core-xrux carries the question of
whether its map merge is still guarding the file overlay path.
This commit is contained in:
sam committed 2026-09-21 08:57:55 +10:00
1 parent d8dd9ac6d6
commit 2311529def
35 files changed
+58 -1519

No files matched your search

+4 -52
View File
@@ -45,7 +45,6 @@ import (
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/indexing"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/overlay"
infraembedding "github.com/samcharles93/archie-core/internal/infrastructure/embedding"
"github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
infraMemory "github.com/samcharles93/archie-core/internal/infrastructure/memory"
@@ -84,8 +83,6 @@ type boot struct {
loader *configuration.Loader
doc *configuration.Document
overlayStore *overlay.Store
bootOverlayErr atomic.Pointer[string]
currentProvenance atomic.Pointer[configuration.Provenance]
health *healthSurface
@@ -244,16 +241,12 @@ func (b *boot) cleanup() {
}
}
// loadConfig resolves the file config and layers the runtime overlay
// over it. A Resolve failure is reported on stderr because the file log
// destination is itself configuration that has not been read yet.
func (b *boot) loadConfig(ctx context.Context, cfgPath, overlayPath string, noConfigOverlay bool) error {
// loadConfig resolves the file config. A Resolve failure is reported on
// stderr because the file log destination is itself configuration that has
// not been read yet.
func (b *boot) loadConfig(ctx context.Context, cfgPath, overlayPath string) error {
loader := configuration.New(b.log)
b.loader = loader
skipOverlay := noConfigOverlay || configuration.SkipOverlay()
if skipOverlay {
b.log.Info("runtime config overlay disabled (recovery hatch); booting on file config alone")
}
doc, err := loader.Resolve(cfgPath, overlayPath)
if err != nil {
fmt.Fprintln(os.Stderr, err)
@@ -268,21 +261,6 @@ func (b *boot) loadConfig(ctx context.Context, cfgPath, overlayPath string, noCo
if len(doc.UnknownKeys) > 0 {
b.log.Warn("config file has unrecognised keys; check for typos", "keys", doc.UnknownKeys)
}
// Runtime config overlay: dashboard-edited overrides layered over the
// file config from their own SQLite file (own user_version and
// migrator, no contention with the task store). Skipped under
// --no-config-overlay / ARCHIE_SKIP_CONFIG_OVERLAY=1, or when the
// store cannot be opened or its values fail validation -- a broken
// overlay must not brick the daemon. bootOverlayErr carries the
// degrade reason into /api/config's reload status so it is visible
// where the operator is looking, not only in logs.
if !skipOverlay {
b.overlayStore, b.doc = bootConfigOverlay(ctx, loader, doc, &b.bootOverlayErr, b.log)
if b.overlayStore != nil {
store := b.overlayStore
b.addCleanup(func() { _ = store.Close() })
}
}
b.cfg = b.doc.Config
b.cfgHolder = config.NewHolder(b.cfg)
b.currentProvenance.Store(&b.doc.Provenance)
@@ -1357,22 +1335,6 @@ func (b *boot) configOrigins() []webui.ConfigOrigin {
return origins
}
// configOverrides lists the dotted keys the runtime overlay currently sets,
// so the dashboard can mark those rows: their file value is shadowed until
// reset. A disabled overlay store reports no overrides.
func (b *boot) configOverrides(ctx context.Context) []string {
if b.overlayStore == nil {
return nil
}
keys, err := b.overlayStore.Keys(ctx)
if err != nil {
// A failed read omits the list rather than failing the whole
// view; the reload status carries the overlay degrade reason.
return nil
}
return keys
}
// configViewInput assembles the dashboard's configuration projection from
// the daemon's own configuration state. The daemon is the configuration
// owner, so it is the process that renders this view (archie-core-ml30).
@@ -1380,7 +1342,6 @@ func (b *boot) configViewInput(ctx context.Context) webui.ConfigViewInput {
in := webui.ConfigViewInput{
Config: b.cfgHolder.Get(),
Provenance: b.configOrigins(),
Overridden: b.configOverrides(ctx),
}
if b.lastReload != nil {
status := b.lastReload()
@@ -1447,17 +1408,8 @@ func (b *boot) wireConfigPublishing(ctx context.Context, cfgPath, overlayPath st
log.Info("config reloaded", "paths", doc.Provenance.Paths())
}
})
if b.overlayStore != nil {
reloadController.WithOverlay(func() (map[string]any, error) { return b.overlayStore.Snapshot(ctx) })
}
// lastReload merges the reload controller's outcome with the boot-time
// overlay degrade, so /api/config carries both the last reload result
// and whether the runtime overlay is in effect at all.
b.lastReload = func() config.ReloadStatus {
st := reloadController.Status()
if p := b.bootOverlayErr.Load(); p != nil {
st.OverlayUnavailable = *p
}
return st
}
@@ -9,7 +9,6 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/overlay"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/webui"
)
@@ -81,68 +80,8 @@ func TestPublishConfigSnapshotRendersTheDaemonsConfiguration(t *testing.T) {
if view.Reload == nil || view.Reload.LastError != "poll_interval must be positive" {
t.Errorf("Reload = %+v, want the last reload outcome", view.Reload)
}
// Editable describes the rendering process's write path, never the
// published document.
if view.Editable {
t.Error("the published document claims to be editable")
}
}
// TestPublishedSnapshotCarriesOverlayOverrides: the dashboard marks rows the
// runtime overlay shadows, so the projection has to name those keys. The
// daemon reads them from the overlay store it owns.
func TestPublishedSnapshotCarriesOverlayOverrides(t *testing.T) {
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = st.Close() })
overlayStore, err := overlay.Open(t.Context(), filepath.Join(t.TempDir(), "config.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = overlayStore.Close() })
if err := overlayStore.Set(t.Context(), "label", `"archie"`, "test"); err != nil {
t.Fatal(err)
}
if err := overlayStore.Set(t.Context(), "budgets.max_steps", "40", "test"); err != nil {
t.Fatal(err)
}
b := &boot{
log: slog.New(slog.DiscardHandler),
stateStore: st,
cfgHolder: config.NewHolder(config.Config{}),
overlayStore: overlayStore,
}
b.publishConfigSnapshot(t.Context())
snapshot, found, err := st.ConfigSnapshot(context.Background())
if err != nil || !found {
t.Fatalf("ConfigSnapshot = (found %v, %v), want the published document", found, err)
}
var view webui.ConfigView
if err := json.Unmarshal(snapshot.Document, &view); err != nil {
t.Fatal(err)
}
want := []string{"budgets.max_steps", "label"}
if len(view.Overridden) != len(want) {
t.Fatalf("Overridden = %+v, want %+v", view.Overridden, want)
}
for i, key := range want {
if view.Overridden[i] != key {
t.Errorf("Overridden[%d] = %q, want %q (sorted)", i, view.Overridden[i], key)
}
}
}
// TestPublishedSnapshotCarriesPerIdentityForges: in a multi-identity
// deployment the task board attributes each task to the forge that owns it,
// and the only process that holds that configuration is the daemon. So the
// published projection has to name every configured identity's forge and the
// repositories it owns (archie-core-pv6t); with the default identity alone,
// every row in such a deployment renders unlinked.
func TestPublishedSnapshotCarriesPerIdentityForges(t *testing.T) {
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db"))
if err != nil {
+1 -1
View File
@@ -56,7 +56,7 @@ func gatewayListenAndToken(b *boot, options GatewayOptions) (listen, token strin
func RunGateway(ctx context.Context, options GatewayOptions) error {
b := newBootstrap()
defer b.cleanup()
if err := b.loadConfig(ctx, options.Config, options.Overlay, false); err != nil {
if err := b.loadConfig(ctx, options.Config, options.Overlay); err != nil {
return err
}
b.log = b.log.With("component", "gateway")
+5 -66
View File
@@ -17,7 +17,6 @@ import (
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"syscall"
"github.com/moby/moby/client"
@@ -38,7 +37,6 @@ import (
"github.com/samcharles93/archie-core/internal/forgerpc"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/overlay"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/plugin"
"github.com/samcharles93/archie-core/internal/secret"
@@ -292,15 +290,6 @@ func taskDBPath(configuredPath string) string {
return configuredPath + "-tasks.sqlite"
}
// configDBPath resolves the runtime config overlay file. It is a sibling
// of the task and conversation stores (same configured path, own suffix)
// so each file owns its user_version and its migrator with no
// contention; recovery from a broken overlay is rm this file plus the
// --no-config-overlay boot flag.
func configDBPath(configuredPath string) string {
return configuredPath + "-config.sqlite"
}
func manualRequeueTask(ctx context.Context, st storecontract.TaskStore, taskID int64) error {
task, err := st.TaskByID(ctx, taskID)
if err != nil {
@@ -318,11 +307,10 @@ func manualRequeueTask(ctx context.Context, st storecontract.TaskStore, taskID i
}
type runArgs struct {
cfgPath string
overlayPath string
noConfigOverlay bool
once bool
requeue int64
cfgPath string
overlayPath string
once bool
requeue int64
}
func parseArgs() (runArgs, bool) {
@@ -330,7 +318,6 @@ func parseArgs() (runArgs, bool) {
var args runArgs
flag.StringVar(&args.cfgPath, "config", defaultCfg, "path to a TOML/YAML config file or configuration directory")
flag.StringVar(&args.overlayPath, "config-overlay", "", "path to a TOML/YAML overlay file or configuration directory applied on top of -config")
flag.BoolVar(&args.noConfigOverlay, "no-config-overlay", false, "skip the runtime config overlay (recovery hatch for the DB overlay; the -config-overlay file overlay still applies)")
flag.BoolVar(&args.once, "once", false, "run a single poll+process cycle and exit (systemd timer / testing)")
flag.Int64Var(&args.requeue, "requeue", 0, "requeue a parked/waiting task by id (keeps its workflow), then exit unless -once is also set")
showVersion := flag.Bool("version", false, "print the gateway and runtime versions and exit")
@@ -366,7 +353,7 @@ func Run() int { //nolint:cyclop,funlen // the composition root's setup sequence
// The drain monitor cancels this root to trigger a graceful shutdown, which
// propagates through ctx exactly as an operator SIGTERM does.
b.shutdown = cancelRoot
if err := b.loadConfig(ctx, args.cfgPath, args.overlayPath, args.noConfigOverlay); err != nil {
if err := b.loadConfig(ctx, args.cfgPath, args.overlayPath); err != nil {
return 1
}
defer b.cleanup()
@@ -468,54 +455,6 @@ func (b *boot) wireConfigSurfaces(ctx context.Context, cfgPath, overlayPath stri
b.publishConfigSnapshot(ctx)
}
// bootConfigOverlay layers the runtime config overlay over the resolved
// file config. Every failure degrades rather than aborts -- the daemon
// boots on file config alone and the reason is recorded in bootOverlayErr,
// which /api/config surfaces as the reload status. The returned store is
// nil only when Open failed; a store that opened but could not be read
// stays open and non-nil so the dashboard PATCH path and reload wiring
// keep exactly the behaviour of the original inline block.
func bootConfigOverlay(
ctx context.Context,
loader *configuration.Loader,
doc *configuration.Document,
bootOverlayErr *atomic.Pointer[string],
log *slog.Logger,
) (*overlay.Store, *configuration.Document) {
store, err := overlay.Open(ctx, configDBPath(doc.Config.DBPath))
if err != nil {
recordBootOverlayError(bootOverlayErr, log, err,
"config overlay unavailable; booting on file config alone",
"path", configDBPath(doc.Config.DBPath))
return nil, doc
}
overrides, err := store.Snapshot(ctx)
if err != nil {
recordBootOverlayError(bootOverlayErr, log, err,
"config overlay unreadable; booting on file config alone")
return store, doc
}
if len(overrides) == 0 {
return store, doc
}
applied, err := loader.ApplyOverlay(doc, overrides)
if err != nil {
recordBootOverlayError(bootOverlayErr, log, err,
"config overlay rejected by validation; booting on file config alone")
return store, doc
}
return store, applied
}
// recordBootOverlayError stores the degrade reason for /api/config and
// logs it, so the operator sees both where they are looking.
func recordBootOverlayError(p *atomic.Pointer[string], log *slog.Logger, err error, msg string, args ...any) {
reason := err.Error()
p.Store(&reason)
args = append(args, "err", err)
log.Error(msg, args...)
}
// persistEvents drains the bus until it closes, giving each event an ID
// from the store. The store is the only fan-out point (docs/architecture/
// migration-decisions.md, "Dashboard live event delivery"): the UI process
-29
View File
@@ -33,7 +33,6 @@ type ReloadController struct {
// (dotted keys -> typed values) to layer over the file config before
// publishing. A failed overlay read or validation aborts the reload
// exactly like a bad file.
overlayValues func() (map[string]any, error)
status atomic.Pointer[config.ReloadStatus]
}
@@ -57,27 +56,6 @@ func (c *ReloadController) Reload() error {
})
return err
}
if c.overlayValues != nil {
values, err := c.overlayValues()
if err != nil {
c.status.Store(&config.ReloadStatus{
LastError: err.Error(),
LastErrorAt: time.Now().UTC().Format(time.RFC3339),
})
return err
}
if len(values) > 0 {
// ApplyOverlay never mutates its input: on failure the
// resolved document (and the running config) is untouched.
if doc, err = c.loader.ApplyOverlay(doc, values); err != nil {
c.status.Store(&config.ReloadStatus{
LastError: err.Error(),
LastErrorAt: time.Now().UTC().Format(time.RFC3339),
})
return err
}
}
}
c.apply(doc)
c.status.Store(&config.ReloadStatus{
LastReloadAt: time.Now().UTC().Format(time.RFC3339),
@@ -85,13 +63,6 @@ func (c *ReloadController) Reload() error {
return nil
}
// WithOverlay attaches the runtime config overlay source. Optional: a
// controller without it publishes the file config alone.
func (c *ReloadController) WithOverlay(fn func() (map[string]any, error)) *ReloadController {
c.overlayValues = fn
return c
}
// Status returns the most recent reload outcome.
func (c *ReloadController) Status() config.ReloadStatus {
if p := c.status.Load(); p != nil {
-48
View File
@@ -2,7 +2,6 @@ package archied
import (
"context"
"errors"
"log/slog"
"os"
"path/filepath"
@@ -106,53 +105,6 @@ func TestReloadValidationFailureDoesNotApply(t *testing.T) {
}
}
func TestReloadAppliesOverlayBeforePublish(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.toml")
writeConfig(t, path, minimalConfigTOML("widget"))
loader := configuration.New(slog.New(slog.DiscardHandler))
var published config.Config
controller := newReloadController(loader, path, "", func(doc *configuration.Document) {
published = doc.Config
}).WithOverlay(func() (map[string]any, error) {
return map[string]any{"poll_interval": "90s"}, nil
})
if err := controller.Reload(); err != nil {
t.Fatal(err)
}
if published.PollInterval != config.Duration(90*time.Second) {
t.Errorf("PollInterval = %v, want 90s (overlay applied before publish)", published.PollInterval)
}
}
// TestReloadOverlayFailureAborts pins that a failed overlay read or
// validation aborts the reload exactly like a bad file: apply is not
// called and the error is recorded.
func TestReloadOverlayFailureAborts(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.toml")
writeConfig(t, path, minimalConfigTOML("widget"))
loader := configuration.New(slog.New(slog.DiscardHandler))
applied := 0
controller := newReloadController(loader, path, "", func(*configuration.Document) { applied++ }).
WithOverlay(func() (map[string]any, error) {
return nil, errors.New("overlay unreadable")
})
if err := controller.Reload(); err == nil {
t.Fatal("expected an error from the failed overlay")
}
if applied != 0 {
t.Fatalf("apply called %d times after overlay failure, want 0", applied)
}
if st := controller.Status(); st.LastError == "" {
t.Fatal("expected LastError recorded")
}
}
func TestReloadLoopAppliesOnSignalAndStopsOnCancel(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.toml")
+1 -1
View File
@@ -75,7 +75,7 @@ type StateStoreOptions struct {
func RunStateStore(ctx context.Context, options StateStoreOptions) error {
b := newBootstrap()
defer b.cleanup()
if err := b.loadConfig(ctx, options.Config, options.Overlay, false); err != nil {
if err := b.loadConfig(ctx, options.Config, options.Overlay); err != nil {
return err
}
listen, err := resolveServiceListen("state", options.Listen, b.cfg.Services.Get(config.ServiceNameState).Listen)
@@ -9,10 +9,7 @@ import (
// TestLoadConfigWarnsOnUnknownKeys pins plan-config-drift.md step 3: a
// stray/misspelled config key must be visible to the operator, not just
// silently parsed, validated and dropped. noConfigOverlay:true keeps the
// test to the file-load path alone, matching the recovery-hatch boot the
// daemon uses when it cannot or should not touch the runtime overlay
// store.
// silently parsed, validated and dropped.
func TestLoadConfigWarnsOnUnknownKeys(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
writeConfig(t, path, minimalConfigTOML("widget")+"[containers]\nmax_concurrancy = 4\n")
@@ -21,7 +18,7 @@ func TestLoadConfigWarnsOnUnknownKeys(t *testing.T) {
log := slog.New(slog.NewTextHandler(&sb, &slog.HandlerOptions{Level: slog.LevelWarn}))
b := &boot{log: log}
if err := b.loadConfig(t.Context(), path, "", true); err != nil {
if err := b.loadConfig(t.Context(), path, ""); err != nil {
t.Fatalf("loadConfig: %v (an unknown key must not fail the boot)", err)
}
@@ -42,7 +39,7 @@ func TestLoadConfigDoesNotWarnOnAKnownConfig(t *testing.T) {
log := slog.New(slog.NewTextHandler(&sb, &slog.HandlerOptions{Level: slog.LevelWarn}))
b := &boot{log: log}
if err := b.loadConfig(t.Context(), path, "", true); err != nil {
if err := b.loadConfig(t.Context(), path, ""); err != nil {
t.Fatalf("loadConfig: %v", err)
}
@@ -56,7 +53,7 @@ func TestLoadConfigMakesRuntimeSettingsAvailableBeforeSubsystemSetup(t *testing.
writeConfig(t, path, minimalConfigTOML("widget"))
b := &boot{log: slog.Default()}
if err := b.loadConfig(t.Context(), path, "", true); err != nil {
if err := b.loadConfig(t.Context(), path, ""); err != nil {
t.Fatalf("loadConfig: %v", err)
}
if b.cfgHolder == nil {
-3
View File
@@ -78,9 +78,6 @@ func TestComposeUIServerHoldsNoDaemonState(t *testing.T) {
}
unwired := map[string]any{
"UpdateConfig": srv.UpdateConfig,
"ResetConfig": srv.ResetConfig,
"UpdateRepoField": srv.UpdateRepoField,
"ReloadChannel": srv.ReloadChannel,
"RunningVersions": srv.RunningVersions,
"Events": srv.Events,
+2 -6
View File
@@ -113,7 +113,6 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
// links from, the same projection the task list uses.
published, err := json.Marshal(webui.ConfigView{
Identity: webui.IdentityView{BotUser: "archie", ForgeType: "github", ForgeHost: "https://forge.example"},
Editable: true,
})
if err != nil {
t.Fatal(err)
@@ -256,9 +255,6 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
if rendered.Identity.BotUser != "archie" {
t.Fatalf("config view = %s, want the published projection", body)
}
if rendered.Editable {
t.Error("the UI process rendered configuration as editable; it has no write path")
}
req, err := http.NewRequestWithContext(t.Context(), http.MethodPatch, ts.URL+"/api/config", http.NoBody)
if err != nil {
t.Fatalf("patch request: %v", err)
@@ -268,8 +264,8 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
t.Fatalf("PATCH /api/config: %v", err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusServiceUnavailable {
t.Errorf("PATCH /api/config = %d, want 503: the daemon stays the configuration writer (PRD lines 95-96)", resp.StatusCode)
if resp.StatusCode != http.StatusMethodNotAllowed {
t.Errorf("PATCH /api/config = %d, want 405: configuration is read here and written through the control plane", resp.StatusCode)
}
// The run-detail reads. These three routes have no fake behind them: the