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(state): reject invalid discovered chat imports
cyhfe8582883d6c
diff --git a/storage/importer.py b/storage/importer.pyindex a18cef144..8b29ada06 100644--- a/storage/importer.py+++ b/storage/importer.py@@ -149,10 +149,10 @@ class _ParsedState:discovered: DiscoveredChatsStore-def _parse_json_state(state_dir: Path, *, primary_platform: str) -> _ParsedState:+def _parse_json_state(state_dir: Path, *, primary_platform: str | None) -> _ParsedState:settings = _load_settings_from_copy(state_dir / "settings.json")sessions = _load_sessions_from_copy(state_dir / "sessions.json", primary_platform=primary_platform)- discovered = DiscoveredChatsStore(state_dir / "discovered_chats.json")+ discovered = _load_discovered_chats_strict(state_dir / "discovered_chats.json")return _ParsedState(settings=settings, sessions=sessions, discovered=discovered)@@ -175,6 +175,14 @@ def _load_sessions_from_copy(source: Path, *, primary_platform: str | None) -> Sreturn state+def _load_discovered_chats_strict(source: Path) -> DiscoveredChatsStore:+ if source.exists():+ payload = json.loads(source.read_text(encoding="utf-8"))+ if not isinstance(payload, dict):+ raise ValueError("discovered_chats.json must contain a JSON object")+ return DiscoveredChatsStore(source)++def _migrate_session_state_for_import(state: SessionState, *, primary_platform: str | None) -> None:if primary_platform is not None and not primary_platform.strip():raise ValueError("primary_platform must be non-empty when provided")diff --git a/tests/test_sqlite_state_migration.py b/tests/test_sqlite_state_migration.pyindex 82fbf38b8..26afb1492 100644--- a/tests/test_sqlite_state_migration.py+++ b/tests/test_sqlite_state_migration.py@@ -149,6 +149,30 @@ def test_failed_json_import_does_not_mark_complete_and_can_retry(tmp_path: Path)assert report.counts["channel_settings"] == 1+def test_invalid_discovered_chats_import_does_not_mark_complete_and_can_retry(tmp_path: Path) -> None:+ state_dir = tmp_path / "state"+ state_dir.mkdir()+ db_path = state_dir / "vibe.sqlite"+ _write_current_settings(state_dir / "settings.json")+ _write_current_sessions(state_dir / "sessions.json")+ (state_dir / "discovered_chats.json").write_text("{not-json", encoding="utf-8")++ with pytest.raises(json.JSONDecodeError):+ ensure_sqlite_state(db_path=db_path, state_dir=state_dir, primary_platform="slack")++ with sqlite3.connect(db_path) as conn:+ marker = conn.execute(+ "select value from schema_meta where key = 'json_import_completed_at'",+ ).fetchone()+ assert marker is None++ _write_discovered_chats(state_dir / "discovered_chats.json")+ report = ensure_sqlite_state(db_path=db_path, state_dir=state_dir, primary_platform="slack")++ assert report.imported is True+ assert report.counts["discovered_chats"] == 1++def test_data_version_probe_detects_external_write(tmp_path: Path) -> None:db_path = tmp_path / "vibe.sqlite"run_migrations(db_path)