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(workbench): make project default agent a soft pin until native bind
cyh27423792b122
diff --git a/storage/workbench_sessions_service.py b/storage/workbench_sessions_service.pyindex 4ef014e00..ecb69852e 100644--- a/storage/workbench_sessions_service.py+++ b/storage/workbench_sessions_service.py@@ -269,10 +269,12 @@ def create_session(raise PermissionError(f"Scope is archived: {scope_id}")# Inherit the project's default Agent when the caller didn't pin a backend.# The default lives in ``scope_settings`` (set via Project Settings); adopting- # it at creation pins the backend from the first turn (a session's backend is- # write-once) and makes the chat header open on the right Agent. No project- # default → the fields stay empty and dispatch falls back to the global- # default Vibe Agent. An explicit caller backend always wins.+ # it at creation makes the chat header open on the right Agent and the first+ # turn run on it. It is a SOFT default: until a native conversation exists+ # the user can still re-route the session to any backend or clear it back to+ # the global default (see ``update_session``). No project default → the+ # fields stay empty and dispatch falls back to the global default Vibe+ # Agent. An explicit caller backend always wins.if not agent_backend and scope_row.get("agent_backend"):agent_backend = str(scope_row["agent_backend"])if agent_name is None:@@ -350,15 +352,21 @@ def update_session(if existing is None:raise LookupError(f"Session not found: {session_id}")- # Backend is pinned as soon as the session row has a concrete backend. Allow- # changing the agent/model/effort within the SAME backend; reject a switch to- # a DIFFERENT backend. A plain Workbench chat may still have an EMPTY- # agent_backend (legacy/global-default inheritance), so empty -> concrete is- # the initial pin rather than a backend switch.+ # Backend is pinned once a NATIVE conversation exists: the native can only+ # be resumed by the backend that created it, so switching (or clearing) the+ # backend would strand it. Before the first turn nothing is strandable — a+ # fresh session may carry a project-default backend (see ``create_session``)+ # and the user can still re-route it to ANY backend or clear back to the+ # default. Within the same backend, agent/model/effort changes stay allowed+ # for the session's whole life. Legacy agent-less rows whose native predates+ # the bind-time backend backfill keep the old empty -> concrete "initial+ # pin" escape — the row doesn't know which backend owns its native, and+ # locking them would leave their picker permanently stuck.if (agent_backend is not _UNSET+ and str(existing.native_session_id or "")and str(existing.agent_backend or "")- and str(agent_backend) != str(existing.agent_backend or "")+ and str(agent_backend or "") != str(existing.agent_backend or "")):raise SessionBackendLockedError(session_id=session_id,diff --git a/tests/test_core_services_sessions.py b/tests/test_core_services_sessions.pyindex d6737c3b5..4e4b5b3c8 100644--- a/tests/test_core_services_sessions.py+++ b/tests/test_core_services_sessions.py@@ -19,7 +19,7 @@ from core.services import sessions as sessions_servicefrom storage import workbench_sessions_service as storage_sessionsfrom storage.db import create_sqlite_enginefrom storage.importer import ensure_sqlite_state-from storage.models import scope_settings+from storage.models import agent_sessions, scope_settingsfrom storage.settings_service import upsert_scope@@ -414,10 +414,48 @@ def test_reset_running_agent_status_clears_only_running(isolated_state):assert sessions_service.get_session(conn, failed)["agent_status"] == "failed"-def test_update_session_pins_concrete_backend_at_creation(isolated_state):- """A session is locked to its backend once it has a concrete backend:- same-backend agent/model changes are allowed; a cross-backend switch raises- SessionBackendLockedError."""+def _bind_native(conn, session_id: str, native_id: str = "native-1") -> None:+ """Simulate the first turn's native bind (``bind_agent_session_by_id``)."""+ conn.execute(+ agent_sessions.update()+ .where(agent_sessions.c.id == session_id)+ .values(native_session_id=native_id)+ )+++def test_update_session_backend_is_free_until_native_bind(isolated_state):+ """A concrete backend at creation (e.g. inherited from the project's default+ Agent) is a SOFT default: until a native conversation exists the session can+ be re-routed to a DIFFERENT backend, or cleared back to the default."""++ engine = create_sqlite_engine()+ with engine.begin() as conn:+ scope_id = _seed_avibe_scope(conn)+ sid = sessions_service.create_session(+ conn, scope_id=scope_id, agent_backend="claude", agent_name="claude"+ )["id"]+ # No native yet → cross-backend re-route is allowed.+ sessions_service.update_session(conn, sid, agent_backend="codex", agent_name="codex")+ assert sessions_service.get_session(conn, sid)["agent_backend"] == "codex"+ # ... and so is clearing back to the inherited default.+ sessions_service.update_session(+ conn,+ sid,+ agent_backend=None,+ agent_name=None,+ agent_id=None,+ agent_variant=None,+ model=None,+ reasoning_effort=None,+ )+ assert not sessions_service.get_session(conn, sid)["agent_backend"]+++def test_update_session_locks_backend_once_native_exists(isolated_state):+ """Once the first turn bound a native conversation the backend is pinned for+ life — the native can only be resumed by the backend that created it.+ Same-backend agent/model changes stay allowed; a cross-backend switch or a+ clear back to default raises SessionBackendLockedError."""engine = create_sqlite_engine()with engine.begin() as conn:@@ -425,50 +463,32 @@ def test_update_session_pins_concrete_backend_at_creation(isolated_state):sid = sessions_service.create_session(conn, scope_id=scope_id, agent_backend="claude", agent_name="claude")["id"]+ _bind_native(conn, sid)# Same-backend change (different agent / model) is still allowed.sessions_service.update_session(conn, sid, agent_backend="claude", agent_name="claude-pro", model="opus")# Cross-backend switch is rejected.with pytest.raises(sessions_service.SessionBackendLockedError):sessions_service.update_session(conn, sid, agent_backend="codex", agent_name="codex")+ # Clearing back to the inherited default is rejected too: a future+ # default switch could route the old session through another backend.+ with pytest.raises(sessions_service.SessionBackendLockedError):+ sessions_service.update_session(conn, sid, agent_backend=None, agent_name=None)-def test_update_session_blank_backend_takes_first_concrete_pin(isolated_state):- """A plain Workbench chat is created with an EMPTY agent_backend. After its- first real backend selection is the INITIAL pin, not a cross-backend switch- — it must be allowed, then lock the session to that backend going forward."""+def test_update_session_legacy_blank_backend_keeps_initial_pin_escape(isolated_state):+ """Legacy agent-less rows whose native predates the bind-time backend+ backfill don't know which backend owns their native; the empty -> concrete+ "initial pin" stays allowed so their picker isn't permanently stuck. The pin+ then locks the session like any other."""engine = create_sqlite_engine()with engine.begin() as conn:scope_id = _seed_avibe_scope(conn)sid = sessions_service.create_session(conn, scope_id=scope_id, agent_backend="")["id"]- # Empty -> concrete is the first pin.+ _bind_native(conn, sid)+ # Empty -> concrete is the initial pin, even with a native bound.sessions_service.update_session(conn, sid, agent_backend="codex", agent_name="codex")assert sessions_service.get_session(conn, sid)["agent_backend"] == "codex"# Now pinned: a different backend is rejected.with pytest.raises(sessions_service.SessionBackendLockedError):sessions_service.update_session(conn, sid, agent_backend="claude", agent_name="claude")---def test_update_session_pinned_session_cannot_clear_backend_to_default(isolated_state):- """Once a session has a concrete backend, clearing back to inherited default- could let a future default switch route the old session through another- backend."""-- engine = create_sqlite_engine()- with engine.begin() as conn:- scope_id = _seed_avibe_scope(conn)- sid = sessions_service.create_session(- conn, scope_id=scope_id, agent_backend="codex", agent_name="codex"- )["id"]-- with pytest.raises(sessions_service.SessionBackendLockedError):- sessions_service.update_session(- conn,- sid,- agent_backend=None,- agent_name=None,- agent_id=None,- agent_variant=None,- model=None,- reasoning_effort=None,- )diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsxindex b79457f47..5bea1e032 100644--- a/ui/src/components/workbench/ChatPage.tsx+++ b/ui/src/components/workbench/ChatPage.tsx@@ -1044,8 +1044,13 @@ interface ChatHeaderBarProps {const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack }) => {const { t } = useTranslation();const defaultAgent = defaultAgentName ? agents.find((agent) => agent.name === defaultAgentName) : null;- const pinnedBackend = session.agent_backend?.trim() || null;- const canClearToDefault = !pinnedBackend && !session.native_session_id;+ // Backend locks only once a NATIVE conversation exists — a native can only be+ // resumed by the backend that created it (mirrors update_session's guard).+ // Until then a session may carry a project-default backend, but the user can+ // still re-route it to any backend or clear back to the default.+ const hasNative = Boolean(session.native_session_id);+ const pinnedBackend = hasNative ? session.agent_backend?.trim() || null : null;+ const canClearToDefault = !hasNative;const defaultRoute = defaultAgent? {agent_name: defaultAgent.name,