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
fix(web): prevent GitHub status failures from refreshing lists (#8329)
Peter Chinman3fc2345a7e50
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex dc9a49bd8e..be7f0a6185 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -98,6 +98,7 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.- Preserve focused chrome editors during deferred split insertion/removal autofocus; explicit return-focus commands may still focus the pane.- Reconcile global focus when focused DOM subtrees are removed; iOS can omit blur events, otherwise floating creation actions stay hidden after search or editor teardown.- Mount the floating mobile AI composer only on the Agents view; other views keep their New action or their own reply/comment composer.+- Passive PR mentions must not retry initial GitHub status failures on remount; preserve confirmed status through refetch errors and keep pending data reads out of their parent Suspense boundary.- Keep native booking exit navigation in the route shell, outside page loading boundaries, and use the router so the native hash route stays intact.- All API/network calls live in service-clients.- Route explicit call exits using the server's `callEnded` result: ended callsdiff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsxindex 966d40c765..8f4fdbf229 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsx@@ -1,7 +1,14 @@-import { githubLinkStatusQueryOptions } from '@queries/auth/github-link';+import {+ githubLinkStatusQueryOptions,+ invalidateGithubLinkStatus,+} from '@queries/auth/github-link';import type { authServiceClient } from '@service-auth/client';import { cleanup, render, screen } from '@solidjs/testing-library';-import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';+import {+ QueryClient,+ QueryClientProvider,+ QueryObserver,+} from '@tanstack/solid-query';import { err, ok } from 'neverthrow';import { createSignal, Show, Suspense } from 'solid-js';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -55,6 +62,51 @@ afterEach(() => {});describe('PR mention connection-status suspense', () => {+ it('keeps a confirmed plain link through refetch errors and remounts', async () => {+ checkGithubLinkStatus.mockResolvedValueOnce(+ err([{ code: 'NOT_FOUND', message: 'GitHub account not linked' }])+ );+ await client.fetchQuery(githubLinkStatusQueryOptions());+ const [mounted, setMounted] = createSignal(true);+ const suspended = vi.fn();+ function HiddenSurface() {+ suspended();+ return <span>Hidden surface</span>;+ }+ render(() => (+ <QueryClientProvider client={client}>+ <Suspense fallback={<HiddenSurface />}>+ <Show when={mounted()}>+ <PullRequestMention+ id="pr-1"+ url="https://github.com/macro-inc/macro/pull/7956"+ label="macro-inc/macro#7956"+ key="sent"+ theme={{}}+ />+ </Show>+ </Suspense>+ </QueryClientProvider>+ ));+ expect(screen.getByRole('link').getAttribute('href')).toBe(+ 'https://github.com/macro-inc/macro/pull/7956'+ );+ checkGithubLinkStatus.mockResolvedValueOnce(+ err([{ code: 'HTTP_ERROR', message: 'Connection status unavailable' }])+ );+ await expect(+ client.fetchQuery({ ...githubLinkStatusQueryOptions(), staleTime: 0 })+ ).rejects.toThrow();+ await new Promise<void>((resolve) => queueMicrotask(resolve));+ expect(screen.getByRole('link').getAttribute('href')).toBe(+ 'https://github.com/macro-inc/macro/pull/7956'+ );+ setMounted(false);+ setMounted(true);+ expect(screen.getByRole('link')).toBeDefined();+ expect(suspended).not.toHaveBeenCalled();+ });+it.each(['linked', 'unlinked', 'error'] as const)('keeps the composer and message visible during a retry that ends %s',async (outcome) => {@@ -113,6 +165,13 @@ describe('PR mention connection-status suspense', () => {composer.focus();setInserted(true);+ expect(checkGithubLinkStatus).toHaveBeenCalledTimes(1);+ setInserted(false);+ setInserted(true);+ expect(checkGithubLinkStatus).toHaveBeenCalledTimes(1);++ // An explicit retry still works and must not suspend either surface.+ const settled = client.fetchQuery(githubLinkStatusQueryOptions());expect(checkGithubLinkStatus).toHaveBeenCalledTimes(2);expect(screen.getByRole('textbox')).toBe(composer);expect(document.activeElement).toBe(composer);@@ -134,7 +193,6 @@ describe('PR mention connection-status suspense', () => {message: 'Connection status unavailable',} as const,]);- const settled = client.fetchQuery(githubLinkStatusQueryOptions());retry.resolve(response);if (outcome === 'error') {await expect(settled).rejects.toThrow();@@ -157,3 +215,96 @@ describe('PR mention connection-status suspense', () => {});});++it('refreshes a failed inactive status query after OAuth completes', async () => {+ checkGithubLinkStatus.mockResolvedValueOnce(+ err([{ code: 'HTTP_ERROR', message: 'Connection status unavailable' }])+ );+ await expect(+ client.fetchQuery(githubLinkStatusQueryOptions())+ ).rejects.toThrow();+ checkGithubLinkStatus.mockResolvedValueOnce(+ ok({+ github_user_id: '123',+ github_username: 'macro-user',+ reauthentication_required: false,+ })+ );++ await invalidateGithubLinkStatus();++ expect(checkGithubLinkStatus).toHaveBeenCalledTimes(2);+ expect(client.getQueryData(githubLinkStatusQueryOptions().queryKey)).toEqual({+ status: 'linked',+ username: 'macro-user',+ userId: '123',+ });+});++it('refreshes a failed status query after OAuth when all observers are disabled', async () => {+ checkGithubLinkStatus.mockResolvedValueOnce(+ err([{ code: 'HTTP_ERROR', message: 'Connection status unavailable' }])+ );+ await expect(+ client.fetchQuery(githubLinkStatusQueryOptions())+ ).rejects.toThrow();+ const observer = new QueryObserver(client, {+ ...githubLinkStatusQueryOptions(),+ enabled: false,+ retryOnMount: false,+ });+ const unsubscribe = observer.subscribe(() => {});+ try {+ checkGithubLinkStatus.mockResolvedValueOnce(+ ok({+ github_user_id: '123',+ github_username: 'macro-user',+ reauthentication_required: false,+ })+ );+ await invalidateGithubLinkStatus();+ expect(checkGithubLinkStatus).toHaveBeenCalledTimes(2);+ expect(observer.getCurrentResult().data?.status).toBe('linked');+ } finally {+ unsubscribe();+ }+});++it('does not reuse an in-flight pre-OAuth status request', async () => {+ const previous =+ Promise.withResolvers<+ Awaited<ReturnType<typeof authServiceClient.checkGithubLinkStatus>>+ >();+ checkGithubLinkStatus.mockReturnValueOnce(previous.promise);+ const pending = client.fetchQuery(githubLinkStatusQueryOptions());+ // Cancellation is expected; attach a handler before refreshing.+ const previousSettled = Promise.allSettled([pending]);+ checkGithubLinkStatus.mockResolvedValueOnce(+ ok({+ github_user_id: '123',+ github_username: 'macro-user',+ reauthentication_required: false,+ })+ );+ const refreshed = invalidateGithubLinkStatus();+ previous.resolve(+ err([{ code: 'NOT_FOUND', message: 'GitHub account not linked' }])+ );+ await previousSettled;+ await refreshed;++ expect(checkGithubLinkStatus).toHaveBeenCalledTimes(2);+ expect(+ client.getQueryData(githubLinkStatusQueryOptions().queryKey)+ ).toMatchObject({ status: 'linked' });+});++it('does not report a post-OAuth status failure as an OAuth failure', async () => {+ checkGithubLinkStatus.mockResolvedValue(+ err([{ code: 'HTTP_ERROR', message: 'Connection status unavailable' }])+ );+ await expect(invalidateGithubLinkStatus()).resolves.toBeUndefined();+ expect(+ client.getQueryState(githubLinkStatusQueryOptions().queryKey)?.status+ ).toBe('error');+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsxindex a2e82804af..4951a41b22 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx@@ -554,6 +554,8 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {const githubLinkQuery = useGithubLinkStatusQuery({enabled: () => !lexicalWrapper?.skipPreviewFetch,+ // Virtualized rows remount while scrolling; they should not retry failures.+ retryOnMount: false,});const isSelectedAsNode = () => {@@ -571,10 +573,12 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {// When GitHub is not linked, render as a plain link instead of the fancy mention UIconst shouldRenderAsPlainLink = () => {if (lexicalWrapper?.skipPreviewFetch) return false;- // A failed query is still "fetched" while its next mount retries it.- // Reading its pending data would suspend the surrounding composer/message.+ // An initial failure has no resource value and reading it during a retry+ // suspends the surrounding surface. Refetch errors retain confirmed data;+ // Solid Query exposes that value without suspending.return !!(props.url &&+ !githubLinkQuery.isLoadingError &&queryReadyGate(githubLinkQuery) &&githubLinkQuery.data.status !== 'linked');diff --git a/apps/web/src/lib/queries/auth/github-link.ts b/apps/web/src/lib/queries/auth/github-link.tsindex eefed6c190..01886a20eb 100644--- a/apps/web/src/lib/queries/auth/github-link.ts+++ b/apps/web/src/lib/queries/auth/github-link.ts@@ -24,6 +24,7 @@ type UseGithubLinkStatusQueryOptions = {enabled?: boolean | (() => boolean);refetchInterval?: number;refetchOnMount?: 'always';+ retryOnMount?: boolean;};function hasReauthenticationError(@@ -81,14 +82,23 @@ export function useGithubLinkStatusQuery(enabled,refetchInterval: options?.refetchInterval,refetchOnMount: options?.refetchOnMount,+ retryOnMount: options?.retryOnMount,};});}-export function invalidateGithubLinkStatus() {- return queryClient.invalidateQueries({- queryKey: authKeys.githubLinkStatus.queryKey,+export async function invalidateGithubLinkStatus() {+ const options = githubLinkStatusQueryOptions();+ // A pre-OAuth request must not overwrite the newly verified connection.+ await queryClient.cancelQueries({ queryKey: options.queryKey });+ await queryClient.invalidateQueries({+ queryKey: options.queryKey,+ refetchType: 'none',});+ // Invalidation skips queries whose observers are all disabled (for example,+ // skipPreviewFetch mentions). Explicit fetching refreshes those readers too.+ // Keep refresh failures in query state, not in the completed OAuth result.+ return queryClient.prefetchQuery({ ...options, staleTime: 0 });}export function useInitGithubLinkMutation() {diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.mdindex b49b4c47ee..1062bbe6c6 100644--- a/docs/agent-guide/channels.md+++ b/docs/agent-guide/channels.md@@ -608,11 +608,16 @@ On a cold channel open, verify that delayed bot/agent mention requests leave themessages and composer visible. Expand a thread while its replies are stillloading: existing preview replies should remain visible until the full listarrives. Repeat after reopening the channel to cover both cold and cached data.-For PR mentions, also fail a GitHub connection-status request, then paste a+For PR mentions, also fail a GitHub connection-status request, scroll through+virtualized rows repeatedly, and verify remounts make no new status requests.+An explicit retry or completed OAuth must still refresh the status, even if all+mentions have unmounted or only disabled preview observers remain. Then paste amention while the retry is held pending. The composer must stay visible andfocused, and messages containing PR mentions must render immediately. Resolvethe retry as linked, unlinked, or failed: none should hide the surrounding UI;only a confirmed unlinked/reauthentication status changes the chip to a link.+After a confirmed unlinked status, fail a refetch and remount the mention: it+must remain a plain GitHub link without hiding the surrounding UI.Scrolling a collapsed thread into view must keep its timeline preview unchanged,without fetching or revealing the full reply list. Cached replies from a previousexpansion must not enlarge that preview either. Explicit expansion, replying,