Files
triggerdotdev--trigger.dev/apps/webapp/test/runsListQueryError.test.ts
T
Eric Allam 47ff76d727 feat(webapp,clickhouse): return an actionable error instead of a 500 when a runs list query is too expensive (#4773)
## Summary

When a runs list query is too expensive to complete, it now fails with a
clear, actionable error instead of a generic 500.

Previously, a runs list query that exceeded ClickHouse resource limits
threw an opaque error. On the public `runs.list` API that surfaced as a
retryable 500, so a customer task calling it would keep retrying a query
that could never succeed. On the dashboard it rendered as a generic
error page with no hint about what to do.

## Fix

The ClickHouse client now tags resource-limit failures (memory, time,
rows, bytes) with their error type, and the runs repository maps those
to a dedicated `RunsListQueryError` (HTTP 422).

- `runs.list` API returns 422 with a message telling the user to narrow
their `created_at` range, plus an `x-should-retry: false` header so the
SDK does not retry it.
- The dashboard runs list (and the errors, scheduled, standard-task,
agents, and webhooks list views) render a shared error state with the
same guidance, so a too-broad time filter is recoverable by the user.
2026-08-25 14:49:10 +01:00

53 lines
1.9 KiB
TypeScript

import { ClickHouse } from "@internal/clickhouse";
import { containerTest } from "@internal/testcontainers";
import { describe, expect, vi } from "vitest";
import {
RunsListQueryError,
RunsRepository,
} from "~/services/runsRepository/runsRepository.server";
import {
createRun,
insertTaskRunV2Rows,
seedParents,
} from "./helpers/apiRunListPresenterTestHelpers";
vi.mock("~/db.server", () => ({ prisma: {}, $replica: {} }));
vi.setConfig({ testTimeout: 90_000 });
describe("runs list query error handling", () => {
containerTest(
"a ClickHouse resource-limit error surfaces as RunsListQueryError",
async ({ clickhouseContainer, prisma }) => {
const ctx = await seedParents(prisma, "qerr");
const run = await createRun(prisma, ctx, { friendlyId: "run_qerr" });
const seedClient = new ClickHouse({
url: clickhouseContainer.getConnectionUrl(),
name: "runs-list-query-error-seed",
});
await insertTaskRunV2Rows(seedClient, [{ ...run, createdAt: new Date() }]);
const listArgs = {
page: { size: 10 } as const,
organizationId: ctx.organizationId,
projectId: ctx.projectId,
environmentId: ctx.environmentId,
};
const cappedClient = new ClickHouse({
url: clickhouseContainer.getConnectionUrl(),
name: "runs-list-query-error-capped",
clickhouseSettings: { max_memory_usage: "1" },
});
const capped = new RunsRepository({ prisma, clickhouse: cappedClient });
await expect(capped.listRuns(listArgs)).rejects.toBeInstanceOf(RunsListQueryError);
await expect(capped.countRuns(listArgs)).rejects.toBeInstanceOf(RunsListQueryError);
const ok = new RunsRepository({ prisma, clickhouse: seedClient });
const result = await ok.listRuns(listArgs);
expect(result.runs.map((r) => r.friendlyId)).toEqual(["run_qerr"]);
}
);
});