Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): Topics shows analyzing, waiting and failed screens on the first run (#19285)

Trang Nguyene139e39b9ee5
diff --git a/web/src/features/topics/TopicPilesIllustration.tsx b/web/src/features/topics/TopicPilesIllustration.tsx
index bde559bd7e..198cadeeee 100644
--- a/web/src/features/topics/TopicPilesIllustration.tsx
+++ b/web/src/features/topics/TopicPilesIllustration.tsx
@@ -98,7 +98,7 @@ function fadedColor(color: PileColor, index: number) {
type PileColor = "violet" | "blue" | "amber";
-type TopicPile = {
+export type TopicPile = {
name: string;
detail: string;
slots: number;
diff --git a/web/src/features/topics/TopicSetupProgressView.stories.tsx b/web/src/features/topics/TopicSetupProgressView.stories.tsx
index bb45f1d2f4..8984867114 100644
--- a/web/src/features/topics/TopicSetupProgressView.stories.tsx
+++ b/web/src/features/topics/TopicSetupProgressView.stories.tsx
@@ -7,8 +7,6 @@ const facets = ["Intent", "Sentiment", "Outcome", "Issues"].map((name) => ({
name,
complete: 200,
requested: 500,
- outcome: null as string | null,
- topicCount: null as number | null,
}));
const meta = preview.meta({
@@ -18,7 +16,6 @@ const meta = preview.meta({
facets,
retrying: false,
canRetry: true,
- onDisplayResults: fn(),
onRetry: fn(),
},
});
@@ -32,16 +29,8 @@ export const Naming = meta.story({
},
});
-export const Done = meta.story({
- args: {
- stage: "done" as const,
- facets: facets.map((facet, index) => ({
- ...facet,
- complete: 500,
- outcome: index === 3 ? "insufficient_data" : "published",
- topicCount: index === 3 ? null : 4 + index,
- })),
- },
-});
-
export const Failed = meta.story({ args: { stage: "failed" as const } });
+
+export const WaitingForTraces = meta.story({
+ args: { waiting: true, facets: [], canRetry: false },
+});
diff --git a/web/src/features/topics/TopicSetupProgressView.tsx b/web/src/features/topics/TopicSetupProgressView.tsx
index be23595a3d..5245b61b4b 100644
--- a/web/src/features/topics/TopicSetupProgressView.tsx
+++ b/web/src/features/topics/TopicSetupProgressView.tsx
@@ -1,212 +1,169 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
-import { Check, Sparkles } from "@langfuse/icons";
+import { useEffect, useState } from "react";
import { Button } from "@/src/components/design-system/Button/Button";
-import { Progress } from "@/src/components/design-system/Progress/Progress";
-import { Spinner } from "@/src/components/design-system/Spinner/Spinner";
import { type TopicSetupStage } from "./topic-setup-flow";
+import {
+ type TopicPile,
+ TopicPilesIllustration,
+} from "./TopicPilesIllustration";
-export type TopicSetupProgressFacet = {
+type TopicSetupProgressFacet = {
key: string;
name: string;
complete: number;
requested: number;
- outcome: string | null;
- topicCount: number | null;
};
-const RUNNING = {
- title: "Analyzing your traces",
- detail: "This runs in the background. You can leave this page.",
-};
-const COPY: Record<TopicSetupStage, { title: string; detail: string }> = {
- summarizing: RUNNING,
- grouping: RUNNING,
- naming: RUNNING,
- done: {
- title: "Your first topics are ready",
- detail: "Display the results to explore them.",
- },
- failed: {
- title: "The first analysis did not finish",
- detail: "Retry picks up where it stopped.",
- },
-};
-const TOPIC_STEPS = [
- { stage: "grouping", label: "Identifying clusters" },
- { stage: "naming", label: "Generating & refining topics" },
+const PILE_SLOTS = [
+ { name: "Group 1", slots: 9, color: "violet" },
+ { name: "Group 2", slots: 6, color: "blue" },
+ { name: "Group 3", slots: 4, color: "amber" },
] as const;
-const NO_TOPICS = new Set([
- "no_topics",
- "insufficient_data",
- "no_applicable_summaries",
-]);
-/** First-run progress in two phases: summaries, then topics. */
+const TICK_MS = 260;
+
+const STAGE_LABEL: Partial<Record<TopicSetupStage, string>> = {
+ summarizing: "Summarizing traces",
+ grouping: "Finding similar answers",
+ naming: "Naming topics",
+};
+
+/** First analysis in progress: one illustration, one line of copy and one progress bar. */
export function TopicSetupProgressView({
canRetry,
facets,
onViewDetails,
- onDisplayResults,
onRetry,
retrying,
stage,
-}: {
- facets: TopicSetupProgressFacet[];
- stage: TopicSetupStage;
- retrying: boolean;
- canRetry: boolean;
- onDisplayResults: () => void;
- // Opens the run in History; set when a run or one of its facets failed.
- onViewDetails?: () => void;
- onRetry: () => void;
-}) {
+ waiting = false,
+}: TopicSetupProgressViewProps) {
+ const failed = stage === "failed";
+ const animate = !failed && !waiting;
+ const tick = usePileTick(animate);
const requested = Math.max(0, ...facets.map((facet) => facet.requested));
const complete = Math.min(
requested,
...facets.map((facet) => facet.complete),
);
const summarizing = stage === "summarizing";
- const summariesDone =
- stage === "grouping" || stage === "naming" || stage === "done";
- const percent =
- summariesDone || requested === 0
- ? 100
- : Math.round((complete / requested) * 100);
- const topicIndex = ["grouping", "naming", "done"].indexOf(stage);
+ const processed = summarizing ? complete : requested;
+ const percent = requested === 0 ? 0 : (processed / requested) * 100;
+ const copy = progressCopy(failed, waiting);
+ const piles: TopicPile[] = PILE_SLOTS.map((pile, index) => ({
+ ...pile,
+ detail: "",
+ filled: pileFill(pile.slots, index, tick),
+ }));
return (
- <div className="mx-auto flex w-full max-w-2xl flex-col items-center gap-6 overflow-y-auto px-4 pt-12">
+ <div className="flex flex-1 flex-col items-center-safe justify-center-safe gap-6 overflow-y-auto px-4 pb-35">
+ <TopicPilesIllustration piles={piles} bare />
<div className="flex flex-col items-center gap-2 text-center">
- <Sparkles aria-hidden="true" size="xl" color="muted" />
- <h2 className="text-2xl font-bold">{COPY[stage].title}</h2>
- <p className="text-muted-foreground text-sm">
- {stage === "failed" && !canRetry
- ? "Topics could not start. Use Generate topics in the menu."
- : COPY[stage].detail}
+ <h2 className="text-3xl leading-tight font-bold tracking-tight text-balance">
+ {copy.title}
+ </h2>
+ <p className="text-muted-foreground text-sm text-pretty">
+ {failed && !canRetry ? NO_RETRY_DETAIL : copy.detail}
</p>
</div>
- <div className="grid w-full gap-4 sm:grid-cols-2">
- <section className="bg-card flex flex-col gap-3 rounded-xl border p-5">
- <div className="flex items-center gap-2">
- <PhaseMarker done={summariesDone} active={summarizing} index={1} />
- <h3 className="text-sm font-bold">
- Analyzing traces & generating summaries
- </h3>
- </div>
- <div className="flex items-center gap-3">
- <div className="flex-1">
- <Progress value={percent} />
- </div>
- <span className="text-muted-foreground w-10 text-right font-mono text-xs">
- {percent}%
- </span>
- </div>
- <span className="text-muted-foreground text-xs">
- {summariesDone
- ? `${requested.toLocaleString("en-US")} traces summarized`
- : `${complete.toLocaleString("en-US")} of ${requested.toLocaleString("en-US")} traces`}
- </span>
- </section>
- <section className="bg-card flex flex-col gap-3 rounded-xl border p-5">
- <div className="flex items-center gap-2">
- <PhaseMarker
- done={stage === "done"}
- active={stage === "grouping" || stage === "naming"}
- index={2}
+ {failed ? (
+ <div className="flex items-center gap-2">
+ {canRetry && (
+ <Button text="Retry" loading={retrying} onClick={onRetry} />
+ )}
+ {onViewDetails && (
+ <Button
+ text="See run details"
+ variant="ghost"
+ onClick={onViewDetails}
/>
- <h3 className="text-sm font-bold">
- Identifying clusters & generating topics
- </h3>
- </div>
- {topicIndex < 0 ? (
- <span className="text-muted-foreground text-xs">
- Starts when summaries are done.
- </span>
- ) : null}
- {topicIndex >= 0 && stage !== "done" ? (
- <ul className="flex flex-col gap-1.5">
- {TOPIC_STEPS.map((step, index) => (
- <li
- key={step.stage}
- className="text-muted-foreground flex items-center gap-2 text-xs"
- >
- <StepMarker state={stepState(index, topicIndex)} />
- {step.label}
- </li>
- ))}
- </ul>
- ) : null}
- {stage === "done" ? (
- <ul className="flex flex-col gap-1.5">
- {facets.map((facet) => (
- <li
- key={facet.key}
- className="flex items-center justify-between gap-2 text-xs"
- >
- <span>{facet.name}</span>
- <span className="text-muted-foreground">
- {facetResult(facet)}
- </span>
- </li>
- ))}
- </ul>
- ) : null}
- </section>
- </div>
- {stage === "done" ? (
- <Button text="Display results" onClick={onDisplayResults} />
- ) : null}
- {stage === "failed" && canRetry ? (
- <Button text="Retry" loading={retrying} onClick={onRetry} />
- ) : null}
- {onViewDetails ? (
- <Button
- text="See run details"
- variant="ghost"
- onClick={onViewDetails}
- />
+ )}
+ </div>
) : null}
+ {!failed && !waiting && (
+ <div className="flex w-90 max-w-full flex-col gap-2">
+ <div
+ role="progressbar"
+ aria-label="Analysis progress"
+ aria-valuemin={0}
+ aria-valuemax={100}
+ aria-valuenow={Math.round(percent)}
+ className="bg-muted h-1.5 overflow-hidden rounded-sm"
+ >
+ <div
+ className="bg-foreground h-full rounded-sm transition-[width] duration-300"
+ style={{ width: `${percent}%` }}
+ />
+ </div>
+ <div className="text-muted-foreground flex justify-between gap-2 text-xs">
+ <span>{STAGE_LABEL[stage]}</span>
+ {requested > 0 && (
+ <span className="text-foreground font-mono">
+ {processed.toLocaleString("en-US")} /{" "}
+ {requested.toLocaleString("en-US")}
+ </span>
+ )}
+ </div>
+ </div>
+ )}
</div>
);
}
-function stepState(index: number, current: number) {
- if (index < current) return "done";
- if (index === current) return "active";
- return "waiting";
-}
-
-function facetResult(facet: TopicSetupProgressFacet) {
- if (facet.outcome === "failed") return "Failed";
- if (NO_TOPICS.has(facet.outcome ?? "")) return "Not enough data yet";
- if (facet.topicCount === null) return "Topics ready";
- return `${facet.topicCount} ${facet.topicCount === 1 ? "topic" : "topics"}`;
+/** Animation tick for the piles; stays at 0 when animation is off or motion is reduced. */
+function usePileTick(enabled: boolean) {
+ const [tick, setTick] = useState(0);
+ useEffect(() => {
+ if (!enabled) return;
+ if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
+ const interval = window.setInterval(
+ () => setTick((current) => current + 1),
+ TICK_MS,
+ );
+ return () => window.clearInterval(interval);
+ }, [enabled]);
+ return enabled ? tick : 0;
}
-function PhaseMarker({
- active,
- done,
- index,
-}: {
- active: boolean;
- done: boolean;
- index: number;
-}) {
- if (done)
- return (
- <span className="bg-dark-green flex size-5 shrink-0 items-center justify-center rounded-full text-white">
- <Check size="sm" aria-hidden="true" />
- </span>
- );
- if (active) return <Spinner size="sm" />;
- return (
- <span className="text-muted-foreground flex size-5 shrink-0 items-center justify-center rounded-full border text-xs">
- {index}
- </span>
+/** Piles fill and drain out of step; at tick 0 they sit near half full. */
+function pileFill(slots: number, pileIndex: number, tick: number) {
+ if (tick === 0) return Math.max(1, Math.round(slots / 2));
+ return Math.max(
+ 1,
+ Math.round(slots * (0.5 + 0.5 * Math.sin(tick * 0.12 + pileIndex * 1.7))),
);
}
-function StepMarker({ state }: { state: "done" | "active" | "waiting" }) {
- if (state === "done") return <Check size="sm" aria-hidden="true" />;
- if (state === "active") return <Spinner size="xxs" />;
- return <span className="size-3 rounded-full border" />;
+const NO_RETRY_DETAIL =
+ "Topics could not start. Use Generate topics in the menu.";
+
+function progressCopy(failed: boolean, waiting: boolean) {
+ if (failed)
+ return {
+ title: "The first analysis did not finish",
+ detail: "Retry picks up where it stopped.",
+ };
+ if (waiting)
+ return {
+ title: "Waiting for new traces",
+ detail:
+ "Automatic processing is on. Topics appear once new traces are summarized.",
+ };
+ return {
+ title: "Analyzing your traces",
+ detail:
+ "Runs in the background. Your topics will be here when you're back.",
+ };
}
+
+type TopicSetupProgressViewProps = {
+ facets: TopicSetupProgressFacet[];
+ stage: TopicSetupStage;
+ retrying: boolean;
+ canRetry: boolean;
+ /** Opens the failed run in History. */
+ onViewDetails?: () => void;
+ onRetry: () => void;
+ /** Automatic processing is on but no trace has been summarized yet. */
+ waiting?: boolean;
+};
diff --git a/web/src/features/topics/TopicsPage.clienttest.tsx b/web/src/features/topics/TopicsPage.clienttest.tsx
index 861d183ebb..53738b9fd8 100644
--- a/web/src/features/topics/TopicsPage.clienttest.tsx
+++ b/web/src/features/topics/TopicsPage.clienttest.tsx
@@ -230,9 +230,6 @@ vi.mock("@/src/utils/api", () => ({
: null,
}),
},
- setupTopicCounts: {
- useQuery: () => ({ data: undefined }),
- },
setAutomaticProcessing: {
useMutation: () => ({
isPending: false,
diff --git a/web/src/features/topics/TopicsPage.tsx b/web/src/features/topics/TopicsPage.tsx
index fedbe65dbd..30242dda4f 100644
--- a/web/src/features/topics/TopicsPage.tsx
+++ b/web/src/features/topics/TopicsPage.tsx
@@ -271,39 +271,25 @@ function TopicsWorkspaceContent({
},
);
const [mountedAt] = useState(Date.now);
- const [acknowledgedSetupId, setAcknowledgedSetupId] = useState<string | null>(
- null,
- );
const setupRun = topicSetupRun(executions.data ?? []);
const setup = setupRun ? topicSetupStage(setupRun, Date.now()) : null;
- // A run that finished before this visit is not replayed; results show instead.
+ // A finished run hands over to results; a failure from this visit stays until retried.
const showSetupProgress =
setupRun !== null &&
setup !== null &&
- setupRun.process.id !== acknowledgedSetupId &&
(["summarizing", "grouping", "naming"].includes(setup.stage) ||
- Date.parse((setupRun.update ?? setupRun.process).updatedAt) > mountedAt);
- const setupRunIds =
- setupRun?.update?.facets.flatMap((facet) =>
- facet.runId ? [facet.runId] : [],
- ) ?? [];
- const setupTopicCounts = api.topics.setupTopicCounts.useQuery(
- { projectId, runIds: setupRunIds },
- { enabled: setup?.stage === "done" && setupRunIds.length > 0 },
- );
+ (setup.stage === "failed" &&
+ Date.parse((setupRun.update ?? setupRun.process).updatedAt) >
+ mountedAt));
const setupRetry = api.topics.retry.useMutation({
onSuccess: () => utils.topics.executions.invalidate({ projectId }),
});
- // A run worth inspecting: the one that failed, or a topic run with failed facets.
const setupDetailsId =
- setupRun && setup ? detailsRunId(setupRun, setup) : null;
- const setupFacets =
- setupRun?.process.facets.map((facet) => {
- const update = setupRun.update?.facets.find(
- (item) =>
- item.facetId === facet.facetId &&
- item.facetVersion === facet.facetVersion,
- );
+ setupRun && setup?.stage === "failed"
+ ? (setup.retryId ?? setupRun.update?.id ?? setupRun.process.id)
+ : null;
+ const runFacets = (run: typeof setupRun) =>
+ run?.process.facets.map((facet) => {
return {
key: `${facet.facetId}:${facet.facetVersion}`,
name:
@@ -311,12 +297,14 @@ function TopicsWorkspaceContent({
"Facet",
complete: facet.counts.complete,
requested: facet.counts.requested,
- outcome: update?.outcome ?? null,
- topicCount:
- setupTopicCounts.data?.find((count) => count.runId === update?.runId)
- ?.topicCount ?? null,
};
}) ?? [];
+ const setupFacets = runFacets(setupRun);
+ const busyProcess =
+ (executions.data ?? []).find(
+ (execution) =>
+ execution.input.operation === "process" && busy(execution.status),
+ ) ?? null;
const executionId =
typeof router.query.executionId === "string"
? router.query.executionId
@@ -487,6 +475,16 @@ function TopicsWorkspaceContent({
!results.isLoading &&
!results.error &&
!hasStoredSummaries;
+ // Without a tracked setup run, a running summary run or automatic processing still shows progress.
+ const landingRun =
+ showLanding && !showSetupProgress && busyProcess
+ ? { process: busyProcess, update: null }
+ : null;
+ const waitingForTraces =
+ showLanding &&
+ !showSetupProgress &&
+ !landingRun &&
+ modelSettings.automaticProcessing.state.status === "on";
const showOnboarding = showSetupProgress || showLanding;
const landingOnly =
showLanding && !showSetupProgress && !setupBlockedReason;
@@ -599,8 +597,33 @@ function TopicsWorkspaceContent({
startBlockedReason={setupBlockedReason}
onKeepOff={automaticProcessing.clearPause}
onTurnBackOn={turnAutomaticProcessingBackOn}
- showOnboarding={showLanding && !showSetupProgress}
+ showOnboarding={
+ showLanding &&
+ !showSetupProgress &&
+ !landingRun &&
+ !waitingForTraces
+ }
/>
+ {landingRun ? (
+ <TopicSetupProgressView
+ stage={topicSetupStage(landingRun, Date.now()).stage}
+ facets={runFacets(landingRun)}
+ retrying={false}
+ canRetry={false}
+ onViewDetails={() => openExecution(landingRun.process.id)}
+ onRetry={refreshResults}
+ />
+ ) : null}
+ {waitingForTraces ? (
+ <TopicSetupProgressView
+ waiting
+ stage="summarizing"
+ facets={[]}
+ retrying={false}
+ canRetry={false}
+ onRetry={refreshResults}
+ />
+ ) : null}
{showSetupProgress && setup ? (
<TopicSetupProgressView
stage={setup.stage}
@@ -619,10 +642,6 @@ function TopicsWorkspaceContent({
executionId: setup.retryId,
});
}}
- onDisplayResults={() => {
- setAcknowledgedSetupId(setupRun.process.id);
- return utils.topics.invalidate();
- }}
/>
) : null}
<Sheet
@@ -1045,17 +1064,3 @@ function startBlockedReason(running: boolean, automaticOn: boolean) {
return "Automatic processing is on. Topics appear here as traces are summarized.";
return null;
}
-
-function detailsRunId(
- run: {
- process: { id: string };
- update: { id: string; facets: Array<{ outcome: string }> } | null;
- },
- setup: { stage: string; retryId: string | null },
-) {
- if (setup.stage === "failed")
- return setup.retryId ?? run.update?.id ?? run.process.id;
- return run.update?.facets.some((facet) => facet.outcome === "failed")
- ? run.update.id
- : null;
-}
diff --git a/web/src/features/topics/server/topicsRouter.ts b/web/src/features/topics/server/topicsRouter.ts
index e36e73afe9..ede745fbc4 100644
--- a/web/src/features/topics/server/topicsRouter.ts
+++ b/web/src/features/topics/server/topicsRouter.ts
@@ -474,19 +474,6 @@ export const topicsRouter = createTRPCRouter({
if (!execution) throw new LangfuseNotFoundError("Execution not found.");
return readTopicExecutionTraceErrors(execution);
}),
- /** Topics each grouping run published, for the setup progress view. */
- setupTopicCounts: topicsProcedure
- .input(projectInput.extend({ runIds: z.array(topicIdSchema).max(20) }))
- .query(async ({ input, ctx }) => {
- const runs = await ctx.prisma.topicClusteringRun.findMany({
- where: { projectId: input.projectId, id: { in: input.runIds } },
- select: { id: true, topicVersionIds: true },
- });
- return runs.map((run) => ({
- runId: run.id,
- topicCount: run.topicVersionIds.length,
- }));
- }),
setupTraceCounts: topicsProcedure.query(async ({ input }) =>
getTopicSetupTraceCounts({
projectId: input.projectId,