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(permissions): restart policy polling by epoch

Maxfb6a87acc355
diff --git a/ui/src/features/permissions/PermissionsPage.test.tsx b/ui/src/features/permissions/PermissionsPage.test.tsx
index a2811a810..70c547037 100644
--- a/ui/src/features/permissions/PermissionsPage.test.tsx
+++ b/ui/src/features/permissions/PermissionsPage.test.tsx
@@ -358,6 +358,65 @@ describe('PermissionsPage state model', () => {
expect(screen.queryByText('permissions.states.applyingTitle')).toBeNull();
});
+ it('restarts the bounded policy poll for a new applying mutation epoch', async () => {
+ vi.useFakeTimers();
+ const applying = response();
+ applying.projection.policy_sync.status = 'applying';
+ applying.projection.projects[0]!.sync.status = 'pending';
+ applying.projection.access.entries = [{
+ kind: 'email',
+ value: '[email protected]',
+ role: 'viewer',
+ }];
+ api.getPermissions.mockResolvedValue(applying);
+
+ renderPage();
+ await act(async () => { await Promise.resolve(); });
+ await act(async () => { await vi.advanceTimersByTimeAsync(60_000); });
+
+ expect(api.getPermissions).toHaveBeenCalledTimes(31);
+ expect(screen.getByRole('button', { name: 'permissions.actions.refresh' })).toBeTruthy();
+
+ const nextApplying = response();
+ nextApplying.projection.instance.authorization_revision = 5;
+ nextApplying.projection.policy_sync.status = 'applying';
+ nextApplying.projection.projects[0]!.sync.status = 'pending';
+ nextApplying.projection.access.entries = [{
+ kind: 'email',
+ value: '[email protected]',
+ role: 'editor',
+ }];
+ api.getPermissions.mockResolvedValue(nextApplying);
+ api.replaceAuthorizedUsers.mockResolvedValueOnce({
+ ok: true,
+ authorization_revision: 5,
+ entries: nextApplying.projection.access.entries,
+ });
+
+ fireEvent.click(screen.getByRole('button', { name: 'permissions.actions.editAccess' }));
+ fireEvent.click(screen.getByRole('radio', { name: 'permissions.roles.editor' }));
+ fireEvent.click(screen.getByRole('button', { name: 'permissions.actions.save' }));
+ await act(async () => { await Promise.resolve(); });
+
+ expect(api.replaceAuthorizedUsers).toHaveBeenCalledWith(
+ [{ kind: 'email', value: '[email protected]', role: 'editor' }],
+ 4,
+ 'inst-123',
+ );
+ expect(screen.queryByRole('button', { name: 'permissions.actions.refresh' })).toBeNull();
+
+ await act(async () => { await vi.advanceTimersByTimeAsync(2_000); });
+ expect(api.getPermissions).toHaveBeenCalledTimes(32);
+ expect(screen.queryByRole('button', { name: 'permissions.actions.refresh' })).toBeNull();
+
+ await act(async () => { await vi.advanceTimersByTimeAsync(58_000); });
+ expect(api.getPermissions).toHaveBeenCalledTimes(61);
+ expect(screen.getByRole('button', { name: 'permissions.actions.refresh' })).toBeTruthy();
+
+ await act(async () => { await vi.advanceTimersByTimeAsync(60_000); });
+ expect(api.getPermissions).toHaveBeenCalledTimes(61);
+ });
+
it.each([
['error', 'permissions.states.syncErrorTitle'],
['offline', 'permissions.states.syncOfflineTitle'],
diff --git a/ui/src/features/permissions/PermissionsPage.tsx b/ui/src/features/permissions/PermissionsPage.tsx
index e2b2d7d42..b458c2478 100644
--- a/ui/src/features/permissions/PermissionsPage.tsx
+++ b/ui/src/features/permissions/PermissionsPage.tsx
@@ -751,7 +751,6 @@ export function PermissionsPage() {
const currentPolicySignature = state.kind === 'ready' && shouldRefreshPolicy(state.response)
? policyRefreshSignature(state.response)
: null;
- const currentPolicySignatureRef = useRef<string | null>(currentPolicySignature);
const installReadyResponse = useCallback((candidate: PermissionsResponse): PermissionsResponse => {
const accepted = revisionMonotonicResponse(readyResponseRef.current, candidate);
@@ -808,16 +807,11 @@ export function PermissionsPage() {
};
}, [installPageResult]);
- useEffect(() => {
- currentPolicySignatureRef.current = currentPolicySignature;
- }, [currentPolicySignature]);
-
- const livePolicyIsApplying = state.kind === 'ready' && shouldRefreshPolicy(state.response);
const policyRefreshExhausted = currentPolicySignature !== null
&& exhaustedPolicySignature === currentPolicySignature;
useEffect(() => {
- if (!livePolicyIsApplying) return undefined;
+ if (currentPolicySignature === null) return undefined;
let active = true;
let attempts = 0;
let timer: ReturnType<typeof setTimeout> | undefined;
@@ -834,7 +828,7 @@ export function PermissionsPage() {
else if (mounted.current) {
const signature = result.kind === 'ready'
? policyRefreshSignature(result.response)
- : currentPolicySignatureRef.current;
+ : currentPolicySignature;
if (signature !== null) setExhaustedPolicySignature(signature);
}
};
@@ -844,7 +838,7 @@ export function PermissionsPage() {
active = false;
if (timer !== undefined) clearTimeout(timer);
};
- }, [livePolicyIsApplying, refreshReady]);
+ }, [currentPolicySignature, refreshReady]);
if (state.kind === 'loading') {
return (