Commit graph

1 commit

Author SHA1 Message Date
a4f23c226e fix(dashboard): v0.4 C.2.1 -- route PUT /config to multi-file save_section (Rule 17 persistence unblocked)
C.2 surfaced that GUI config saves were broken in the prod multi-file
layout. This fixes it. Pre-existing v0.3-era bug (predates C.2; affected
EVERY config section, not just environmental).

Save flow (before -> after):
  before: PUT /api/config/{section} -> config.py::load_config(config.yaml)
          [monolithic, vanilla YAML] -> blows up on the !include orchestrator
          ("could not determine a constructor for the tag '!include'"),
          then config.py::save_config (same !include-blind path). Every save
          500'd; nothing persisted.
  after:  PUT validates the body by coercing to the section dataclass (runs
          __post_init__ validators, e.g. feed_source), then persists via
          config_loader.py::save_section(section, dict, config_dir) -- the
          multi-file / !include-aware writer. It writes ONLY the section's
          target file (env_feeds.yaml for environmental, notifications.yaml,
          llm.yaml, ...), strips SECRET_FIELDS (traffic.api_key, firms.map_key)
          and extracts LOCAL_FIELDS (ducting lat/lon -> local.yaml). The
          orchestrator config.yaml and its !include directives are never
          re-parsed. Live app.state.config is kept in sync via setattr when
          the section isn't restart-required (no disk reload needed).

Also: save_section now tolerates a top-level LIST section (mesh_sources) --
it cleans each item for secrets and writes the list directly instead of
assuming a dict (which would have crashed). Other callers of save_config are
untouched (it remains valid for the monolithic single-file path).

Files: meshai/dashboard/api/config_routes.py (PUT handler + import),
meshai/config_loader.py (save_section list guard),
tests/test_dashboard_config_save.py (new).

Verification:
- (A) py_compile clean on config_routes.py + config_loader.py.
- (C) pytest -q: 272 passed (269 + 3 new -- save_section writes env_feeds,
  strips secret fields, handles the mesh_sources list section).
- (D) Rebuilt prod; ran the C.2 round-trip again, now SUCCESS: backup
  env_feeds.yaml (md5 dde5d634...), GET then PUT /api/config/environmental ->
  {"saved":true,"restart_required":false} (NO !include error); disk reflected
  it (feed_source on all 10 adapters + central block written); restored from
  backup -> md5 matches original -> DISK_PRISTINE_RESTORED.
- (E) Rule 17 round-trip confirmed: the GUI can now SAVE config that
  round-trips to disk in the multi-file !include layout, secrets staying in
  .env and local fields in local.yaml.

C.3 (quake -> central flip) is now unblocked: feed_source can be flipped and
saved from the GUI.

Follow-up (non-blocking): mesh_sources per-item secret stripping
(mesh_sources.*.api_token) isn't matched by the section-relative check in the
new list path; mesh_sources files are volume-only (not git) and this was no
worse before, but worth tightening when mesh_sources GUI save is exercised.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 03:17:30 +00:00