From 4cca6f0d27965d78f1949333024093f9951df58f Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Sat, 10 Oct 2026 22:24:45 +0000 Subject: [PATCH 1/2] Fix job run history sorting flash --- packages/app/src/features/runs/history.tsx | 6 +++--- packages/app/src/features/runs/queries.ts | 4 ++-- packages/app/test/runs.browser.test.mjs | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/app/src/features/runs/history.tsx b/packages/app/src/features/runs/history.tsx index 121210b5..f57e8906 100644 --- a/packages/app/src/features/runs/history.tsx +++ b/packages/app/src/features/runs/history.tsx @@ -10,7 +10,7 @@ export function RunHistory({ jobId }: { jobId: string }) { const runs = useQuery(historyQuery(jobId, search.cursor, search.sort, search.direction)); const previous = search.previous === undefined ? [] : search.previous.split(","); const pageClasses = `inline-flex min-h-10 items-center rounded-lg border px-3 py-2 text-sm font-semibold ${buttonClasses.secondary}`; - const columns: Array<[HistorySort, string]> = [["run", "Run"], ["status", "Status"], ["created", "Created"], ["agent", "Agent"]]; + const columns: Array<[HistorySort, string]> = [["status", "Status"], ["run", "Run"], ["created", "Created"], ["agent", "Agent"]]; const sortColumn = (column: HistorySort) => { const direction = search.sort === column && search.direction === "asc" ? "desc" : "asc"; void navigate({ to: "/jobs/$jobId", params: { jobId }, search: { sort: column, direction, cursor: undefined, previous: undefined } }); @@ -18,11 +18,11 @@ export function RunHistory({ jobId }: { jobId: string }) { const sortLabel = (column: HistorySort) => search.sort === column ? (search.direction === "desc" ? "sorted descending" : "sorted ascending") : "not sorted"; return
{runs.isPending &&

Loading run history…

}{runs.error &&

{runs.error.message}

} - {runs.data && <> + {runs.data && <>
Job runs{search.sort ? "" : ", newest first"}
{columns.map(([column, label]) => sortColumn(column)} />)}{runs.data.items.map(run => - + )}{runs.data.items.length === 0 && }
Job runs{search.sort ? "" : ", newest first"}
{run.run_name || run.issue_title || "Run"} {run.run_name || run.issue_title || "Run"} {run.agent_kind}
No runs found.
} diff --git a/packages/app/src/features/runs/queries.ts b/packages/app/src/features/runs/queries.ts index fbc226dd..a3360db8 100644 --- a/packages/app/src/features/runs/queries.ts +++ b/packages/app/src/features/runs/queries.ts @@ -1,5 +1,5 @@ import { api } from "factorize-api-client"; -import { queryOptions } from "@tanstack/react-query"; +import { keepPreviousData, queryOptions } from "@tanstack/react-query"; import { messageOf } from "../auth/session"; export const runStatusQuery = (runId: string) => queryOptions({ queryKey: ["runs", runId, "status"], @@ -23,4 +23,4 @@ export const runPageQuery = ({ jobId, cursor, limit, sort, direction }: { jobId? queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, limit, sort, direction } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, staleTime: 0, refetchInterval: 2_000, refetchIntervalInBackground: false, }); -export const historyQuery = (jobId: string, cursor?: string, sort?: "run" | "status" | "created" | "agent", direction?: "asc" | "desc") => queryOptions({ queryKey: ["runs", "history", jobId, cursor, sort, direction], queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, sort, direction: direction ?? (sort ? "asc" : undefined), limit: 30 } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, staleTime: 10_000 }); +export const historyQuery = (jobId: string, cursor?: string, sort?: "run" | "status" | "created" | "agent", direction?: "asc" | "desc") => queryOptions({ queryKey: ["runs", "history", jobId, cursor, sort, direction], queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, sort, direction: direction ?? (sort ? "asc" : undefined), limit: 30 } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, placeholderData: keepPreviousData, staleTime: 10_000 }); diff --git a/packages/app/test/runs.browser.test.mjs b/packages/app/test/runs.browser.test.mjs index ccd9b234..6ecb454a 100644 --- a/packages/app/test/runs.browser.test.mjs +++ b/packages/app/test/runs.browser.test.mjs @@ -69,6 +69,23 @@ test("job run history restores its cursor on direct refresh and ignores legacy f await page.goto(origin + `/jobs/${jobId}?state=succeeded&contextQuery=needle`); await page.getByRole("link", { name: "First run", exact: true }).waitFor(); await page.getByRole("link", { name: "Next page" }).click(); await page.getByRole("link", { name: "Second run", exact: true }).waitFor(); await page.reload(); await page.getByRole("link", { name: "Second run", exact: true }).waitFor(); assert.equal(new URL(page.url()).searchParams.get("cursor"), "next-cursor"); assert.ok(requests.every(url => url.searchParams.get("jobId") === jobId && url.searchParams.get("limit") === "30" && !url.searchParams.has("contextQuery") && !url.searchParams.has("state"))); await context.close(); }); +test("job run history keeps the table visible while sorting and puts status first", async () => { + const { context, page } = await setup(); let releaseSorted; + const sorted = new Promise(resolve => { releaseSorted = resolve; }); + await page.route(`**/api/v1/jobs/${jobId}`, route => route.fulfill({ json: { id: jobId, name: "Job", enabled: true, model: "", agentKind: "codex", concurrencyLimit: 1, runningCount: 0, promptTemplate: "Prompt", triggers: [] } })); + await page.route("**/api/v1/runs?**", async route => { + const url = new URL(route.request().url()); + if (url.searchParams.has("sort")) { await sorted; return route.fulfill({ json: { items: [{ id: runId, run_name: "Sorted run", state: "failed", created_at: time, agent_kind: "codex" }], nextCursor: null } }); } + return route.fulfill({ json: { items: [{ id: runId, run_name: "Initial run", state: "succeeded", created_at: time, agent_kind: "codex" }], nextCursor: null } }); + }); + await page.goto(origin + `/jobs/${jobId}`); const table = page.getByRole("region", { name: "Runs table" }); + await table.getByRole("link", { name: "Initial run", exact: true }).waitFor(); + assert.equal(await table.locator("thead th").first().textContent(), "Status"); + await table.getByRole("button", { name: /Run, not sorted/ }).click(); await page.waitForURL(`**/jobs/${jobId}?sort=run&direction=asc`); + assert.equal(await page.getByText("Loading run history…", { exact: true }).count(), 0); + assert.equal(await table.getByRole("link", { name: "Initial run", exact: true }).count(), 1); + releaseSorted(); await table.getByRole("link", { name: "Sorted run", exact: true }).waitFor(); await context.close(); +}); test("prompt/provenance and diagnostics are lazy, terminal replay retries reuse a stable key and reset the visible trace", async () => { const { context, page } = await setup(); let revision = "old", detailReads = 0, diagnosticReads = 0; const replays = []; await page.route(`**/api/v1/runs/${runId}/status`, route => route.fulfill({ json: { id: runId, job_id: jobId, job_name: "Job", run_name: "Run", state: "succeeded", finalizing: false, trace_revision: revision, artifact_state: "stored", created_at: time, updated_at: time, started_at: time, destination_url: null } })); From e23b6f7946cffaa297c882c62a3e2ced0f2bc562 Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Sat, 10 Oct 2026 22:29:59 +0000 Subject: [PATCH 2/2] test(app): update run history column order --- packages/app/test/jobs.browser.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/test/jobs.browser.test.mjs b/packages/app/test/jobs.browser.test.mjs index 90f16623..cc97f19f 100644 --- a/packages/app/test/jobs.browser.test.mjs +++ b/packages/app/test/jobs.browser.test.mjs @@ -301,7 +301,7 @@ test("run table headers sort every column accessibly and persist in the URL", as await page.goto(origin + `/jobs/${jobId}`); const table = page.getByRole("table"); await table.getByRole("columnheader").nth(0).getByRole("button").waitFor(); - assert.deepEqual(await table.locator("thead th").allTextContents(), ["Run", "Status", "Created", "Agent"]); + assert.deepEqual(await table.locator("thead th").allTextContents(), ["Status", "Run", "Created", "Agent"]); assert.equal(await table.getByRole("columnheader", { name: /Agent/ }).count(), 1); for (const index of [0, 1, 2, 3]) assert.equal(await table.getByRole("columnheader").nth(index).getByRole("button").count(), 1); const runButton = page.getByRole("button", { name: "Run job", exact: true }), optionsButton = page.getByRole("button", { name: "More run options", exact: true });