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(permissions): preserve superseded mutation state
Max0e3fea9316d9
diff --git a/storage/resource_access_service.py b/storage/resource_access_service.pyindex 5a4a933d9..1751839e5 100644--- a/storage/resource_access_service.py+++ b/storage/resource_access_service.py@@ -476,6 +476,7 @@ def _remember_show_page_instance_ownership_locked(or configured is _CONFIGURED_SHOW_PAGE_INSTANCE_UNAVAILABLEor instance_id != configured[0]or mode not in {"personal", "organization"}+ or configured[1] != modeor (mode == "organization") != bool(organization_id)):return current_show_page_instance_ownership(connection=connection)diff --git a/tests/test_permissions.py b/tests/test_permissions.pyindex 4b3726096..3573d8063 100644--- a/tests/test_permissions.py+++ b/tests/test_permissions.py@@ -846,6 +846,52 @@ def test_permissions_cache_mutation_rebase_reads_complete_equal_revision_projectassert cached.projection["access"]["entries"] == updated_entries+def test_permissions_cache_mutation_rebase_preserves_newer_project_sync_state() -> None:+ newer = _complete_projection()+ newer_project = newer["projects"][0]+ newer_project["access"] = {+ **newer_project["access"],+ "mode": "restricted",+ "revision": 4,+ "bindings": [+ {+ "principal_kind": "email",+ "principal_value": "[email protected]",+ "access_role": "editor",+ }+ ],+ }+ newer_project["sync"] = {+ **newer_project["sync"],+ "status": "in_sync",+ "desired_access_revision": 4,+ "applied_access_revision": 4,+ }+ mutation_project = deepcopy(newer_project)+ mutation_project["sync"] = {+ **mutation_project["sync"],+ "status": "pending",+ "applied_access_revision": 3,+ }++ permissions._cache_projection( # noqa: SLF001+ "inst-123",+ newer,+ request_order=20,+ )+ permissions._cache_mutation_result( # noqa: SLF001+ "inst-123",+ newer["instance"]["authorization_revision"],+ project=mutation_project,+ request_order=19,+ )++ cached = permissions._read_cache("inst-123") # noqa: SLF001+ assert cached is not None+ assert cached.projection["projects"][0]["access"] == mutation_project["access"]+ assert cached.projection["projects"][0]["sync"] == newer_project["sync"]++@pytest.mark.parametrize("status",[*sorted(permissions._CACHE_FALLBACK_HTTP_STATUSES), 503], # noqa: SLF001diff --git a/tests/test_resource_acl_show_pages.py b/tests/test_resource_acl_show_pages.pyindex 90d16f73d..c7cb3762d 100644--- a/tests/test_resource_acl_show_pages.py+++ b/tests/test_resource_acl_show_pages.py@@ -1069,6 +1069,11 @@ def test_reconciliation_rejects_a_pairing_switch_before_policy_write(monkeypatch"_assert_show_page_pairing_current",switch_after_validation,)+ monkeypatch.setattr(+ permissions,+ "resolve_current_instance_ownership",+ lambda: _ownership("organization", organization_id="org-1"),+ )reconciliation = store.reconcile_resource_policy("ses-pairing-race")assert reconciliation["status"] == "pending"diff --git a/ui/src/components/workbench/ShowPageShareControl.tsx b/ui/src/components/workbench/ShowPageShareControl.tsxindex cc7326bac..87a5e2381 100644--- a/ui/src/components/workbench/ShowPageShareControl.tsx+++ b/ui/src/components/workbench/ShowPageShareControl.tsx@@ -309,6 +309,7 @@ export const ShowPageShareControl: React.FC<{active={open}canManageInstance={canManageInstance}sessionId={sessionId}+ ownerWindowId={ownerWindowId}/></div>) : null}diff --git a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsxindex 62ff76834..4b72e090b 100644--- a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx+++ b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx@@ -180,13 +180,14 @@ const resource = ({const renderControl = (access: ShowPageAccess = showPageAccess(),- options: { sessionId?: string; canManageInstance?: boolean } = {},+ options: { sessionId?: string; canManageInstance?: boolean; ownerWindowId?: string } = {},) => render(<ShowPageWorkspaceAccessControlaccess={access}activecanManageInstance={options.canManageInstance ?? true}sessionId={options.sessionId ?? 'ses-1'}+ ownerWindowId={options.ownerWindowId}/>,);@@ -269,6 +270,20 @@ describe('ShowPageWorkspaceAccessControl', () => {);});+ it('associates the narrowing confirmation with its owning app window', async () => {+ api.getResourceAccess.mockResolvedValue({+ resource: resource({ level: 'public' }),+ });+ const user = userEvent.setup();+ renderControl(showPageAccess(), { ownerWindowId: 'window-42' });++ await user.click(await screen.findByRole('radio', { name: 'Private' }));+ await user.click(screen.getByRole('button', { name: 'Apply' }));++ const dialog = screen.getByText('Narrow Workspace access?').closest('[role="dialog"]');+ expect(dialog?.getAttribute('data-window-owner-id')).toBe('window-42');+ });+it('saves Organization and selected-group policies and reloads the canonical group selection', async () => {api.updateResourceAccess.mockResolvedValueOnce({ ok: true, resource: resource({ level: 'public', revision: 5 }) })diff --git a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsx b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsxindex 387bfb57b..5a5ee6826 100644--- a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsx+++ b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsx@@ -51,11 +51,13 @@ export function ShowPageWorkspaceAccessControl({active,canManageInstance,sessionId,+ ownerWindowId,}: {access: ShowPageAccess | null;active: boolean;canManageInstance: boolean;sessionId: string;+ ownerWindowId?: string;}) {const { t } = useTranslation();const [gate, setGate] = useState<Gate>('idle');@@ -433,6 +435,7 @@ export function ShowPageWorkspaceAccessControl({confirmLabel={t('chat.showPage.applyWorkspaceAccess')}confirmDisabled={!editable}onConfirm={commit}+ windowOwnerId={ownerWindowId}/></section>);diff --git a/ui/src/features/permissions/PermissionsPage.test.tsx b/ui/src/features/permissions/PermissionsPage.test.tsxindex e838edc5e..9231214ea 100644--- a/ui/src/features/permissions/PermissionsPage.test.tsx+++ b/ui/src/features/permissions/PermissionsPage.test.tsx@@ -620,6 +620,68 @@ describe('PermissionsPage state model', () => {}});+ it('installs a superseded Project acknowledgement without regressing the newer revision', async () => {+ vi.useFakeTimers();+ const initial = response();+ initial.projection.policy_sync.status = 'applying';+ initial.projection.projects[0]!.sync.status = 'pending';+ const newer = response();+ newer.projection.instance.authorization_revision = 6;+ newer.projection.access.entries = [{+ kind: 'email',+ value: '[email protected]',+ role: 'viewer',+ }];+ const acknowledgement = deferred<ProjectAccessWriteResponse>();+ api.getPermissions+ .mockResolvedValueOnce(initial)+ .mockResolvedValueOnce(newer);+ api.updateProjectAccess.mockReturnValueOnce(acknowledgement.promise);++ renderPage();+ await act(async () => { await Promise.resolve(); });+ fireEvent.click(screen.getByRole('tab', { name: 'permissions.tabs.projects' }));+ fireEvent.click(screen.getByRole('button', { name: 'permissions.actions.manage' }));+ fireEvent.change(screen.getByLabelText('permissions.fields.role'), {+ target: { value: 'editor' },+ });+ fireEvent.click(screen.getByRole('button', { name: 'permissions.actions.save' }));+ await act(async () => { await Promise.resolve(); });++ await act(async () => { await vi.advanceTimersByTimeAsync(2_000); });++ await act(async () => {+ acknowledgement.resolve({+ ok: true,+ instance_id: 'inst-123',+ authorization_revision: 5,+ project: {+ ...initial.projection.projects[0]!,+ display_name: 'Updated Project',+ access: {+ ...initial.projection.projects[0]!.access,+ revision: 2,+ bindings: [{+ principal_kind: 'email',+ principal_value: '[email protected]',+ access_role: 'editor',+ }],+ },+ sync: {+ ...initial.projection.projects[0]!.sync,+ status: 'pending',+ },+ },+ });+ await Promise.resolve();+ });++ fireEvent.click(screen.getByRole('tab', { name: 'permissions.tabs.access' }));+ expect(screen.getByText('[email protected]')).toBeTruthy();+ fireEvent.click(screen.getByRole('tab', { name: 'permissions.tabs.projects' }));+ expect(screen.getByText('Updated Project')).toBeTruthy();+ });+it.each([['a different instance', 'inst-other', 5],['an older revision', 'inst-123', 3],diff --git a/ui/src/features/permissions/PermissionsPage.tsx b/ui/src/features/permissions/PermissionsPage.tsxindex 72539a5d6..0acfaf78c 100644--- a/ui/src/features/permissions/PermissionsPage.tsx+++ b/ui/src/features/permissions/PermissionsPage.tsx@@ -177,6 +177,45 @@ const revisionMonotonicResponse = (return candidate;};+const mergeProjectMutationAcknowledgement = (+ current: PermissionsResponse,+ result: Awaited<ReturnType<typeof updateProjectAccess>>,+): PermissionsResponse => {+ const currentRevision = current.projection.instance.authorization_revision;+ const acknowledgedProject = result.project;+ const currentProject = current.projection.projects.find(+ (project) => project.project_id === acknowledgedProject.project_id,+ );+ let project = acknowledgedProject;+ if (currentProject) {+ if (currentProject.access.revision > acknowledgedProject.access.revision) {+ project = currentProject;+ } else if (+ currentProject.access.revision === acknowledgedProject.access.revision+ && currentRevision > result.authorization_revision+ ) {+ // A later acknowledgement may already have observed this policy's sync+ // progress. Keep that progress while applying the committed policy.+ project = { ...acknowledgedProject, sync: currentProject.sync };+ }+ }+ const projects = current.projection.projects.map((candidate) => (+ candidate.project_id === project.project_id ? project : candidate+ ));+ if (!currentProject) projects.push(project);+ return {+ ...current,+ projection: {+ ...current.projection,+ instance: {+ ...current.projection.instance,+ authorization_revision: Math.max(currentRevision, result.authorization_revision),+ },+ projects,+ },+ };+};+const principalIcon = (kind: PrincipalKind) => {if (kind === 'organization_group') return Users;if (kind === 'email_domain') return Globe2;@@ -1286,14 +1325,11 @@ export function PermissionsPage() {editable={editable}onOpenChange={(open) => { if (!open) setEditingProject(null); }}onRefresh={refreshReady}- onSaved={(instanceId, result) => installMutationAcknowledgement(instanceId, result.instance_id, (current) => ({- ...current,- projection: {- ...current.projection,- instance: { ...current.projection.instance, authorization_revision: result.authorization_revision },- projects: current.projection.projects.map((project) => project.project_id === result.project.project_id ? result.project : project),- },- }))}+ onSaved={(instanceId, result) => installMutationAcknowledgement(+ instanceId,+ result.instance_id,+ (current) => mergeProjectMutationAcknowledgement(current, result),+ )}/><ConfirmDialogopen={removingAccess !== null}diff --git a/vibe/permissions.py b/vibe/permissions.pyindex c75cee600..460fc230d 100644--- a/vibe/permissions.py+++ b/vibe/permissions.py@@ -725,6 +725,32 @@ def _merge_equal_revision_projection(return merged+def _merge_mutation_rebase_projection(+ cached: dict[str, Any],+ candidate: dict[str, Any],+) -> dict[str, Any]:+ """Apply mutation policy fields while retaining newer cached sync state."""++ merged = _prefer_mapping(candidate, cached)+ cached_projects = {+ project["project_id"]: project for project in cached["projects"]+ }+ projects: list[dict[str, Any]] = []+ for project in candidate["projects"]:+ cached_project = cached_projects.get(project["project_id"])+ if cached_project is None:+ projects.append(dict(project))+ continue+ merged_project = _merge_project_projection(project, cached_project)+ merged_project["sync"] = _prefer_mapping(+ cached_project["sync"],+ project["sync"],+ )+ projects.append(merged_project)+ merged["projects"] = projects+ return merged++def _cache_read_merge_write(instance_id: str,merge: Callable[[dict[str, Any] | None], Any],@@ -769,6 +795,16 @@ def _cache_read_merge_write(),)validated = _validated_projection(validated, instance_id)+ elif (+ cached_revision == candidate_revision+ and mutation_rebase+ and cached.cache_order > request_order+ ):+ validated = _merge_mutation_rebase_projection(+ cached.projection,+ validated,+ )+ validated = _validated_projection(validated, instance_id)if pairing_guard is not None:pairing_guard()_write_cache(instance_id, validated, cache_order=cache_order)