Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(config): field-complete config serializers (stop dropping ui.show_agent_activity / agents.avault) (#939)

Call Whitef4d80f2bf994
diff --git a/docs/plans/config-field-completeness.md b/docs/plans/config-field-completeness.md
new file mode 100644
index 000000000..5c3b57901
--- /dev/null
+++ b/docs/plans/config-field-completeness.md
@@ -0,0 +1,85 @@
+# Config field completeness — dropped `ui.show_agent_activity` investigation
+
+## Symptom
+
+A regression instance's `config.ui.show_agent_activity` was observed flipped
+`true → false`, with `config.json` rewritten mid-deploy. Framed as a possible
+"settings silently lost on upgrade" data-loss bug.
+
+## What the config writers actually do (verified hermetically, temp `AVIBE_HOME`)
+
+| Writer | Mechanism | `ui.show_agent_activity` |
+| --- | --- | --- |
+| `V2Config.save()` | top-level keys hand-listed, nested `ui` via `self.ui.__dict__` | **preserved** |
+| `api.save_config()` (UI save) | deep-merge onto `config_to_payload(load_config())` → `from_payload` → `save` | **preserved** (recursive merge) |
+| `api.config_to_payload()` | `ui` via `{**config.ui.__dict__}` | **preserved** |
+| `_persist_avault_cli_path` (`vibe runtime prepare`) | `load_config()` → mutate → `save()` | **preserved** |
+| boot `_migrate_language_from_settings` | `load()` → set language → `save()` | **preserved** |
+| `scripts/incus_regression.py:normalize_runtime_config` | raw `json` round-trip of the whole payload | **preserved** |
+| `scripts/prepare_regression.py:_build_config_payload` | hand-listed `ui` subset; **fresh/reset** rebuild only | default (fresh) |
+| `scripts/incus_tenant.py:default_config` | hand-listed `ui` subset; **fresh tenant** cloud-init only | default (fresh) |
+
+Conclusion: **no runtime/upgrade writer drops `show_agent_activity`** — it is
+always serialized wholesale via `ui.__dict__` (this is why a plain service
+restart and any UI save preserve it). The provisioning scripts emit only the
+fields they override and let `V2Config.from_payload` fill the rest with
+`UiConfig` defaults; they run only when a *new* config is intentionally created
+(regression `--reset-mode config|all` / missing config, or fresh-tenant
+cloud-init), so a default `show_agent_activity` there is the correct fresh state,
+not lost user data. On a state-preserving regression deploy the seed step is
+skipped entirely (`run_prepare_state` early-returns), so those scripts do not run.
+
+On the reported non-reset deploy the seed was skipped; the mid-deploy
+`config.json` write matches the avault dependency-refresh writer
+(`_persist_avault_cli_path`), which is load-modify-save and **preserves** the
+field. The `false` state therefore predates that deploy (an earlier reset/reseed,
+or a toggle that did not persist) rather than being flipped by it. Exact
+attribution needs the instance's config history — out of scope for this change.
+
+## The real bug (root cause)
+
+Full-config serialization is done by **multiple hand-maintained field lists**
+(`V2Config.save`, `api.config_to_payload`). The confirmed, real-user-facing
+instance:
+
+**`api.config_to_payload` omitted `agents.avault`.** That payload is the
+deep-merge *base* for every UI save (`save_config`), so **every UI config save
+silently reset `agents.avault.cli_path`** to the dataclass default. Same class as
+the earlier `config_to_payload` status-bubble omission already guarded by
+`test_save_config_preserves_status_bubble_settings_on_partial_save`.
+
+## Fix
+
+- `api.config_to_payload`: emit `agents.avault` (mirror `V2Config.save`).
+- **Mechanism guard** (`test_full_config_serializers_cover_every_config_field`):
+ asserts both `V2Config.save` (on disk) and `config_to_payload` emit every
+ top-level `V2Config` field, every `UiConfig` sub-field, and every agent
+ backend. A newly-added field hand-listed into only one serializer now fails
+ CI — closing the class on the two runtime serializers that operate on an
+ existing user config.
+
+### Deliberately not changed
+
+The provisioning scripts (`prepare_regression.py`, `incus_tenant.py`) keep their
+minimal ui override. They build *fresh* configs where `from_payload` fills the
+rest with `UiConfig` defaults (correct by construction), and `incus_tenant.py` is
+by contract stdlib-only so it can run on a fresh Incus host before the package is
+installed — importing `config` there would break every subcommand. A reset/reseed
+correctly re-establishes defaults; the non-reset path (`_normalize_existing_state`)
+already preserves the existing config.
+
+## Severity
+
+- **Real-user-facing:** the `config_to_payload` / `agents.avault` omission — every
+ UI save reset a persisted avault path. Fixed + guarded.
+- **Not** a runtime/upgrade data-loss path for `show_agent_activity`:
+ `vibe runtime prepare`, migrations, and boot all preserve it. This corrects the
+ initial "settings lost on upgrade" framing with evidence.
+
+## Evidence layers
+
+- Unit/contract: `tests/test_api_save_config_merge.py` — avault round-trip,
+ partial-save preservation for avault + ui fields, and the field-coverage
+ mechanism guard; existing `tests/test_v2_config_platform_registry.py` round-trip.
+- Manual/hermetic: reproduced the drop and the fix against a temp `AVIBE_HOME`
+ (never touched real `~/.avibe`).
diff --git a/tests/test_api_save_config_merge.py b/tests/test_api_save_config_merge.py
index 3a91b7a68..86741f0ff 100644
--- a/tests/test_api_save_config_merge.py
+++ b/tests/test_api_save_config_merge.py
@@ -2,11 +2,12 @@ from __future__ import annotations
import ast
import sys
+from dataclasses import fields
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
-from config.v2_config import V2Config
+from config.v2_config import UiConfig, V2Config
from vibe import api
@@ -746,3 +747,94 @@ def test_wizard_platform_selection_preserves_credential_drafts_on_continue():
assert "await onSave(nextData);" in source
assert "onNext(nextData);" in source
assert "onNext(selectionData);" not in source
+
+
+# ---------------------------------------------------------------------------
+# Config field-completeness (guards the "partial save silently drops a field"
+# class of bug). ``save_config`` deep-merges the incoming payload onto
+# ``config_to_payload(load_config())`` as its base; any field the base payload
+# omits is lost whenever a save does not itself re-send that field. So every
+# persisted config field MUST appear in both serializers.
+# ---------------------------------------------------------------------------
+
+
+def test_config_to_payload_includes_avault_agent():
+ """Regression: ``config_to_payload`` dropped ``agents.avault`` entirely, so
+ every UI save reset ``agents.avault.cli_path`` to the dataclass default."""
+ config = V2Config.from_payload(_full_config_payload())
+ config.agents.avault.cli_path = "/opt/managed/avault"
+
+ payload = api.config_to_payload(config)
+
+ assert "avault" in payload["agents"]
+ assert payload["agents"]["avault"]["cli_path"] == "/opt/managed/avault"
+
+
+def test_save_config_preserves_avault_cli_path_on_unrelated_partial_save(monkeypatch, tmp_path):
+ """A partial UI save (e.g. toggling ``show_duration``) must NOT reset a
+ previously-persisted ``agents.avault.cli_path`` (set by ``vibe runtime
+ prepare`` -> ``_persist_avault_cli_path``)."""
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+
+ full = _full_config_payload()
+ full["agents"]["avault"] = {"cli_path": "/opt/managed/avault"}
+ created = api.save_config(full)
+ assert created.agents.avault.cli_path == "/opt/managed/avault"
+
+ updated = api.save_config({"show_duration": False})
+
+ assert updated.agents.avault.cli_path == "/opt/managed/avault"
+ assert api.config_to_payload(updated)["agents"]["avault"]["cli_path"] == "/opt/managed/avault"
+
+
+def test_save_config_preserves_ui_fields_on_unrelated_partial_save(monkeypatch, tmp_path):
+ """The owner-facing scenario: after enabling ``show_agent_activity`` (and a
+ custom font size / instance name), an unrelated partial save must keep them.
+ Guards the ``ui`` sub-block of the deep-merge base."""
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+
+ full = _full_config_payload()
+ full["ui"] = {
+ **full["ui"],
+ "show_agent_activity": True,
+ "chat_message_font_size": 20,
+ "instance_name": "OwnerBox",
+ }
+ created = api.save_config(full)
+ assert created.ui.show_agent_activity is True
+
+ updated = api.save_config({"show_duration": False})
+
+ assert updated.ui.show_agent_activity is True
+ assert updated.ui.chat_message_font_size == 20
+ assert updated.ui.instance_name == "OwnerBox"
+
+
+def test_full_config_serializers_cover_every_config_field(monkeypatch, tmp_path):
+ """Mechanism guard for the whole class: both full-config serializers
+ (``V2Config.save`` on disk and ``config_to_payload``, the save merge base)
+ must emit every persisted field — top-level, every ``UiConfig`` sub-field,
+ and every agent backend. A newly-added field hand-listed into only one
+ serializer (or neither) fails here, so it cannot silently drop on save."""
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+
+ config = api.save_config(_full_config_payload())
+
+ ui_field_names = {f.name for f in fields(UiConfig)}
+ # ``platform_configs`` is the internal per-platform aggregate; it is emitted
+ # under each platform's own key, not as a top-level ``platform_configs`` key.
+ top_level = {f.name for f in fields(V2Config)} - {"platform_configs"}
+ agents = {"opencode", "claude", "codex", "avault"}
+
+ def _assert_complete(label: str, payload: dict) -> None:
+ assert top_level <= set(payload), f"{label} top-level missing: {top_level - set(payload)}"
+ assert ui_field_names <= set(payload["ui"]), f"{label} ui missing: {ui_field_names - set(payload['ui'])}"
+ assert agents <= set(payload["agents"]), f"{label} agents missing: {agents - set(payload['agents'])}"
+
+ _assert_complete("config_to_payload", api.config_to_payload(config))
+
+ import json
+
+ from config import paths
+
+ _assert_complete("V2Config.save", json.loads(paths.get_config_path().read_text(encoding="utf-8")))
diff --git a/vibe/api.py b/vibe/api.py
index 6c4c238b8..b4ff01246 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -1009,6 +1009,10 @@ def config_to_payload(config: V2Config, *, include_secrets: bool = False) -> dic
"opencode": config.agents.opencode.__dict__,
"claude": _agent_payload(config.agents.claude.__dict__, include_secrets=include_secrets),
"codex": _agent_payload(config.agents.codex.__dict__, include_secrets=include_secrets),
+ # Mirror ``V2Config.save`` — avault must be emitted here too, or every
+ # UI save (which uses this payload as the deep-merge base) silently
+ # resets ``agents.avault.cli_path`` to the dataclass default.
+ "avault": config.agents.avault.__dict__,
},
"gateway": _project_secret_fields(
config.gateway.__dict__ if config.gateway else None,