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(channels): harden migration and loading cleanup
cyh078fe9669628
diff --git a/core/chat_discovery.py b/core/chat_discovery.pyindex 9f14431b5..a42b4459a 100644--- a/core/chat_discovery.py+++ b/core/chat_discovery.py@@ -54,6 +54,7 @@ _refresh_locks: dict[str, threading.Lock] = {}_scheduled_refreshes_lock = threading.Lock()_scheduled_refreshes: set[str] = set()_migration_lock = threading.Lock()+_legacy_migration_lock = threading.Lock()_migrated_db_paths: set[Path] = set()@@ -528,6 +529,11 @@ def should_refresh(def migrate_legacy_discovered_chats(*, db_path: Path | None = None, legacy_path: Path | None = None) -> None:+ with _legacy_migration_lock:+ _migrate_legacy_discovered_chats_unlocked(db_path=db_path, legacy_path=legacy_path)+++def _migrate_legacy_discovered_chats_unlocked(*, db_path: Path | None = None, legacy_path: Path | None = None) -> None:marker = "migrations.discovered_chats_to_scopes"if get_state_meta(marker, db_path=db_path) == "done":return@@ -539,6 +545,9 @@ def migrate_legacy_discovered_chats(*, db_path: Path | None = None, legacy_path:try:payload = json.loads(source.read_text(encoding="utf-8"))+ except FileNotFoundError:+ set_state_meta(marker, "done", db_path=db_path)+ returnexcept Exception as exc:logger.warning("Skipping malformed legacy discovered chats file %s: %s", source, exc)return@@ -880,8 +889,17 @@ def _payload_native_type(native_type: str) -> str | int:def _rename_preserving_existing(source: Path, target: Path) -> None:+ if not source.exists():+ returnif not target.exists():- source.rename(target)+ try:+ source.rename(target)+ except FileNotFoundError:+ return+ return+ try:+ payload = source.read_text(encoding="utf-8")+ except FileNotFoundError:returnwith tempfile.NamedTemporaryFile(mode="w",@@ -890,7 +908,10 @@ def _rename_preserving_existing(source: Path, target: Path) -> None:delete=False,encoding="utf-8",) as handle:- handle.write(source.read_text(encoding="utf-8"))+ handle.write(payload)temp_path = Path(handle.name)- source.unlink()+ try:+ source.unlink()+ except FileNotFoundError:+ returnlogger.info("Legacy discovered chats file already migrated; preserved duplicate at %s", temp_path)diff --git a/tests/test_chat_discovery.py b/tests/test_chat_discovery.pyindex cf0ba0051..b525cb64a 100644--- a/tests/test_chat_discovery.py+++ b/tests/test_chat_discovery.py@@ -134,6 +134,16 @@ def test_legacy_discovered_chats_migration_is_idempotent(tmp_path: Path) -> Noneassert chat_discovery.get_state_meta("migrations.discovered_chats_to_scopes", db_path=db_path) == "done"+def test_legacy_migration_rename_tolerates_missing_source(tmp_path: Path) -> None:+ source = tmp_path / "discovered_chats.json"+ target = tmp_path / "discovered_chats.json.migrated"++ chat_discovery._rename_preserving_existing(source, target)++ assert source.exists() is False+ assert target.exists() is False++def test_refresh_marks_absent_rows_not_returned_without_deleting_settings(tmp_path: Path, monkeypatch) -> None:db_path = tmp_path / "vibe.sqlite"run_migrations(db_path)diff --git a/ui/src/components/steps/ChannelList.tsx b/ui/src/components/steps/ChannelList.tsxindex afbe36e62..95bc2fe7f 100644--- a/ui/src/components/steps/ChannelList.tsx+++ b/ui/src/components/steps/ChannelList.tsx@@ -106,6 +106,8 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onBconst [channels, setChannels] = useState<any[]>([]);const [browseAll, setBrowseAll] = useState(false);const [loadingAll, setLoadingAll] = useState(false);+ const channelLoadingCountsRef = useRef({ default: 0, all: 0 });+ const allPlatformsLoadingCountRef = useRef(0);// Wizard multi-platform mode: show tabs instead of separate stepsconst isWizardMultiPlatform = !isPage && Array.isArray(wizardPlatforms) && wizardPlatforms.length > 1;const [wizardActivePlatform, setWizardActivePlatform] = useState(forcedPlatform || wizardPlatforms?.[0] || 'slack');@@ -303,6 +305,36 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onBreturn refreshFollowupVersionRef.current;};+ const beginChannelLoading = (all: boolean) => {+ const key: 'default' | 'all' = all ? 'all' : 'default';+ channelLoadingCountsRef.current[key] += 1;+ if (all) {+ setLoadingAll(true);+ } else {+ setLoading(true);+ }+ return key;+ };++ const endChannelLoading = (key: 'default' | 'all') => {+ channelLoadingCountsRef.current[key] = Math.max(0, channelLoadingCountsRef.current[key] - 1);+ if (key === 'all') {+ if (channelLoadingCountsRef.current.all === 0) setLoadingAll(false);+ } else if (channelLoadingCountsRef.current.default === 0) {+ setLoading(false);+ }+ };++ const beginAllPlatformsLoading = () => {+ allPlatformsLoadingCountRef.current += 1;+ setAllLoading(true);+ };++ const endAllPlatformsLoading = () => {+ allPlatformsLoadingCountRef.current = Math.max(0, allPlatformsLoadingCountRef.current - 1);+ if (allPlatformsLoadingCountRef.current === 0) setAllLoading(false);+ };+useEffect(() => () => {invalidateRefreshFollowups();}, [platform, selectedGuild, pageTab, botToken, larkAppId, larkAppSecret, larkDomain]);@@ -410,11 +442,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onBreturn;}const isAll = all ?? browseAll;- if (isAll) {- setLoadingAll(true);- } else {- setLoading(true);- }+ const loadingKey = beginChannelLoading(isAll);try {if (platform === 'lark') {const result = await api.larkChats(larkAppId, larkAppSecret, larkDomain, force);@@ -434,7 +462,6 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB}} else if (platform === 'discord') {if (!selectedGuild) {- setLoading(false);return;}const result = await api.discordChannels(botToken, selectedGuild, force);@@ -458,10 +485,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB} catch (e) {console.error('Failed to load channels:', e);} finally {- if (refreshFollowupVersionRef.current === requestVersion) {- setLoading(false);- setLoadingAll(false);- }+ endChannelLoading(loadingKey);}};@@ -702,7 +726,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onBconst platforms = getEnabledPlatforms(config).filter((p) => platformSupportsChannels(config, p));if (platforms.length === 0) return;const requestVersion = invalidateRefreshFollowups();- setAllLoading(true);+ beginAllPlatformsLoading();try {const results = await Promise.all(platforms.map(async (p) => {@@ -764,9 +788,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onBsetAllConfigsByPlatform(configsByPlatform);if (results.some((r) => r.refreshing)) scheduleAllPlatformsRefreshFollowup();} finally {- if (refreshFollowupVersionRef.current === requestVersion) {- setAllLoading(false);- }+ endAllPlatformsLoading();}};