Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Preserve Quick Access continuation after failed cache refresh (#6704)
Sean Aye793388b58a4b
diff --git a/apps/web/src/lib/core/context/quickAccess/projected-list.test.ts b/apps/web/src/lib/core/context/quickAccess/projected-list.test.tsindex fdf7943b4b..eb6d624e65 100644--- a/apps/web/src/lib/core/context/quickAccess/projected-list.test.ts+++ b/apps/web/src/lib/core/context/quickAccess/projected-list.test.ts@@ -14,6 +14,7 @@ import { exclude } from './types';const cleanups: (() => void)[] = [];afterEach(() => {for (const cleanup of cleanups.splice(0)) cleanup();+ vi.restoreAllMocks();});function root<T>(fn: () => T): T {@@ -107,6 +108,116 @@ describe('Quick Access local projection', () => {expect(search).toHaveBeenCalledTimes(4);});+ it.each([+ { stage: 'search', failurePage: 1 },+ { stage: 'search', failurePage: 2 },+ { stage: 'materialize', failurePage: 1 },+ { stage: 'materialize', failurePage: 2 },+ ])(+ 'retains the committed window after $stage fails on replay page $failurePage',+ async ({ stage, failurePage }) => {+ const [revision, setRevision] = createSignal(0);+ let replaying = false;+ let replayPage = 0;+ vi.spyOn(console, 'warn').mockImplementation(() => {});+ const search = vi.fn(+ async (args: SearchCacheArgs): Promise<SearchCachePage> => {+ if (replaying) {+ replayPage += 1;+ if (stage === 'search' && replayPage === failurePage)+ throw new Error('cache search unavailable');+ return page([`refreshed-${replayPage}`], true);+ }+ if (!args.cursor) return page(['one'], true);+ if (args.cursor.recordKey === 'GraphqlSoupDocument:one')+ return page(['two'], true);+ if (args.cursor.recordKey === 'GraphqlSoupDocument:two')+ return page(['three']);+ throw new Error('pagination used an uncommitted cursor');+ }+ );+ const list = root(() =>+ createProjectedList({+ host: { search },+ buckets: ['note'],+ revision,+ materialize: async (documents) => {+ if (+ replaying &&+ stage === 'materialize' &&+ replayPage === failurePage+ )+ throw new Error('cache materialization unavailable');+ return materialize(documents);+ },+ })+ );+ await vi.waitFor(() => expect(list.hasMore()).toBe(true));+ await list.loadMore();+ const committedRows = list.items();+ expect(committedRows).toEqual([+ { id: 'GraphqlSoupDocument:one' },+ { id: 'GraphqlSoupDocument:two' },+ ]);++ // Repeated failures must retain the same committed cursor, including when+ // part of a multi-page replay already succeeded before the error.+ replaying = true;+ for (const revision of [1, 2]) {+ replayPage = 0;+ setRevision(revision);+ await vi.waitFor(() => expect(list.isLoading()).toBe(false));+ expect(replayPage).toBe(failurePage);+ expect(list.items()).toBe(committedRows);+ expect(list.hasMore()).toBe(true);+ expect(list.isLoadingMore()).toBe(false);+ }++ replaying = false;+ await list.loadMore();+ expect(search.mock.calls.at(-1)?.[0].cursor).toEqual({+ recordKey: 'GraphqlSoupDocument:two',+ timestampMs: 1,+ });+ expect(list.items()).toEqual([+ ...committedRows,+ { id: 'GraphqlSoupDocument:three' },+ ]);+ expect(list.hasMore()).toBe(false);+ }+ );++ it('does not carry a failed replay cursor into a different query', async () => {+ const [revision, setRevision] = createSignal(0);+ const [query, setQuery] = createSignal('');+ vi.spyOn(console, 'warn').mockImplementation(() => {});+ const search = vi+ .fn<(args: SearchCacheArgs) => Promise<SearchCachePage>>()+ .mockResolvedValueOnce(page(['old'], true))+ .mockRejectedValueOnce(new Error('replay failed'))+ .mockResolvedValueOnce(page(['new']));+ const list = root(() =>+ createProjectedList({+ host: { search },+ buckets: ['note'],+ revision,+ searchTerm: query,+ materialize,+ })+ );+ await vi.waitFor(() => expect(list.hasMore()).toBe(true));+ setRevision(1);+ await vi.waitFor(() => expect(list.isLoading()).toBe(false));+ expect(list.hasMore()).toBe(true);+ setQuery('new');+ await vi.waitFor(() => expect(list.isLoading()).toBe(false));+ expect(search.mock.calls[2][0].cursor).toBeUndefined();+ expect(list.items()).toEqual([{ id: 'GraphqlSoupDocument:new' }]);+ expect(list.hasMore()).toBe(false);+ await list.loadMore();+ expect(search).toHaveBeenCalledTimes(3);+ });+it('searches only materializable buckets before applying the limit', async () => {const emailHits = Array.from({ length: 500 }, (_, i) =>document(`email-${i}`, 'email')@@ -278,7 +389,7 @@ describe('Quick Access local projection', () => {await list.loadMore();expect(list.items()).toHaveLength(2);expect(list.isLoadingMore()).toBe(false);- expect(list.hasMore()).toBe(false);+ expect(list.hasMore()).toBe(true);await list.loadMore();expect(list.items()).toHaveLength(3);warning.mockRestore();diff --git a/apps/web/src/lib/core/context/quickAccess/projected-list.ts b/apps/web/src/lib/core/context/quickAccess/projected-list.tsindex 2d56f80d28..78534a2aeb 100644--- a/apps/web/src/lib/core/context/quickAccess/projected-list.ts+++ b/apps/web/src/lib/core/context/quickAccess/projected-list.ts@@ -118,9 +118,10 @@ export function createProjectedList<T extends { id: string }>(options: {setHasMore(cursor !== undefined);} catch (error) {if (current !== request) return;- // Keep visible rows. Suppress automatic end-of-list retry loops; an- // explicit loadMore or the next revision/query change can retry locally.- setHasMore(false);+ // Rows and their continuation are a committed window. A failed replay+ // (or append) must leave both intact so normal pagination can retry.+ // The mentions page loader guards automatic retries at the same frontier.+ setHasMore(request.cursor !== undefined);console.warn('Quick Access cache search failed', error);} finally {if (current === request) {@@ -147,6 +148,7 @@ export function createProjectedList<T extends { id: string }>(options: {const request: Request = {query,pages: sameQuery ? (previous?.pages ?? 1) : 1,+ cursor: sameQuery ? previous?.cursor : undefined,busy: false,};current = request;diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.mdindex 3da0949527..de1446776b 100644--- a/docs/AGENT_GUIDE/navigation.md+++ b/docs/AGENT_GUIDE/navigation.md@@ -305,7 +305,8 @@ Down); mentions offer **View all** for a category and then load more local pagesCounts describe loaded results, not the full server corpus. Scans throughincomplete or already-visible cache hits are bounded per action; continuenavigating/scrolling, or narrow the query, to resume from the saved cursor.-A missing item may still be uncached, but should appear after hydration without retyping. Cmd+K's+A failed local refresh keeps displayed rows and their continuation available for+another pagination attempt. A missing item may still be uncached, but should appear after hydration without retyping. Cmd+K'slocal search excludes unsupported email hits before limiting entity results;email mentions keep their separate search-service path.