From e01df7331b170762635e04dc36e1077c43dac359 Mon Sep 17 00:00:00 2001 From: Leo Kwan Date: Sun, 22 Nov 2026 23:18:20 -0500 Subject: [PATCH] fix(web): clear resolved MCP sign-in warnings (FBL-1036) --- .../src/components/chat/McpSignInAction.tsx | 32 ++--- .../chat/MessagesTimeline.browser.test.tsx | 131 +++++++++++++++++- .../components/chat/TimelineWorkEntryRow.tsx | 84 +++++++---- 3 files changed, 195 insertions(+), 52 deletions(-) diff --git a/apps/web/src/components/chat/McpSignInAction.tsx b/apps/web/src/components/chat/McpSignInAction.tsx index 63c5d9e49dff0..b6e1033a5119a 100644 --- a/apps/web/src/components/chat/McpSignInAction.tsx +++ b/apps/web/src/components/chat/McpSignInAction.tsx @@ -39,21 +39,15 @@ export function McpSignInAction({ threadId, providerThreadId, server, - noticeAt, }: { readonly environmentId: EnvironmentId; readonly threadId: ThreadId; readonly providerThreadId: ProviderThreadId; readonly server: string; - /** When the environment raised the notice, in epoch milliseconds. */ - readonly noticeAt: number; }) { const gt = useGT(); const formId = useId(); const allowed = useAtomValue(threadEnvironment.mcpSignInStart.permissionAtom(environmentId)); - const signedIn = useAtomValue( - threadEnvironment.mcpSignedInAtom(environmentId, { threadId, server, noticeAt }), - ); const start = useAtomCommand(threadEnvironment.mcpSignInStart, { reportFailure: false }); const complete = useAtomCommand(threadEnvironment.mcpSignInComplete, { reportFailure: false }); const { copyToClipboard, isCopied } = useCopyToClipboard(); @@ -105,22 +99,16 @@ export function McpSignInAction({ return ( <> - {signedIn ? ( - - Signed in - - ) : ( - { - event.stopPropagation(); - void begin(); - }} - onKeyDown={stopRowToggle} - > - Sign in - - )} + { + event.stopPropagation(); + void begin(); + }} + onKeyDown={stopRowToggle} + > + Sign in + { diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index bce13bb454379..7147eefe03d5c 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -10,6 +10,7 @@ import { NodeId, ProviderDriverKind, ProviderInstanceId, + ProviderThreadId, RunAttemptId, RunId, RuntimeRequestId, @@ -33,7 +34,8 @@ import { describe, expect, it, onTestFinished, vi } from "vite-plus/test"; import "~/index.css"; -import { environmentThreadDetails } from "../../state/threads"; +import { AppAtomRegistryProvider, appAtomRegistry } from "~/rpc/atomRegistry"; +import { environmentThreadDetails, threadEnvironment } from "../../state/threads"; import { act, fakeTimers, render, stubGlobal } from "../../../test/render"; import { ChangedFilesCard } from "./ChangedFilesTree"; import { MessagesTimeline } from "./MessagesTimeline"; @@ -2497,3 +2499,130 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se .element(screen.getByRole("button", { name: "Open the current tab", exact: true })) .toBeVisible(); }); + +describe("MessagesTimeline MCP sign-in notice", () => { + it("replaces a resolved MCP sign-in warning with a signed-in row while keeping newer notices actionable", async () => { + setup(); + const threadId = ThreadId.make("mcp-signin-thread"); + const providerThreadId = ProviderThreadId.make("mcp-signin-provider-thread"); + const runId = RunId.make("mcp-signin-run"); + const server = "linear"; + const firstNoticeAt = "2026-03-17T19:12:28.000Z"; + const signedInAt = "2026-03-17T19:13:00.000Z"; + const newerNoticeAt = "2026-03-17T19:14:00.000Z"; + const warningMessage = + "The linear MCP server needs a sign-in before Claude can use it. " + + "Complete authentication in your browser so the agent can reconnect to this workspace tool."; + + const signedInAtByKey = Atom.make>(new Map()); + const receiptAtoms = Atom.family((key: string) => { + const [environmentId, receiptThreadId, receiptServer, noticeAt] = JSON.parse(key) as [ + string, + string, + string, + number, + ]; + return Atom.make((get) => { + const latest = get(signedInAtByKey).get( + JSON.stringify([environmentId, receiptThreadId, receiptServer]), + ); + return latest !== undefined && noticeAt <= latest; + }); + }); + + using _permission = vi + .spyOn(threadEnvironment.mcpSignInStart, "permissionAtom") + .mockReturnValue(Atom.make(true)); + using _signedIn = vi + .spyOn(threadEnvironment, "mcpSignedInAtom") + .mockImplementation((environmentId, input) => + receiptAtoms(JSON.stringify([environmentId, input.threadId, input.server, input.noticeAt])), + ); + + const noticeItem = (id: string, position: number, updatedAtIso: string) => { + const at = DateTime.makeUnsafe(updatedAtIso); + return { + position, + visibility: "local" as const, + sourceThreadId: threadId, + sourceItemId: TurnItemId.make(id), + item: { + id: TurnItemId.make(id), + threadId, + runId, + nodeId: null, + providerThreadId, + providerTurnId: null, + nativeItemRef: null, + parentItemId: null, + ordinal: position, + title: `MCP server ${server} needs a sign-in`, + startedAt: at, + completedAt: at, + updatedAt: at, + type: "system_notice" as const, + status: "completed" as const, + level: "warning" as const, + message: warningMessage, + mcpSignIn: { server }, + }, + }; + }; + + const entriesFor = (items: ReadonlyArray>) => + deriveTimelineEntriesFromVisibleTurnItems({ + visibleTurnItems: items, + optimisticMessages: [], + }); + + const props = baseProps(); + const firstNotice = noticeItem("mcp-notice-1", 0, firstNoticeAt); + const newerNotice = noticeItem("mcp-notice-2", 1, newerNoticeAt); + const ui = (items: ReadonlyArray>) => ( + + + + ); + + await using screen = await renderElement(ui([firstNotice])); + const firstRow = () => + screen.container.querySelector('[data-work-entry-id="mcp-notice-1"]'); + + await vi.waitFor(() => expect(firstRow()).not.toBeNull()); + expect(firstRow()!.textContent).toContain("needs a sign-in"); + expect(firstRow()!.querySelector(".text-warning")).not.toBeNull(); + expect(screen.buttons("Sign in to linear")).toHaveLength(1); + + const rowToggle = firstRow()!.querySelector('[role="button"]'); + if (rowToggle) { + await click(rowToggle); + expect(rowToggle.getAttribute("aria-expanded")).toBe("true"); + } + + await act(() => { + appAtomRegistry.set( + signedInAtByKey, + new Map([[JSON.stringify([ENVIRONMENT_ID, threadId, server]), Date.parse(signedInAt)]]), + ); + }); + + await vi.waitFor(() => expect(firstRow()!.textContent).toContain("Signed in to linear")); + expect(firstRow()!.textContent).not.toContain("needs a sign-in"); + expect(firstRow()!.textContent).toBe("Signed in to linear"); + expect(firstRow()!.querySelector(".text-warning")).toBeNull(); + expect(firstRow()!.querySelector(".text-success-foreground")).not.toBeNull(); + expect(firstRow()!.querySelector('[role="button"]')).toBeNull(); + expect(screen.buttons("Sign in to linear")).toHaveLength(0); + + await screen.rerender(ui([firstNotice, newerNotice])); + const secondRow = () => + screen.container.querySelector('[data-work-entry-id="mcp-notice-2"]'); + + await vi.waitFor(() => expect(secondRow()).not.toBeNull()); + expect(firstRow()!.textContent).toBe("Signed in to linear"); + expect(firstRow()!.querySelector(".text-warning")).toBeNull(); + expect(secondRow()!.textContent).toContain("needs a sign-in"); + expect(secondRow()!.querySelector(".text-warning")).not.toBeNull(); + expect(screen.buttons("Sign in to linear")).toHaveLength(1); + }); +}); diff --git a/apps/web/src/components/chat/TimelineWorkEntryRow.tsx b/apps/web/src/components/chat/TimelineWorkEntryRow.tsx index 4cd6fc0e8dee6..476721a489df9 100644 --- a/apps/web/src/components/chat/TimelineWorkEntryRow.tsx +++ b/apps/web/src/components/chat/TimelineWorkEntryRow.tsx @@ -37,13 +37,16 @@ import ChatMarkdown from "../ChatMarkdown"; import { ChatMarkdownAssetImage } from "./ChatMarkdownMedia"; import type { ExpandedImagePreview } from "./ExpandedImagePreview"; import { workGroupImageGallery } from "./markdownImageGallery"; +import { useAtomValue } from "@effect/atom-react"; import { McpSignInAction } from "./McpSignInAction"; import * as DateTime from "effect/DateTime"; +import { Atom } from "effect/reactivity"; import { ChevronRightIcon, CircleAlertIcon, XIcon, RotateCcwIcon } from "lucide-react"; import { Button, InlineButton } from "../ui/button"; import { useAssetUrls } from "../../assets/assetUrls"; import { observeResize } from "../../lib/observeResize"; import { useThreadShell } from "../../state/entities"; +import { threadEnvironment } from "../../state/threads"; import { threadReadTargetId, threadReadTargetTitle, @@ -281,6 +284,8 @@ export function ViewedImagesTimelineRow({ ); } +const NOT_SIGNED_IN = Atom.make(false); + function WorkEntryLogRow(props: WorkEntryRowProps) { const { workEntry, workspaceRoot, displayLabel } = props; const ctx = use(TimelineRowCtx); @@ -301,20 +306,37 @@ function WorkEntryLogRow(props: WorkEntryRowProps) { const [expanded, setExpanded] = useState( () => groupView?.state.expandedEntries.has(workEntry.id) ?? false, ); - const noticeMessage = - workEntry.structuredPayload?.type === "system_notice" - ? workEntry.structuredPayload.message + const payload = workEntry.structuredPayload; + const mcpSignInNotice = + payload?.type === "system_notice" && payload.mcpSignIn !== undefined + ? { + threadId: payload.threadId, + providerThreadId: payload.providerThreadId, + server: payload.mcpSignIn.server, + noticeAt: DateTime.toEpochMillis(payload.updatedAt), + } : null; + const mcpSignedIn = useAtomValue( + mcpSignInNotice !== null + ? threadEnvironment.mcpSignedInAtom(ctx.activeThreadEnvironmentId, { + threadId: mcpSignInNotice.threadId, + server: mcpSignInNotice.server, + noticeAt: mcpSignInNotice.noticeAt, + }) + : NOT_SIGNED_IN, + ); + const mcpSignInResolved = mcpSignInNotice !== null && mcpSignedIn; + const noticeMessage = payload?.type === "system_notice" ? payload.message : null; const labelRef = useRef(null); const [noticeCutOff, setNoticeCutOff] = useState(false); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- only layout knows whether a notice fits its row useLayoutEffect(() => { const label = labelRef.current; - if (!label || noticeMessage === null) return; + if (!label || noticeMessage === null || mcpSignInResolved) return; const measure = () => setNoticeCutOff(label.scrollWidth > label.clientWidth); measure(); return observeResize(label, measure); - }, [noticeMessage]); + }, [noticeMessage, mcpSignInResolved]); const onInitialOutputReady = () => { if (groupView) groupView.onContentReady?.(workEntry.id); else props.onContentReady?.(); @@ -403,25 +425,30 @@ function WorkEntryLogRow(props: WorkEntryRowProps) { ); } const iconConfig = workToneIcon(workEntry.tone); - const showWarningIndicator = workEntry.sourceActivityKind === "runtime.warning"; + const showWarningIndicator = + !mcpSignInResolved && workEntry.sourceActivityKind === "runtime.warning"; const showFailedIndicator = - !showWarningIndicator && workEntryDisplayIndicatesToolFailure(workEntry); + !mcpSignInResolved && !showWarningIndicator && workEntryDisplayIndicatesToolFailure(workEntry); const showDestructiveRowStyle = !showWarningIndicator && showFailedIndicator && (workEntrySignalsSevereFailure(workEntry) || !workLogEntryIsToolLike(workEntry)); - const entryIconName = - showWarningIndicator || showDestructiveRowStyle ? "circle-alert" : workEntryIconName(workEntry); + const entryIconName = mcpSignInResolved + ? "check" + : showWarningIndicator || showDestructiveRowStyle + ? "circle-alert" + : workEntryIconName(workEntry); const entryToolIcon = - showWarningIndicator || showDestructiveRowStyle + mcpSignInResolved || showWarningIndicator || showDestructiveRowStyle ? undefined : (workEntry.toolIcon ?? workEntry.toolSource?.icon); const isReasoning = workEntry.itemType === "reasoning"; const questionHeading = workEntry.questionAnswer ? getQuestionTextPreview(workEntry.questionAnswer) : ""; - const previewText = - isReasoning && expanded + const previewText = mcpSignInResolved + ? gt("Signed in to {server}", { server: mcpSignInNotice.server }) + : isReasoning && expanded ? workEntry.toolLifecycleStatus === "inProgress" ? gt("Thinking") : gt("Thought") @@ -431,17 +458,13 @@ function WorkEntryLogRow(props: WorkEntryRowProps) { ? getQuestionAnswerPreview(workEntry.questionAnswer) : null; const viewedImagePath = workEntryViewedImagePath(workEntry); - const payload = workEntry.structuredPayload; const mcpSignIn = - payload?.type === "system_notice" && - payload.mcpSignIn !== undefined && - payload.providerThreadId !== null ? ( + mcpSignInNotice !== null && !mcpSignInResolved && mcpSignInNotice.providerThreadId !== null ? ( ) : null; const skill = @@ -496,6 +519,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) { turnItemNeedsDetailFetch(workEntry.projectedItem.item); // A notice's details repeat its row, so it expands only to show text the row cuts off. const canExpandProjectedItem = + !mcpSignInResolved && (noticeMessage === null || noticeCutOff) && (plainOutput !== undefined ? Boolean(plainOutput || viewedImage || workEntry.questionAnswer || plainOutputFetches) @@ -510,15 +534,17 @@ function WorkEntryLogRow(props: WorkEntryRowProps) { )); const iconWrapperClass = cn( "flex size-4 items-center justify-center", - showWarningIndicator - ? "text-warning" - : showDestructiveRowStyle - ? "text-destructive" - : showFailedIndicator - ? failedToolIconClassName - : workEntry.tone === "tool" - ? "text-icon-muted" - : iconConfig.className, + mcpSignInResolved + ? "text-success-foreground" + : showWarningIndicator + ? "text-warning" + : showDestructiveRowStyle + ? "text-destructive" + : showFailedIndicator + ? failedToolIconClassName + : workEntry.tone === "tool" + ? "text-icon-muted" + : iconConfig.className, ); const headingClass = showWarningIndicator ? "font-medium text-warning"