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(acl): close provision and session gaps
Maxvintf933dad1a33f
diff --git a/storage/vault_service.py b/storage/vault_service.pyindex ad886190b..233269ab7 100644--- a/storage/vault_service.py+++ b/storage/vault_service.py@@ -3757,7 +3757,12 @@ def list_requests(return [_request_row_payload(row, conn=conn, audience=REQUEST_AUDIENCE_UI) for row in rows]-def resolve_pending_provision_request_by_name(conn: Connection, name: str) -> tuple[dict[str, Any] | None, bool]:+def resolve_pending_provision_request_by_name(+ conn: Connection,+ name: str,+ *,+ user_context: Any = None,+) -> tuple[dict[str, Any] | None, bool]:_expire_pending_requests(conn)rows = list(conn.execute(@@ -3771,8 +3776,11 @@ def resolve_pending_provision_request_by_name(conn: Connection, name: str) -> tu.limit(2)).mappings())- if len(rows) == 1:- return _request_row_payload(dict(rows[0]), conn=conn, audience=REQUEST_AUDIENCE_UI), False+ row_dicts = [dict(row) for row in rows]+ for row in row_dicts:+ _require_request_secret_access(conn, row, user_context=user_context)+ if len(row_dicts) == 1:+ return _request_row_payload(row_dicts[0], conn=conn, audience=REQUEST_AUDIENCE_UI), Falsereturn None, len(rows) > 1@@ -3781,7 +3789,12 @@ def find_pending_provision_request(conn: Connection, name: str) -> dict[str, Anyreturn request-def get_pending_provision_request(conn: Connection, request_id: str) -> dict[str, Any] | None:+def get_pending_provision_request(+ conn: Connection,+ request_id: str,+ *,+ user_context: Any = None,+) -> dict[str, Any] | None:_expire_pending_requests(conn)row = (conn.execute(@@ -3798,7 +3811,9 @@ def get_pending_provision_request(conn: Connection, request_id: str) -> dict[str)if row is None:return None- return _request_row_payload(dict(row), conn=conn, audience=REQUEST_AUDIENCE_UI)+ row_dict = dict(row)+ _require_request_secret_access(conn, row_dict, user_context=user_context)+ return _request_row_payload(row_dict, conn=conn, audience=REQUEST_AUDIENCE_UI)def _expire_grant_rows(diff --git a/storage/workbench_sessions_service.py b/storage/workbench_sessions_service.pyindex b273f28d8..24281fde1 100644--- a/storage/workbench_sessions_service.py+++ b/storage/workbench_sessions_service.py@@ -359,12 +359,18 @@ def create_session(agent_backend = default_agent.backendif agent_name or agent_id:- ensure_agent_selection_access(+ selected_agent = ensure_agent_selection_access(conn,agent_name=agent_name,agent_id=agent_id,user_context=context,)+ if selected_agent is not None:+ if agent_backend and agent_backend != selected_agent.backend:+ raise ValueError("Agent backend does not match selected Agent")+ agent_id = selected_agent.id+ agent_name = selected_agent.name+ agent_backend = selected_agent.backendnow = _utc_now_iso()variant = agent_variant or agent_backend or "default"@@ -447,32 +453,57 @@ def update_session(raise LookupError(f"Session not found: {session_id}")derived_backend = False- if agent_name is not _UNSET and agent_backend is _UNSET:- agent_backend = _backend_for_agent_name(conn, str(agent_name or "")) if agent_name else None- derived_backend = True-- from core.vibe_agents import VibeAgentAccessError, ensure_agent_selection_access, resolve_resource_access_context+ from core.vibe_agents import (+ VibeAgentAccessError,+ ensure_agent_selection_access,+ ensure_default_agent_access,+ resolve_resource_access_context,+ )context = resolve_resource_access_context(user_context)- requested_agent_name = "" if agent_name is _UNSET else str(agent_name or "").strip()- requested_agent_id = "" if agent_id is _UNSET else str(agent_id or "").strip()+ selector_changed = agent_name is not _UNSET or agent_id is not _UNSET+ selected_agent = None+ if selector_changed:+ selected_agent = ensure_agent_selection_access(+ conn,+ agent_name=None if agent_name is _UNSET else agent_name,+ agent_id=None if agent_id is _UNSET else agent_id,+ user_context=context,+ )+ if selected_agent is None and context.is_remote:+ selected_agent = ensure_default_agent_access(+ conn,+ user_context=context,+ missing_is_error=True,+ )+ if selected_agent is not None:+ requested_backend = str(agent_backend or "").strip() if agent_backend is not _UNSET else ""+ if requested_backend and requested_backend != selected_agent.backend:+ raise ValueError("Agent backend does not match selected Agent")+ agent_id = selected_agent.id+ agent_name = selected_agent.name+ if not requested_backend:+ agent_backend = selected_agent.backend+ derived_backend = True+ else:+ # Preserve legacy local names/ids that predate the Agent catalog,+ # but clear the omitted half so it cannot remain stale.+ requested_name = "" if agent_name is _UNSET else str(agent_name or "").strip()+ requested_id = "" if agent_id is _UNSET else str(agent_id or "").strip()+ agent_name = requested_name or None+ agent_id = requested_id or None+ if agent_backend is _UNSET and requested_name:+ agent_backend = _backend_for_agent_name(conn, requested_name)+ derived_backend = True+if (context.is_remoteand agent_backend is not _UNSETand bool(str(agent_backend or "").strip())- and not requested_agent_name- and not requested_agent_id+ and selected_agent is None):raise VibeAgentAccessError("Agent access is not permitted.")- if agent_name is not _UNSET or agent_id is not _UNSET:- ensure_agent_selection_access(- conn,- agent_name=None if agent_name is _UNSET else agent_name,- agent_id=None if agent_id is _UNSET else agent_id,- user_context=context,- )-# 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. A RUNNING turn locks it too — the first turn isdiff --git a/tests/test_remote_resource_acl_sync.py b/tests/test_remote_resource_acl_sync.pyindex b8d3895de..04eb3b2c0 100644--- a/tests/test_remote_resource_acl_sync.py+++ b/tests/test_remote_resource_acl_sync.py@@ -236,6 +236,35 @@ def test_sync_publishes_empty_index_after_last_organization_policy_is_deleted(moassert resource_access_service.list_resource_organization_ids() == []+def test_malformed_intent_keeps_empty_organization_queued_for_retry(monkeypatch) -> None:+ _seed_policy()+ config = _config()+ engine = get_cached_sqlite_engine()+ with engine.begin() as connection:+ assert resource_access_service.delete_resource_policy(connection, "agent", "agent-1")++ responses = iter(+ [+ _Response({"organization_id": "org-1", "resources": []}),+ _Response(+ {+ "organization_id": "org-1",+ "poll_after_seconds": 30,+ "intents": [{"resource_kind": "invalid"}],+ }+ ),+ ]+ )+ monkeypatch.setattr(remote_access.requests, "request", lambda *_args, **_kwargs: next(responses))++ result = remote_access.sync_resource_acl_once(config)++ assert result["ok"] is False+ assert result["organizations"][0]["rejected"] == 1+ assert result["organizations"][0]["ack_errors"] == 1+ assert resource_access_service.list_resource_organization_ids() == ["org-1"]++def test_poll_delay_honors_successful_organization_backoff() -> None:result = {"ok": False,diff --git a/tests/test_resource_acl_agents.py b/tests/test_resource_acl_agents.pyindex a920244d3..09f44ce2e 100644--- a/tests/test_resource_acl_agents.py+++ b/tests/test_resource_acl_agents.py@@ -177,6 +177,54 @@ def test_remote_agent_creation_defaults_to_private_organization_policy(monkeypatassert policy["access_level"] == "private"+def test_remote_partial_agent_updates_persist_canonical_selector_pair(monkeypatch, tmp_path) -> None:+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ store, agents = _seed_agents_with_policies()+ store.close()+ engine = get_cached_sqlite_engine()+ with engine.begin() as connection:+ scope_id = upsert_scope(+ connection,+ platform="avibe",+ scope_type="project",+ native_id="proj_partial_agent",+ now="2026-07-20T00:00:00Z",+ )+ session = workbench_sessions_service.create_session(+ connection,+ scope_id=scope_id,+ agent_backend="",+ agent_id=agents["public"].id,+ user_context=_organization_context("member-1"),+ )+ by_name = workbench_sessions_service.update_session(+ connection,+ session["id"],+ agent_name=agents["scope"].name,+ user_context=_organization_context("member-1"),+ )+ by_id = workbench_sessions_service.update_session(+ connection,+ session["id"],+ agent_id=agents["public"].id,+ user_context=_organization_context("member-1"),+ )++ assert (session["agent_id"], session["agent_name"], session["agent_backend"]) == (+ agents["public"].id,+ agents["public"].name,+ agents["public"].backend,+ )+ assert (by_name["agent_id"], by_name["agent_name"]) == (+ agents["scope"].id,+ agents["scope"].name,+ )+ assert (by_id["agent_id"], by_id["agent_name"]) == (+ agents["public"].id,+ agents["public"].name,+ )++def test_remote_agent_request_and_selection_reject_inaccessible_agent(monkeypatch, tmp_path) -> None:monkeypatch.setenv("AVIBE_HOME", str(tmp_path))config = _save_config(tmp_path)diff --git a/tests/test_resource_acl_vaults.py b/tests/test_resource_acl_vaults.pyindex 67c1a0356..2454f2c81 100644--- a/tests/test_resource_acl_vaults.py+++ b/tests/test_resource_acl_vaults.py@@ -197,6 +197,43 @@ def test_vault_request_reads_and_denial_enforce_member_secret_acls(vault) -> Nonassert denied["status"] == "denied"+def test_pending_provision_lookups_require_instance_owner(vault, monkeypatch) -> None:+ owner = _context("owner-1", instance_role="owner")+ member = _context("member-1")+ with vault.begin() as conn:+ provision = vault_service.create_provision_request(conn, "MISSING_SECRET")+ with pytest.raises(vault_service.VaultSecretAccessError):+ vault_service.resolve_pending_provision_request_by_name(+ conn,+ "MISSING_SECRET",+ user_context=member,+ )+ with pytest.raises(vault_service.VaultSecretAccessError):+ vault_service.get_pending_provision_request(+ conn,+ provision["id"],+ user_context=member,+ )+ visible, ambiguous = vault_service.resolve_pending_provision_request_by_name(+ conn,+ "MISSING_SECRET",+ user_context=owner,+ )++ assert visible is not None+ assert visible["id"] == provision["id"]+ assert ambiguous is False++ monkeypatch.setattr(api, "_vault_engine", lambda: vault)+ monkeypatch.setattr(api, "resolve_resource_access_context", lambda: member)+ with pytest.raises(api.VaultApiError) as by_name:+ api.get_vault_provision_request_by_name("MISSING_SECRET")+ with pytest.raises(api.VaultApiError) as by_id:+ api.get_vault_provision_request(provision["id"])+ assert by_name.value.status == 403+ assert by_id.value.status == 403++def test_vault_request_limit_applies_after_acl_filtering(vault) -> None:owner = _context("owner-1")member = _context("member-1")diff --git a/vibe/api.py b/vibe/api.pyindex 28e7c03bd..117ef574b 100644--- a/vibe/api.py+++ b/vibe/api.py@@ -2686,8 +2686,15 @@ def get_vault_provision_request_by_name(name: str) -> dict:if not vault_crypto.is_valid_secret_name(requested_name):raise VaultApiError("invalid secret name (use ^[A-Za-z_][A-Za-z0-9_]*$)", code="invalid_name")engine = _vault_engine()- with engine.begin() as conn:- request, ambiguous = vault_service.resolve_pending_provision_request_by_name(conn, requested_name)+ try:+ with engine.begin() as conn:+ request, ambiguous = vault_service.resolve_pending_provision_request_by_name(+ conn,+ requested_name,+ user_context=resolve_resource_access_context(),+ )+ except vault_service.VaultSecretAccessError as exc:+ raise _vault_secret_access_forbidden(exc) from excreturn {"ok": True, "request": request, "ambiguous": ambiguous}@@ -2698,8 +2705,15 @@ def get_vault_provision_request(request_id: str) -> dict:if not requested_id:raise VaultApiError("request_id is required", code="missing_request_id")engine = _vault_engine()- with engine.begin() as conn:- request = vault_service.get_pending_provision_request(conn, requested_id)+ try:+ with engine.begin() as conn:+ request = vault_service.get_pending_provision_request(+ conn,+ requested_id,+ user_context=resolve_resource_access_context(),+ )+ except vault_service.VaultSecretAccessError as exc:+ raise _vault_secret_access_forbidden(exc) from excreturn {"ok": True, "request": request}diff --git a/vibe/remote_access.py b/vibe/remote_access.pyindex 51a1af280..44bc73002 100644--- a/vibe/remote_access.py+++ b/vibe/remote_access.py@@ -950,6 +950,7 @@ def _sync_one_organization(# A malformed device response is not safe to acknowledge because it# does not identify an exact valid revision.rejected += 1+ ack_errors += 1continuerelease_scopes: list[dict[str, str]] = []release_key = (