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(settings): a settings read never persists, so only an explicit enable authorizes a channel (#2791)

Call Whiteaadefcc84215
diff --git a/core/auth.py b/core/auth.py
index 0ade48f6b..e9fb906ad 100644
--- a/core/auth.py
+++ b/core/auth.py
@@ -139,9 +139,9 @@ def check_auth(
ch = store.find_channel(channel_id)
else:
ch = getattr(getattr(store, "settings", None), "channels", {}).get(channel_id)
- # A channel with no row is not authorized, so a brand-new channel's
- # first inbound message is denied: no settings read runs before this
- # gate on any IM entry point.
+ # Default-deny: a channel is authorized only when someone enabled it
+ # explicitly (the settings UI, or a settings submit from the channel).
+ # A channel with no row is not, and no settings read creates one.
if ch is None or not ch.enabled:
return AuthResult(allowed=False, denial="unauthorized_channel", is_dm=False)
diff --git a/modules/settings_manager.py b/modules/settings_manager.py
index 48652ab67..f243cd0d9 100644
--- a/modules/settings_manager.py
+++ b/modules/settings_manager.py
@@ -315,8 +315,7 @@ class SettingsManager:
"""Get settings for a specific user/channel context.
Checks dm_user_settings first, then channel_settings, then falls back
- to the store. A key with no settings gets the defaults; see below for
- when that default is persisted.
+ to the store. A key with no settings gets the defaults, unsaved.
"""
normalized_id = self._normalize_user_id(user_id)
@@ -348,22 +347,12 @@ class SettingsManager:
self.channel_settings[normalized_id] = settings
return settings
- # Truly new.
- settings = UserSettings()
- if self.platform == "avibe":
- # An Avibe Session's key gates nothing, so its read returns the
- # defaults and saves nothing: a read is on every emit, and the first
- # one of each new Session saved the whole settings state on the
- # controller loop (#2706). Its settings persist when updated.
- return settings
- # On an IM platform this persists an enabled channel row, and that row
- # is what authorizes the channel (core/auth.py): a channel an outbound
- # path reads before anyone enabled it becomes authorized. The read
- # keeps that effect until the owner decides the rule for channels
- # nobody enabled explicitly.
- self.channel_settings[normalized_id] = settings
- self._save_settings()
- return settings
+ # Truly new: the defaults, persisted only when updated. A read never
+ # saves. It is on every emit, so a save here ran on the controller loop
+ # (#2706), and the row it saved was enabled, which authorized an IM
+ # channel nobody enabled (core/auth.py). A channel is authorized only
+ # when someone enables it explicitly.
+ return UserSettings()
def update_user_settings(self, user_id: Union[int, str], settings: UserSettings):
"""Update settings for a specific user"""
diff --git a/tests/test_sqlite_settings_store.py b/tests/test_sqlite_settings_store.py
index c82aae9dc..6295f765f 100644
--- a/tests/test_sqlite_settings_store.py
+++ b/tests/test_sqlite_settings_store.py
@@ -1271,54 +1271,96 @@ def test_sqlite_filters_deprecated_system_message_type(tmp_path: Path) -> None:
assert legacy.users["slack::U1"].show_message_types == ["toolcall"]
-def test_an_avibe_session_read_returns_defaults_and_saves_nothing(tmp_path: Path, monkeypatch) -> None:
- """#2706: the first emit of each new Web Session read its settings and saved them on the loop."""
+_PLATFORMS = ["avibe", "slack", "discord", "lark", "telegram", "wechat"]
- monkeypatch.setattr(paths, "ensure_data_dirs", lambda: None)
- manager = SettingsManager(settings_file=str(tmp_path / "settings.json"), platform="avibe")
- try:
- saves: list[str] = []
- monkeypatch.setattr(manager.store, "save", lambda **_kwargs: saves.append("save"))
- hidden = manager.is_message_type_hidden("ses-new", "toolcall")
- routing = manager.get_channel_routing("ses-new")
+def isolated_settings_home(tmp_path: Path, monkeypatch):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ SettingsStore.reset_instance()
+ yield
+ SettingsStore.reset_instance()
- assert hidden is ("toolcall" not in UserSettings().show_message_types)
- assert routing is None
- assert saves == []
- assert manager.store.find_channel("ses-new", platform="avibe") is None
- finally:
- manager.store.close()
+def _outbound_touch(manager: SettingsManager, key: str) -> None:
+ """The settings reads an outbound path makes: an emit's visibility check, routing, a working directory."""
[email protected]("platform", ["slack", "discord", "lark"])
-def test_a_new_im_channel_keeps_todays_authorization_outcomes(tmp_path: Path, monkeypatch, platform) -> None:
- """Its first inbound message is denied, and a settings read still authorizes it, as on master.
+ manager.is_message_type_hidden(key, "toolcall")
+ manager.get_channel_routing(key)
+ manager.get_custom_cwd(key)
- Whether a channel nobody enabled explicitly should be authorized by such a
- read is the owner's decision; until then the read keeps its effect.
- """
[email protected]("platform", _PLATFORMS)
+def test_a_settings_read_returns_defaults_and_saves_nothing(isolated_settings_home, monkeypatch, platform) -> None:
+ """#2706: every emit reads settings, and the first read of each new key saved them on the loop."""
+
+ manager = SettingsManager(platform=platform)
+ saves: list[str] = []
+ monkeypatch.setattr(manager.store, "save", lambda **_kwargs: saves.append("save"))
+
+ _outbound_touch(manager, "key-new")
+
+ assert manager.is_message_type_hidden("key-new", "toolcall") is ("toolcall" not in UserSettings().show_message_types)
+ assert manager.get_channel_routing("key-new") is None
+ assert saves == []
+ assert manager.store.find_channel("key-new", platform=platform) is None
+
+
+def _inbound(manager: SettingsManager, platform: str, *, channel_id: str, user_id: str = "U-1"):
from core.auth import check_auth
- monkeypatch.setattr(paths, "ensure_data_dirs", lambda: None)
- manager = SettingsManager(settings_file=str(tmp_path / "settings.json"), platform=platform)
- try:
- def first_inbound():
- return check_auth(
- user_id="U-1",
- channel_id="C-new",
- is_dm=False,
- platform=platform,
- action="",
- settings_manager=manager,
- )
+ # WeChat has no channels: every chat is a direct message, gated by binding.
+ return check_auth(
+ user_id=user_id if platform != "wechat" else channel_id,
+ channel_id=channel_id,
+ is_dm=platform == "wechat",
+ platform=platform,
+ action="",
+ settings_manager=manager,
+ )
- denied = first_inbound()
- assert (denied.allowed, denied.denial) == (False, "unauthorized_channel")
- manager.get_channel_routing("C-new")
[email protected]("platform", ["slack", "discord", "lark", "telegram", "wechat"])
+def test_only_an_explicit_enable_authorizes_a_chat_an_outbound_path_touched(isolated_settings_home, platform) -> None:
+ """Default-deny (owner decision, 2026-10-17): posting into a chat never lets people there drive the bot.
- assert first_inbound().allowed is True
- finally:
- manager.store.close()
+ A Run or scheduled task may post into a chat nobody enabled; its settings
+ reads used to persist an enabled row, which authorized the chat by side
+ effect. Only the settings UI enables a channel; WeChat chats are enabled by
+ binding the contact.
+ """
+
+ from vibe import api
+
+ manager = SettingsManager(platform=platform)
+ _outbound_touch(manager, "chat-new")
+
+ denied = _inbound(manager, platform, channel_id="chat-new")
+ assert denied.allowed is False
+ assert denied.denial == ("unbound_dm" if platform == "wechat" else "unauthorized_channel")
+
+ if platform == "wechat":
+ api.save_users({"platform": platform, "users": {"chat-new": {"display_name": "Contact", "enabled": True}}})
+ else:
+ api.save_settings({"platform": platform, "channels": {"chat-new": {"enabled": True}}})
+
+ assert _inbound(manager, platform, channel_id="chat-new").allowed is True
+
+
[email protected]("platform", ["slack", "discord", "lark", "telegram"])
+def test_existing_channel_rows_keep_their_authorization(isolated_settings_home, platform) -> None:
+ """Rows persisted before default-deny, enabled explicitly or by the old read, stay as they are."""
+
+ store = SettingsStore.get_instance()
+ store.update_channel("C-on", ChannelSettings(enabled=True), platform=platform)
+ store.update_channel("C-off", ChannelSettings(enabled=False), platform=platform)
+ store.save()
+ manager = SettingsManager(platform=platform)
+
+ for key in ("C-on", "C-off"):
+ _outbound_touch(manager, key)
+
+ assert _inbound(manager, platform, channel_id="C-on").allowed is True
+ assert _inbound(manager, platform, channel_id="C-off").denial == "unauthorized_channel"
+ assert manager.store.find_channel("C-on", platform=platform).enabled is True
+ assert manager.store.find_channel("C-off", platform=platform).enabled is False