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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(storage): validate head schema before stamping
cyh06cda5278f44
diff --git a/storage/migrations.py b/storage/migrations.pyindex 02367e17b..e829aea3f 100644--- a/storage/migrations.py+++ b/storage/migrations.py@@ -67,7 +67,7 @@ def background_tables_ready(db_path: Path | None = None) -> bool:return Falsewith sqlite3.connect(target_db) as conn:tables = _table_names(conn)- return {"background_tasks", "background_runs"}.issubset(tables)+ return _head_schema_ready(conn, tables)def initialize_background_tables(db_path: Path | None = None) -> None:@@ -118,11 +118,8 @@ def _repair_unreleased_head_schema_drift(db_path: Path) -> None:if version != ("20260515_0002",):return- for table, required_columns in HEAD_REQUIRED_COLUMNS.items():- existing_columns = _column_names(conn, table)- if table == "background_tasks" and "deleted_at" not in existing_columns:- conn.execute('alter table "background_tasks" add column "deleted_at" VARCHAR')- conn.commit()+ if _repair_head_required_columns(conn, tables):+ conn.commit()def _stamp_existing_initial_schema(db_path: Path, cfg: Config) -> None:@@ -145,6 +142,13 @@ def _stamp_existing_initial_schema(db_path: Path, cfg: Config) -> None:if not INITIAL_TABLES.issubset(tables):returnif HEAD_TABLES.issubset(tables):+ if not _head_schema_ready(conn, tables):+ _repair_head_required_columns(conn, tables)+ conn.commit()+ tables = _table_names(conn)+ if not _head_schema_ready(conn, tables):+ missing = _missing_head_schema_description(conn, tables)+ raise RuntimeError(f"existing SQLite head schema is incomplete; missing: {missing}")command.stamp(cfg, "head")return@@ -162,3 +166,31 @@ def _table_names(conn: sqlite3.Connection) -> set[str]:def _column_names(conn: sqlite3.Connection, table: str) -> set[str]:return {row[1] for row in conn.execute(f'pragma table_info("{table}")')}+++def _head_schema_ready(conn: sqlite3.Connection, tables: set[str]) -> bool:+ if not HEAD_TABLES.issubset(tables):+ return False+ return all(required_columns.issubset(_column_names(conn, table)) for table, required_columns in HEAD_REQUIRED_COLUMNS.items())+++def _repair_head_required_columns(conn: sqlite3.Connection, tables: set[str]) -> bool:+ if not HEAD_TABLES.issubset(tables):+ return False+ changed = False+ existing_columns = _column_names(conn, "background_tasks")+ if "deleted_at" not in existing_columns:+ conn.execute('alter table "background_tasks" add column "deleted_at" VARCHAR')+ changed = True+ return changed+++def _missing_head_schema_description(conn: sqlite3.Connection, tables: set[str]) -> str:+ missing_parts = [f"tables {', '.join(sorted(HEAD_TABLES - tables))}"] if not HEAD_TABLES.issubset(tables) else []+ for table, required_columns in HEAD_REQUIRED_COLUMNS.items():+ if table not in tables:+ continue+ missing_columns = required_columns - _column_names(conn, table)+ if missing_columns:+ missing_parts.append(f"{table}.{', '.join(sorted(missing_columns))}")+ return "; ".join(missing_parts) or "unknown head schema drift"diff --git a/tests/test_sqlite_state_migration.py b/tests/test_sqlite_state_migration.pyindex 94e3d7acf..b53432e3a 100644--- a/tests/test_sqlite_state_migration.py+++ b/tests/test_sqlite_state_migration.py@@ -10,7 +10,7 @@ import pytestfrom config import pathsfrom storage.db import SqliteInvalidationProbe, create_sqlite_enginefrom storage.importer import ensure_sqlite_state-from storage.migrations import run_migrations+from storage.migrations import background_tables_ready, run_migrationsfrom storage.models import metadata@@ -102,6 +102,48 @@ def test_run_migrations_stamps_existing_initial_schema_with_empty_version_table(assert version == ("20260515_0002",)+def test_run_migrations_repairs_head_columns_before_stamping_head(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:+ columns = [+ row+ for row in conn.execute("pragma table_info(background_tasks)").fetchall()+ if row[1] != "deleted_at"+ ]+ column_defs = []+ for _cid, name, column_type, not_null, default_value, primary_key in columns:+ definition = f'"{name}" {column_type or "TEXT"}'+ if primary_key:+ definition += " PRIMARY KEY"+ if not_null:+ definition += " NOT NULL"+ if default_value is not None:+ definition += f" DEFAULT {default_value}"+ column_defs.append(definition)+ conn.execute('alter table "background_tasks" rename to "background_tasks_old"')+ conn.execute(f'create table "background_tasks" ({", ".join(column_defs)})')+ conn.execute('drop table "background_tasks_old"')+ conn.execute("create table alembic_version (version_num varchar(32) not null)")+ conn.commit()++ assert background_tables_ready(db_path) is False++ run_migrations(db_path)++ with sqlite3.connect(db_path) as conn:+ version = conn.execute("select version_num from alembic_version").fetchone()+ background_columns = {row[1] for row in conn.execute("pragma table_info(background_tasks)")}+ assert version == ("20260515_0002",)+ assert "deleted_at" in background_columns+ assert background_tables_ready(db_path) is True++def test_run_migrations_does_not_stamp_partial_schema_missing_scopes(tmp_path: Path) -> None:db_path = tmp_path / "vibe.sqlite"with sqlite3.connect(db_path) as conn: