From 5343c68160b49a06e07c7dc8c3447ee2fac78e75 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 10 Aug 2026 01:45:44 +1000 Subject: [PATCH] docs(architecture): record the implemented config reload and runtime overlay Per the sequencing call (adversarial pass first, docs last), the docs now reflect the design the reviews confirmed. configuration.md: - Mutation ledger gains rows for SIGHUP reload, dashboard PATCH, dashboard reset, and the runtime overlay store, each mapping to the universal change protocol with what is and is not yet implemented. - New section 'Implemented runtime reload and config overlay (2026-08)': the Holder published-snapshot model, the reloadable-field criterion (a field is reloadable when EVERY consumer re-reads it), SIGHUP reload semantics, the overlay store (separate -config.sqlite, dotted keys, denylist, bootstrap degrade), and the PATCH/reset paths. safe-change-and-recovery.md: - New section 'Runtime config overlay: degrade paths and recovery' tabulating the three boot degrade paths and the reload degrade, all verified by the adversarial passes, plus the three documented recoveries (--no-config-overlay flag, rm the overlay file, dashboard reset). Status line notes the overlay subset is implemented while the full runtime-supervision protocol remains under design. No new documents, per the constraint. --- docs/architecture/configuration.md | 79 +++++++++++++++++++ docs/architecture/safe-change-and-recovery.md | 35 ++++++++ 2 files changed, 114 insertions(+) diff --git a/docs/architecture/configuration.md b/docs/architecture/configuration.md index b5384dfc3..cd34e43cc 100644 --- a/docs/architecture/configuration.md +++ b/docs/architecture/configuration.md @@ -244,6 +244,10 @@ The application currently changes behavioural values through unrelated paths: | Persona selection | `PersonaRegistry.SetActive` mutates an in-memory per-session choice. | Agent-system session state. Persistence and audit requirements are owned by that domain, not the configuration loader. | | Memory provider `SaveConfig` | Accepts an untyped map, delegates validation/persistence to an optional provider interface, then providers reload backing files. | A typed provider-owned configuration command using candidate validation, versioning, atomic promotion, health observation, audit, and rollback. | | File and environment overlays | Applied while loading `internal/config`; defaults are filled by mutation in `finalize`. | Configuration-infrastructure input processing that produces separately typed candidates. Defaults and derivations remain visible in provenance. | +| SIGHUP config reload (2026-08) | Re-resolves the file config (+ the runtime overlay), validates, then atomically republishes through `config.Holder`. A failed reload keeps the running config and records `last_error`/`last_error_at` in `/api/config`. | Candidate promotion with last-known-good retention: the running snapshot is untouched on failure. A bounded observation period and actor audit are not yet implemented. | +| Dashboard PATCH `/api/config` (2026-08) | Applies dotted-key updates to a deep copy of the published config, validates the materialised result, persists to the runtime overlay, then republishes. Denylisted keys (`db_path`, `work_dir`) return 400; a rejected candidate never reaches `Set`. | The universal change protocol's validate-stage-promote path with the overlay store as persistence. Actor is recorded as `dashboard`; no per-field health observation or versioned audit trail yet. | +| Dashboard reset `POST /api/config/reset` (2026-08) | Deletes one overlay row after resolving and validating the target state, then republishes file + remaining overlay, so a dashboard-created override can be removed without editing SQL. | Remediation/rollback: the last-known-good (file) value is restored for that key. | +| Runtime config overlay store (2026-08) | Dashboard-edited overrides in `cfg.DBPath + "-config.sqlite"` (own `user_version`, own migrator), layered over the file config at boot and on every reload. A broken overlay degrades to file config alone, surfaced via `ReloadStatus.OverlayUnavailable`. | External configuration storage for runtime-tunable values, separate from the task/conversation stores so each file owns its migration. The `--no-config-overlay` / `ARCHIE_SKIP_CONFIG_OVERLAY=1` recovery hatch skips it entirely. | Any further mutation seam discovered during migration MUST be added here before it is changed. Direct field assignment on a live settings object is prohibited. @@ -274,6 +278,81 @@ Settings that cannot safely reload in-process are marked restart-required. The change may still be validated and versioned immediately, but promotion occurs through a controlled restart with the same health and rollback semantics. +## Implemented runtime reload and config overlay (2026-08) + +A first implementation of the universal change protocol now exists for the +runtime-tunable surface: SIGHUP reload, the dashboard PATCH, and the runtime +config overlay. The mechanics below are the current implementation; the +aspirational protocol (bounded observation, versioned audit trail, per-actor +audit) remains future work. + +### Published snapshot: `config.Holder` + +The running configuration is a published snapshot held in `config.Holder` +(`internal/config/holder.go`). Get returns a value under RLock; Set replaces the +whole snapshot. A published Config is immutable: reload constructs a fresh one +and calls Set. `config.Clone` deep-copies every reference-type field so a failed +decode cannot mutate the published snapshot's shared maps. `Holder.Get` panics +on a nil receiver — a forgotten `NewHolder` must fail loudly, not boot a daemon +that silently runs on an empty config. + +### The reloadable-field criterion + +The diff-and-warn on reload asks whether a changed field takes effect without a +restart. The criterion is: **a field is reloadable when every consumer re-reads +it.** That question read as "what does the daemon re-read" while the daemon owned +the only Holder; it stopped being sufficient when webui began sharing that +Holder, because webui handlers re-read on every request. The allowlist lives in +`cmd/archied/reload.go` and is deliberately a deny-by-default list: a field added +to Config later defaults to requires-restart, forcing whoever adds it to decide +deliberately. A reload that changes any non-allowlisted field logs +"requires a restart" with the field names; a fully-applied reload logs Info. + +### SIGHUP reload + +SIGHUP re-resolves the file config (plus the runtime overlay), validates, and +atomically republishes through the shared Holder. A failed reload — bad file, +bad overlay — keeps the running config and records `last_error`/`last_error_at` +in `/api/config` so the stale state is visible where the operator is looking. +The three poll tickers re-read `PollInterval` per iteration and reset on change, +so a reloaded interval genuinely takes effect. + +### The runtime config overlay + +The dashboard's edits persist to a dedicated SQLite file +(`cfg.DBPath + "-config.sqlite"`, its own `user_version` and migrator — no +contention with the task or conversation stores). The `config_overlay` table +stores dotted-path keys with JSON-encoded values; the daemon layers them over +the file config at boot and on every reload, with the same field-level +precedence as a file overlay. + +- **Denylist:** `db_path` and `work_dir` cannot be set (the daemon must read them + before it can open the overlay store; changing them could break the next + boot). Enforced at write time with a 400 and in the store. +- **Bootstrap degrade:** a broken overlay (unopenable store, unreadable value, + values failing validation) degrades to file config alone — it must not brick +the daemon. The reason is surfaced via `ReloadStatus.OverlayUnavailable` in +`/api/config` and rendered as a banner by the dashboard. +- **Recovery hatch:** `--no-config-overlay` / `ARCHIE_SKIP_CONFIG_OVERLAY=1` + skips the overlay entirely; removing the `-config.sqlite` file is the +documented manual recovery. See safe-change-and-recovery.md. +- **Shadowed file edits are visible:** `/api/config` reports which dotted keys +the overlay currently sets (`overridden`), so the dashboard marks those rows and +offers a per-row reset. + +### Dashboard PATCH and reset + +`PATCH /api/config` receives `{"updates": {"dotted.key": value}}`. It applies the +updates to a deep copy of the published config, validates the materialised +result, persists to the overlay, then republishes — it never calls Set directly +from the handler, since the dashboard shares the daemon's Holder. Dotted keys +are nested before decode (yaml cannot decode a dotted key as a struct field). +Error classification: 400 for a denylisted key or failed validation, 503 when +the overlay is disabled, 500 for a persistence failure. `POST /api/config/reset` +deletes one overlay row after resolving and validating the target state, +restoring the file value — the answer to "my file edit isn't taking effect +because an override shadows it". + ## Completion criteria The configuration rearchitecture is complete only when: diff --git a/docs/architecture/safe-change-and-recovery.md b/docs/architecture/safe-change-and-recovery.md index 38f3320f8..718310dc8 100644 --- a/docs/architecture/safe-change-and-recovery.md +++ b/docs/architecture/safe-change-and-recovery.md @@ -100,6 +100,41 @@ capabilities continue operating. Remediation MUST be bounded, observable, and policy-driven. Recovery MUST NOT silently oscillate between versions or retry forever. +## Runtime config overlay: degrade paths and recovery (2026-08) + +The dashboard edits runtime-tunable settings into a dedicated overlay store +(`cfg.DBPath + "-config.sqlite"`), layered over the file config at boot and on +reload. The file remains the authoritative, editor-reachable source; the overlay +is a runtime-tunable overlay on top of it. A broken overlay must never brick +the daemon, for the same reason a bad file edit must not: the operator needs a +path back that does not depend on the daemon's health. + +### Degrade paths (all verified by the reload design) + +| Failure | Boot behaviour | Where the operator sees it | +| --- | --- | --- | +| Overlay store cannot be opened (permissions, corrupt file) | Boots on file config alone; logs at error level | `/api/config` → `reload.overlay_unavailable` → dashboard banner | +| Overlay snapshot unreadable (a row holds invalid JSON) | Boots on file config alone | Same | +| Overlay values fail validation | Boots on file config alone; the overlay is rejected wholesale, never partially applied | Same | +| SIGHUP reload with a bad file or bad overlay | Running config is kept; the reload records `last_error` / `last_error_at` | `/api/config` → `reload.last_error` → dashboard banner | + +The overlay degrade paths never partially apply: `Loader.ApplyOverlay` decodes +into a deep copy (`config.Clone`) and validates before anything is published, +so a rejected overlay leaves the boot config exactly as the file produced it. + +### Recovery + +1. **`--no-config-overlay`** (or `ARCHIE_SKIP_CONFIG_OVERLAY=1`) boots the +daemon on file config alone, ignoring the overlay entirely. This is the escape +hatch that works when the daemon will not start. +2. **Remove the overlay file** (`rm -config.sqlite`) — the overlay is +recreated empty on next boot, so the daemon returns to pure file config. +3. **Dashboard reset** (`POST /api/config/reset`) removes a single override +whose file edit is shadowed, without stopping the daemon. + +These are the documented recovery paths; they are deliberate, bounded, and do +not require hand-editing SQL in a shared database. + ## Gateway restart: two constraints learned the hard way Telegram `/restart` (`internal/channels/telegram/restart.go` plus the `Start`