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): an Avibe Session's settings read saves nothing (#2789)

Call White0212d02f9a82
diff --git a/core/auth.py b/core/auth.py
index adfdb53a8..0ade48f6b 100644
--- a/core/auth.py
+++ b/core/auth.py
@@ -139,7 +139,10 @@ def check_auth(
ch = store.find_channel(channel_id)
else:
ch = getattr(getattr(store, "settings", None), "channels", {}).get(channel_id)
- if not ch or not ch.enabled:
+ # 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.
+ if ch is None or not ch.enabled:
return AuthResult(allowed=False, denial="unauthorized_channel", is_dm=False)
# 2b. Optional per-channel require_bind gate: when enabled, only bound
diff --git a/docs/plans/controller-loop-sqlite-writers.md b/docs/plans/controller-loop-sqlite-writers.md
index 791b6acb0..488c051e8 100644
--- a/docs/plans/controller-loop-sqlite-writers.md
+++ b/docs/plans/controller-loop-sqlite-writers.md
@@ -130,6 +130,18 @@ What it shows:
- **One queued head took 82% of all loop writes.** It had failed to start three times and was held until its owner retried it explicitly. No automatic start can claim such a head. Even so, every runtime-work scan reported it as an open head, and the drain's read-only precheck counted it as claimable. Each scan therefore took SQLite's writer on the loop, the claim refused the head, and the lane backed off for a second and scanned it again, at about 0.9 writes a second. A held head now only moves the scan's cursor, and the drain's precheck no longer counts it as claimable.
- **Every other site averaged under 30 ms per write.** Single writes reached 400–600 ms on the host's disk. `persist_agent_message` (#2725) is the largest of them, at 5.3 s over 1540 writes.
+**Soak 3** (2026-10-17, the same host, gh-v3.2.2rc2 from 05:40 to 11:31). The 11:31 summary counted 24199 writes at 30 sites, with no `database is locked`. Two loop stalls, attributed from the watchdog's stack of the event-loop thread:
+
+| Stall | Event-loop thread | Census site |
+| --- | --- | --- |
+| 10:16:52, 3.5 s | `drain_delivery_queue` -> `reserve_write_lock` (`BEGIN IMMEDIATE`) | 18066 writes, 140 s total, 2981 ms max |
+| 10:55:19, 4.2 s | `emit_agent_message` -> `is_message_type_hidden` -> `get_user_settings` -> `SettingsStore.save` | `settings_service.save_state`: 4 writes, 6.5 s total, 3530 ms max |
+
+What it shows:
+- **The first stall is the held head** of Soak 2. #2781 fixed it after this build.
+- **The second stall is a settings read that saved.** `get_user_settings` persisted a default for every key it had never seen, and every emit reads it (`is_message_type_hidden`), as do the routing reads. On the Avibe platform the key is the Session id, so the first emit of each new Web Session saved the whole settings state on the loop. The host holds 923 such Session rows. An Avibe read now returns the defaults and saves nothing. On IM platforms the same save persists an enabled channel row, which is what authorizes the channel. That is left as it is until the owner decides the rule for channels nobody enabled explicitly.
+- **Everything else stayed under 700 ms per write:** `upsert_activity` (610 writes), `upsert_connection` (140), `bind_agent_session_by_id`, and `persist_agent_message` (about 3,500 writes).
+
The per-Turn admissions all hold the boundary inside the transaction, so they are loop-side boundary holders and fall under B's split analysis:
- `_admit_p0`, `_admit_p1`, `_admit_p3`, `_promote_fifo_head`;
- `drain_delivery_queue`, `_resume_linked_control_successor`.
diff --git a/modules/settings_manager.py b/modules/settings_manager.py
index 4a483119c..48652ab67 100644
--- a/modules/settings_manager.py
+++ b/modules/settings_manager.py
@@ -315,7 +315,8 @@ class SettingsManager:
"""Get settings for a specific user/channel context.
Checks dm_user_settings first, then channel_settings, then falls back
- to the store, and finally creates a default in channel_settings.
+ to the store. A key with no settings gets the defaults; see below for
+ when that default is persisted.
"""
normalized_id = self._normalize_user_id(user_id)
@@ -347,8 +348,19 @@ class SettingsManager:
self.channel_settings[normalized_id] = settings
return settings
- # Truly new — create default in channels
+ # 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
diff --git a/tests/test_sqlite_settings_store.py b/tests/test_sqlite_settings_store.py
index b5e5a8425..c82aae9dc 100644
--- a/tests/test_sqlite_settings_store.py
+++ b/tests/test_sqlite_settings_store.py
@@ -1269,3 +1269,56 @@ def test_sqlite_filters_deprecated_system_message_type(tmp_path: Path) -> None:
reader.close()
assert legacy.channels["slack::C1"].show_message_types == ["assistant"]
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."""
+
+ 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")
+
+ 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()
+
+
[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.
+
+ 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.
+ """
+
+ 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,
+ )
+
+ denied = first_inbound()
+ assert (denied.allowed, denied.denial) == (False, "unauthorized_channel")
+
+ manager.get_channel_routing("C-new")
+
+ assert first_inbound().allowed is True
+ finally:
+ manager.store.close()