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(workbench): separate unread snapshot ownership

cyhdfbbc74c936d
diff --git a/ui/src/context/WorkbenchInboxProvider.tsx b/ui/src/context/WorkbenchInboxProvider.tsx
index 21fb61b23..62663e7ff 100644
--- a/ui/src/context/WorkbenchInboxProvider.tsx
+++ b/ui/src/context/WorkbenchInboxProvider.tsx
@@ -166,7 +166,8 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>
// One home for "an authoritative unread map arrived": set the map and flip
// ``unreadLoaded`` together so the two can never drift apart. Every whole-account
- // write (refresh / reconcile / markRead / unread.changed) goes through here;
+ // write (refresh / reconcile / unread.changed) goes through here; targeted
+ // reads and mark-read responses merge one session without claiming completeness.
// stable identity, so it never churns the memoized context value.
const applyUnreadMap = useCallback((map: Record<string, number>) => {
setUnreadBySession(map);
@@ -191,7 +192,6 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>
else delete next[sessionId];
return next;
});
- setUnreadLoaded(true);
}, []);
const mergeTargetedSnapshots = useCallback((rows: InboxSession[]): InboxSession[] => {
@@ -330,10 +330,7 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>
const operation = readOwnershipRef.current.beginRead(`inbox-mark-read:${sessionId}`);
const result = await api.markSessionRead(sessionId, untilMessageId);
if (
- !readOwnershipRef.current.isMutationCurrent(operation, [
- `inbox-session:${sessionId}`,
- 'inbox-unread-all',
- ])
+ !readOwnershipRef.current.isMutationCurrent(operation, `inbox-session:${sessionId}`)
) {
return;
}
diff --git a/ui/src/context/WorkbenchSessionReadOrdering.test.tsx b/ui/src/context/WorkbenchSessionReadOrdering.test.tsx
index 0cffcdd2c..79ebcf01f 100644
--- a/ui/src/context/WorkbenchSessionReadOrdering.test.tsx
+++ b/ui/src/context/WorkbenchSessionReadOrdering.test.tsx
@@ -886,6 +886,129 @@ describe('Workbench session read ownership', () => {
expect(inbox?.unreadBySession).toEqual({});
});
+ it('does not treat targeted unread data as a complete account snapshot', async () => {
+ const staleInitialRead = deferred({
+ sessions: [],
+ next_cursor: null,
+ unread_by_session: { [sessionB.id]: 5 },
+ });
+ const replacementFailure = new Error('replacement refresh failed');
+ const listInbox = vi.fn()
+ .mockReturnValueOnce(staleInitialRead.promise)
+ .mockResolvedValueOnce({
+ sessions: [inboxRow],
+ next_cursor: null,
+ unread_by_session: { [session.id]: 3 },
+ })
+ .mockRejectedValueOnce(replacementFailure);
+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
+ let handlers: WorkbenchEventHandlers | null = null;
+ apiRef.current = {
+ listInbox,
+ connectWorkbenchEvents: vi.fn((next) => {
+ handlers = next;
+ return vi.fn();
+ }),
+ };
+ const favicon = document.createElement('link');
+ favicon.rel = 'icon';
+ favicon.href = '/logo.png';
+ document.head.appendChild(favicon);
+ let inbox: ReturnType<typeof useWorkbenchInbox> | null = null;
+ const Probe = () => {
+ const value = useWorkbenchInbox();
+ useEffect(() => {
+ inbox = value;
+ }, [value]);
+ return null;
+ };
+
+ render(
+ <WorkbenchInboxProvider>
+ <Probe />
+ </WorkbenchInboxProvider>,
+ );
+ await settle();
+ act(() => {
+ handlers?.onSessionActivity?.({
+ session_id: session.id,
+ scope_id: session.scope_id,
+ event: 'updated',
+ visibility: 'foreground',
+ });
+ });
+ await settle();
+ expect(inbox?.unreadBySession).toEqual({ [session.id]: 3 });
+ await act(async () => {
+ staleInitialRead.resolve({
+ sessions: [],
+ next_cursor: null,
+ unread_by_session: { [sessionB.id]: 5 },
+ });
+ await staleInitialRead.promise;
+ });
+ await settle();
+
+ expect(listInbox).toHaveBeenCalledTimes(3);
+ expect(inbox?.unreadBySession).toEqual({ [session.id]: 3 });
+ expect(favicon.getAttribute('href')).toBe('/logo.png');
+ expect(consoleError).toHaveBeenCalledWith('[inbox] refresh failed', replacementFailure);
+ favicon.remove();
+ consoleError.mockRestore();
+ });
+
+ it('keeps a mark-read result across an unrelated unread event', async () => {
+ const markReadResult = deferred({ unread_by_session: { [sessionB.id]: 4 } });
+ let handlers: WorkbenchEventHandlers | null = null;
+ apiRef.current = {
+ listInbox: vi.fn().mockResolvedValue({
+ sessions: [inboxRow],
+ next_cursor: null,
+ unread_by_session: { [session.id]: 3, [sessionB.id]: 5 },
+ }),
+ markSessionRead: vi.fn().mockReturnValue(markReadResult.promise),
+ connectWorkbenchEvents: vi.fn((next) => {
+ handlers = next;
+ return vi.fn();
+ }),
+ };
+ let inbox: ReturnType<typeof useWorkbenchInbox> | null = null;
+ const Probe = () => {
+ const value = useWorkbenchInbox();
+ useEffect(() => {
+ inbox = value;
+ }, [value]);
+ return null;
+ };
+
+ render(
+ <WorkbenchInboxProvider>
+ <Probe />
+ </WorkbenchInboxProvider>,
+ );
+ await settle();
+ act(() => {
+ void inbox?.markRead(session.id);
+ });
+ await settle();
+ act(() => {
+ handlers?.onInboxUnreadChanged?.({
+ session_id: sessionB.id,
+ scope_id: sessionB.scope_id,
+ delta: -1,
+ unread_counts: { agent: 7 },
+ unread_by_session: { [session.id]: 3, [sessionB.id]: 4 },
+ });
+ });
+ await act(async () => {
+ markReadResult.resolve({ unread_by_session: { [sessionB.id]: 4 } });
+ await markReadResult.promise;
+ });
+ await settle();
+
+ expect(inbox?.unreadBySession).toEqual({ [sessionB.id]: 4 });
+ });
+
it('keeps a successful mark-read result when an older unread snapshot finishes last', async () => {
const markReadResult = deferred({ unread_by_session: { [sessionB.id]: 5 } });
const staleRefresh = deferred({