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(storage): preserve disabled legacy default repair

cyh07ffa6adb955
diff --git a/storage/alembic/versions/20260530_0008_remove_legacy_default_agent.py b/storage/alembic/versions/20260530_0008_remove_legacy_default_agent.py
index bddda8ce1..37e1a4e35 100644
--- a/storage/alembic/versions/20260530_0008_remove_legacy_default_agent.py
+++ b/storage/alembic/versions/20260530_0008_remove_legacy_default_agent.py
@@ -36,7 +36,7 @@ def upgrade() -> None:
return
backend = str(legacy["backend"])
- target = _backend_default_agent(bind, backend)
+ target = _backend_default_agent(bind, backend, legacy_enabled=bool(legacy["enabled"]))
if target is None:
return
@@ -105,7 +105,7 @@ def _is_unmodified_legacy_default_agent(agent: dict[str, Any]) -> bool:
)
-def _backend_default_agent(bind, backend: str) -> dict[str, Any] | None:
+def _backend_default_agent(bind, backend: str, *, legacy_enabled: bool) -> dict[str, Any] | None:
row = bind.exec_driver_sql(
"""
select id, name, backend, enabled, source, metadata_json
@@ -116,7 +116,7 @@ def _backend_default_agent(bind, backend: str) -> dict[str, Any] | None:
(backend,),
).fetchone()
if row is None:
- return _insert_backend_default_agent(bind, backend)
+ return _insert_backend_default_agent(bind, backend, enabled=legacy_enabled)
agent_id, name, existing_backend, enabled, source, metadata_json = row
metadata = _json_loads(metadata_json, {})
@@ -132,7 +132,7 @@ def _backend_default_agent(bind, backend: str) -> dict[str, Any] | None:
return {"id": agent_id, "name": str(name), "backend": existing_backend}
-def _insert_backend_default_agent(bind, backend: str) -> dict[str, Any]:
+def _insert_backend_default_agent(bind, backend: str, *, enabled: bool) -> dict[str, Any]:
now = _utc_now_iso()
metadata = {**_BUILTIN_DEFAULT_METADATA, "backend": backend, "backend_enabled": True}
agent_id = uuid.uuid4().hex[:12]
@@ -141,7 +141,7 @@ def _insert_backend_default_agent(bind, backend: str) -> dict[str, Any]:
insert into agents (
id, name, normalized_name, description, backend, model, reasoning_effort,
system_prompt, enabled, source, source_ref, metadata_json, created_at, updated_at
- ) values (?, ?, ?, ?, ?, null, null, null, 1, 'builtin', null, ?, ?, ?)
+ ) values (?, ?, ?, ?, ?, null, null, null, ?, 'builtin', null, ?, ?, ?)
""",
(
agent_id,
@@ -149,6 +149,7 @@ def _insert_backend_default_agent(bind, backend: str) -> dict[str, Any]:
backend,
f"Default {backend} agent.",
backend,
+ 1 if enabled else 0,
_json_dumps(metadata),
now,
now,
diff --git a/tests/test_sqlite_state_migration.py b/tests/test_sqlite_state_migration.py
index b00c6f11f..d8dd05677 100644
--- a/tests/test_sqlite_state_migration.py
+++ b/tests/test_sqlite_state_migration.py
@@ -436,6 +436,55 @@ def test_run_migrations_creates_backend_default_before_removing_legacy_default(t
assert json.loads(default_pointer) == "opencode"
+def test_run_migrations_preserves_disabled_legacy_default_when_creating_backend_default(tmp_path: Path) -> None:
+ db_path = tmp_path / "vibe.sqlite"
+ engine = create_sqlite_engine(db_path)
+ try:
+ metadata.create_all(engine)
+ finally:
+ engine.dispose()
+
+ with sqlite3.connect(db_path) as conn:
+ conn.executescript(
+ """
+ insert into agents (
+ id, name, normalized_name, description, backend, model, reasoning_effort,
+ system_prompt, enabled, source, source_ref, metadata_json, created_at, updated_at
+ ) values (
+ 'agent-default', 'default', 'default', 'Default Vibe Remote agent.', 'opencode',
+ null, null, null, 0, 'builtin', null, '{"builtin":true}', 'now', 'now'
+ );
+ insert into state_meta (key, value_json, updated_at)
+ values ('default_agent_name', '"default"', 'now');
+ create table alembic_version (version_num varchar(32) not null);
+ insert into alembic_version values ('20260529_0007');
+ """
+ )
+ conn.commit()
+
+ run_migrations(db_path)
+
+ with sqlite3.connect(db_path) as conn:
+ agent = conn.execute(
+ "select name, backend, enabled, source, metadata_json from agents"
+ ).fetchone()
+ default_pointer = conn.execute(
+ "select value_json from state_meta where key = 'default_agent_name'"
+ ).fetchone()[0]
+ version = conn.execute("select version_num from alembic_version").fetchone()
+
+ assert version == (HEAD_REVISION,)
+ assert agent[0:4] == ("opencode", "opencode", 0, "builtin")
+ assert json.loads(agent[4]) == {
+ "builtin": True,
+ "builtin_default": True,
+ "lock_delete": True,
+ "backend": "opencode",
+ "backend_enabled": True,
+ }
+ assert json.loads(default_pointer) == "opencode"
+
+
def test_run_migrations_skips_user_owned_default_agent(tmp_path: Path) -> None:
db_path = tmp_path / "vibe.sqlite"
engine = create_sqlite_engine(db_path)