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(channels): reject unauthenticated cache reads

cyhbc57607d8bc0
diff --git a/core/chat_discovery.py b/core/chat_discovery.py
index fbccbce62..7402d8d9f 100644
--- a/core/chat_discovery.py
+++ b/core/chat_discovery.py
@@ -573,6 +573,18 @@ def channels_response(
migrate_legacy_discovered_chats(db_path=db_path)
refresh_scope = _refresh_scope_for(platform, refresh_kwargs)
auth_context = _auth_context_for(platform, refresh_kwargs)
+ can_refresh = platform in {"slack", "discord", "lark"}
+ if can_refresh and auth_context is None:
+ return {
+ "ok": False,
+ "channels": [],
+ "chats": [],
+ "refreshing": False,
+ "last_attempt_at": None,
+ "last_success_at": None,
+ "error": f"Missing {platform} channel refresh credentials",
+ "summary": _summary([], [], include_private=include_private),
+ }
all_chats = list_chats(
platform,
include_private=True,
@@ -585,7 +597,6 @@ def channels_response(
refreshing = False
error = state.last_error
- can_refresh = platform in {"slack", "discord", "lark"}
if can_refresh and (force or not chats):
result = refresh_platform(platform, force=force, db_path=db_path, **refresh_kwargs)
state = result.refresh_state
diff --git a/tests/test_chat_discovery.py b/tests/test_chat_discovery.py
index b1f490be5..43b813519 100644
--- a/tests/test_chat_discovery.py
+++ b/tests/test_chat_discovery.py
@@ -256,6 +256,24 @@ def test_slack_channel_cache_is_scoped_by_auth_context(tmp_path: Path, monkeypat
assert [channel["id"] for channel in cached_first["channels"]] == ["C_A"]
+def test_active_channel_response_rejects_missing_auth_context_without_cache_read(tmp_path: Path) -> None:
+ db_path = tmp_path / "vibe.sqlite"
+ run_migrations(db_path)
+ chat_discovery.remember_chat(
+ "slack",
+ "C_OLD",
+ name="old workspace",
+ metadata={chat_discovery.METADATA_AUTH_CONTEXT: _auth_context("slack", bot_token="x")},
+ db_path=db_path,
+ )
+
+ response = chat_discovery.channels_response("slack", bot_token="", db_path=db_path)
+
+ assert response["ok"] is False
+ assert response["channels"] == []
+ assert response["error"] == "Missing slack channel refresh credentials"
+
+
def test_discord_refresh_state_is_scoped_by_guild(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.tsx
index d6df7f580..c7a853222 100644
--- a/ui/src/components/steps/ChannelList.tsx
+++ b/ui/src/components/steps/ChannelList.tsx
@@ -296,12 +296,15 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
const larkAppSecret = config.lark?.app_secret || data.lark?.app_secret || '';
const larkDomain = config.lark?.domain || data.lark?.domain || 'feishu';
- useEffect(() => {
- return () => {
- refreshFollowupVersionRef.current += 1;
- Object.values(refreshFollowupTimersRef.current).forEach((timer) => clearTimeout(timer));
- refreshFollowupTimersRef.current = {};
- };
+ const invalidateRefreshFollowups = () => {
+ refreshFollowupVersionRef.current += 1;
+ Object.values(refreshFollowupTimersRef.current).forEach((timer) => clearTimeout(timer));
+ refreshFollowupTimersRef.current = {};
+ return refreshFollowupVersionRef.current;
+ };
+
+ useEffect(() => () => {
+ invalidateRefreshFollowups();
}, [platform, selectedGuild, pageTab, botToken, larkAppId, larkAppSecret, larkDomain]);
useEffect(() => {
@@ -388,6 +391,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
};
const loadChannels = async (all?: boolean, force = false) => {
+ const requestVersion = invalidateRefreshFollowups();
if (platform === 'lark') {
if (!larkAppId || !larkAppSecret) return;
} else if (!botToken) {
@@ -402,6 +406,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
try {
if (platform === 'lark') {
const result = await api.larkChats(larkAppId, larkAppSecret, larkDomain, force);
+ if (refreshFollowupVersionRef.current !== requestVersion) return;
recordRefreshMeta(platform, result);
if (result.ok) {
setChannels(result.channels || []);
@@ -409,6 +414,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
}
} else if (platform === 'telegram') {
const result = await api.telegramChats(false);
+ if (refreshFollowupVersionRef.current !== requestVersion) return;
recordRefreshMeta(platform, result);
if (result.ok) {
setChannels(result.channels || []);
@@ -420,6 +426,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
return;
}
const result = await api.discordChannels(botToken, selectedGuild, force);
+ if (refreshFollowupVersionRef.current !== requestVersion) return;
recordRefreshMeta(platform, result);
if (result.ok) {
const filtered = (result.channels || []).filter((c: any) => c.type === 0 || c.type === 5);
@@ -428,6 +435,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
}
} else {
const result = await api.slackChannels(botToken, isAll, force);
+ if (refreshFollowupVersionRef.current !== requestVersion) return;
recordRefreshMeta(platform, result);
if (result.ok) {
setChannels(result.channels || []);
@@ -438,8 +446,10 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
} catch (e) {
console.error('Failed to load channels:', e);
} finally {
- setLoading(false);
- setLoadingAll(false);
+ if (refreshFollowupVersionRef.current === requestVersion) {
+ setLoading(false);
+ setLoadingAll(false);
+ }
}
};