Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/app/src/features/runs/continuous-trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ export function ContinuousTrace({ runId, revision, active, onReset, preview = fa
});
const latestSequence = items.at(-1)?.sequence ?? 0;
const live = useQuery({
queryKey: ["runs", runId, "conversation-tail", revision, latestSequence],
enabled: !preview && active && visible && !!trace.data && !trace.isFetching,
queryKey: ["runs", runId, "conversation-tail", revision],
enabled: !preview && active && visible && !!trace.data,
queryFn: async ({ signal }) => {
const { data, error } = await api.GET("/api/v1/runs/{runId}/trace-pages", { signal, params: { path: { runId }, query: { after: latestSequence, revision, limit: 100 } } });
if (!data || error) throw new Error(messageOf(error)); return data;
},
refetchIntervalInBackground: false, refetchInterval: query => query.state.error ? 10_000 : 2_000, retry: 1,
});
useEffect(() => { const changed = live.data?.reset ? live.data : pages.find(page => page.reset || page.revision !== revision); if (changed) onReset(changed.revision); }, [live.data, pages, revision, onReset]);
useEffect(() => { if (live.data && !live.data.reset && live.data.revision === revision) setLiveItems(previous => [...previous, ...live.data!.items]); }, [live.data, revision]);
useEffect(() => { if (live.data && !live.data.reset && live.data.revision === revision && live.data.items.length) setLiveItems(previous => [...previous, ...live.data!.items]); }, [live.data, revision]);
useEffect(() => { setLiveItems([]); setExpanded(new Set()); }, [revision]);
useEffect(() => { initialAlignedRevision.current = null; followRef.current = true; historyTopArmedRef.current = true; }, [revision]);
const updateRetainedRows = () => {
Expand Down Expand Up @@ -196,6 +196,6 @@ export function ContinuousTrace({ runId, revision, active, onReset, preview = fa
</div>;
})}</div>
</div>
{active && <p role="status" className="mt-5 text-sm font-medium"><RunStatusLabel state="running" /></p>}
{active && <p data-run-trace-live role="status" aria-label="Run is still running" className="mt-5 flex items-center gap-2 text-sm font-medium"><RunStatusLabel state="running" /><span className="trace-live-dots" aria-hidden="true"><span /><span /><span /></span></p>}
</>;
}
5 changes: 5 additions & 0 deletions packages/app/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
.trace-content ul { list-style: disc; }
.trace-content ol { list-style: decimal; }
.trace-content blockquote { @apply border-l-2 border-factorize-500 pl-4 text-slate-600 dark:text-slate-300; }
.trace-live-dots { display: inline-flex; align-items: center; gap: .2rem; }
.trace-live-dots span { width: .3rem; height: .3rem; border-radius: 9999px; background: currentColor; animation: trace-dot-pulse 1.1s ease-in-out infinite; }
.trace-live-dots span:nth-child(2) { animation-delay: .18s; }
.trace-live-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes trace-dot-pulse { 0%, 60%, 100% { opacity: .35; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Template overlay shares the editable control's metrics, including wrapping and scroll. */
Expand Down
20 changes: 20 additions & 0 deletions packages/app/test/runs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,26 @@ test("run rename supports keyboard save and cancel, validates names, and preserv
await page.getByRole("button", { name: "Rename", exact: true }).click(); await page.getByRole("textbox", { name: "Run name" }).fill("Saved name"); await page.keyboard.press("Enter"); await page.getByRole("heading", { name: "Saved name", exact: true }).waitFor(); assert.deepEqual(saves, [{ name: "Saved name", expectedName: "Original run" }]);
await page.reload(); await page.getByRole("heading", { name: "Saved name", exact: true }).waitFor(); await context.close();
});
test("running trace shows animated dots and polls forward from its latest event", async () => {
const { context, page } = await setup(); const tailRequests = [];
const event = sequence => ({ id: `live-${sequence}`, sequence, type: "assistant_message", title: `Live ${sequence}`, preview: `Live ${sequence}`, display: {} });
await page.route(`**/api/v1/runs/${runId}/status`, route => route.fulfill({ json: { id: runId, job_id: jobId, job_name: "Job", run_name: "Live run", state: "running", finalizing: false, trace_revision: "live", artifact_state: "pending", created_at: time, updated_at: time, started_at: time, destination_url: null } }));
await page.route(`**/api/v1/runs/${runId}/trace-pages?**`, route => {
const query = new URL(route.request().url()).searchParams;
if (query.has("after")) {
const after = Number(query.get("after")); tailRequests.push(after);
return route.fulfill({ json: { items: [event(after + 1)], nextCursor: null, previousCursor: null, revision: "live", reset: false } });
}
return route.fulfill({ json: { items: [event(1)], nextCursor: null, previousCursor: null, revision: "live", reset: false } });
});
await page.goto(origin + "/job-runs/" + runId + "/trace");
const indicator = page.locator("[data-run-trace-live]"); await indicator.waitFor();
assert.equal(await indicator.locator(".trace-live-dots > span").count(), 3);
assert.equal(await indicator.locator(".trace-live-dots > span").first().evaluate(element => getComputedStyle(element).animationName), "trace-dot-pulse");
await page.getByText("Live 3", { exact: true }).waitFor({ timeout: 7000 });
assert.deepEqual(tailRequests.slice(0, 2), [1, 2], "each poll should request events after the latest displayed sequence");
await context.close();
});
test("full run trace uses pull-to-load history, preserves the anchor, and never crashes on disclosure toggles", async () => {
const { context, page } = await setup(); const requests = [];
const event = (sequence, type = "assistant_message") => ({ id: `trace-${sequence}`, sequence, type, title: `Trace ${sequence}`, preview: `Trace ${sequence}`, display: {} });
Expand Down
Loading