Skip to content

The platform for continuously improving AI agents.

Fix dedicated GPU dialog feedback and restore New dataset (#291)

Freyam Mehta7303fdf4c13b
diff --git a/frontend/src/components/inference/dedicated-deployment.test.tsx b/frontend/src/components/inference/dedicated-deployment.test.tsx
new file mode 100644
index 00000000..76f3b9bc
--- /dev/null
+++ b/frontend/src/components/inference/dedicated-deployment.test.tsx
@@ -0,0 +1,121 @@
+// @vitest-environment jsdom
+// covers: console-logic
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+
+const api = vi.hoisted(() => ({
+ auth: { authMeRetrieve: vi.fn() },
+ billing: { billingSubscriptionRetrieve: vi.fn() },
+ deployedModels: {
+ deployedModelsDedicatedCreate: vi.fn(),
+ deployedModelsDedicatedGpusList: vi.fn(),
+ deployedModelsDedicatedPartialUpdate: vi.fn(),
+ deployedModelsDedicatedRetrieve: vi.fn(),
+ },
+}));
+
+vi.mock("@/client", () => ({ default: api }));
+
+import type { DedicatedDeployment, DeployedModel } from "@/openapi";
+import { DedicatedDeploymentSection } from "./dedicated-deployment";
+
+const MODEL = {
+ id: "model-1",
+ inferenceContract: "chat",
+ modelId: "ft-model",
+ status: "ready",
+} as unknown as DeployedModel;
+
+const LIVE = {
+ gpuType: "L4",
+ id: "row-1",
+ idleShutdownSeconds: 900,
+ maxReplicas: 1,
+ minReplicas: 1,
+ modelId: "dedicated/ft-model",
+ runningReplicas: 1,
+ scaleToZero: false,
+ status: "online",
+} as unknown as DedicatedDeployment;
+
+beforeEach(() => {
+ api.auth.authMeRetrieve.mockResolvedValue({ billingEnabled: false });
+ api.billing.billingSubscriptionRetrieve.mockResolvedValue({ creditsUsd: "1000" });
+ api.deployedModels.deployedModelsDedicatedGpusList.mockResolvedValue([
+ { creditsPerGpuHour: "100", gpuType: "L4" },
+ ]);
+ api.deployedModels.deployedModelsDedicatedRetrieve.mockResolvedValue(null);
+ api.deployedModels.deployedModelsDedicatedCreate.mockResolvedValue(LIVE);
+ api.deployedModels.deployedModelsDedicatedPartialUpdate.mockResolvedValue(LIVE);
+});
+
+afterEach(() => {
+ cleanup();
+ vi.resetAllMocks();
+});
+
+async function openDialog(action: "Deploy" | "Update" = "Deploy") {
+ render(
+ <QueryClientProvider
+ client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}
+ >
+ <DedicatedDeploymentSection model={MODEL} projectId="project-1" />
+ </QueryClientProvider>
+ );
+ const configure = await screen.findByRole("button", { name: "Configure GPU" });
+ await waitFor(() => expect(configure).toHaveProperty("disabled", false));
+ fireEvent.click(configure);
+ return screen.findByRole("button", { name: action });
+}
+
+const enter = (label: string, value: string) =>
+ fireEvent.change(screen.getByLabelText(label), { target: { value } });
+
+it("closes the dialog when a deployment starts", async () => {
+ fireEvent.click(await openDialog());
+ await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
+ expect(api.deployedModels.deployedModelsDedicatedCreate).toHaveBeenCalledOnce();
+});
+
+it("closes the dialog when a running deployment updates", async () => {
+ api.deployedModels.deployedModelsDedicatedRetrieve.mockResolvedValue(LIVE);
+ fireEvent.click(await openDialog("Update"));
+ await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
+ expect(api.deployedModels.deployedModelsDedicatedPartialUpdate).toHaveBeenCalledOnce();
+});
+
+it("keeps the dialog open when a deployment cannot start", async () => {
+ api.deployedModels.deployedModelsDedicatedCreate.mockRejectedValue(new Error("No capacity"));
+ fireEvent.click(await openDialog());
+ await waitFor(() =>
+ expect(api.deployedModels.deployedModelsDedicatedCreate).toHaveBeenCalledOnce()
+ );
+ await screen.findByRole("button", { name: "Deploy" });
+ expect(screen.getByRole("dialog")).toBeTruthy();
+});
+
+it.each([
+ ["Min replicas", "0", "Min replicas must be 1–8"],
+ ["Min replicas", "", "Min replicas must be 1–8"],
+ ["Max replicas", "9", "Max replicas must be 1–8"],
+ ["Max replicas", "0", "Max replicas must be 1–8"],
+ ["Idle timeout (seconds)", "100", "Idle timeout must be 300–86,400 seconds"],
+ ["Idle timeout (seconds)", "86401", "Idle timeout must be 300–86,400 seconds"],
+])("names the invalid value when %s is %j", async (label, value, message) => {
+ const deploy = await openDialog();
+ enter(label, value);
+ expect(screen.getByText(message)).toBeTruthy();
+ expect(deploy).toHaveProperty("disabled", true);
+});
+
+it("replaces the price range when the minimum exceeds the maximum", async () => {
+ const deploy = await openDialog();
+ enter("Min replicas", "3");
+ expect(screen.getByText("Minimum replicas exceeds maximum")).toBeTruthy();
+ expect(screen.queryByText(/credits\/hour/)).toBeNull();
+ expect(deploy).toHaveProperty("disabled", true);
+ enter("Max replicas", "5");
+ expect(screen.getByText("300–500 credits/hour")).toBeTruthy();
+ expect(deploy).toHaveProperty("disabled", false);
+});
diff --git a/frontend/src/components/inference/dedicated-deployment.tsx b/frontend/src/components/inference/dedicated-deployment.tsx
index a2d0112b..9b6e4466 100644
--- a/frontend/src/components/inference/dedicated-deployment.tsx
+++ b/frontend/src/components/inference/dedicated-deployment.tsx
@@ -61,6 +61,9 @@ export const STATUS_TONE = {
const ACTIVE = new Set(["deploying", "warming", "online", "shutting_down"]);
const STARTING = new Set(["deploying", "warming"]);
+const MAX_REPLICAS = 8;
+const MIN_IDLE_SECONDS = 300;
+const MAX_IDLE_SECONDS = 24 * 60 * 60;
export function DedicatedStatusBadge({ status }: { status: string }) {
return (
@@ -99,6 +102,25 @@ function whole(raw: string): number | null {
return /^\d+$/.test(raw) ? Number(raw) : null;
}
+function configProblem(
+ minimum: number | null,
+ maximum: number | null,
+ idleSeconds: number | null,
+ scaleToZero: boolean
+): string | null {
+ if (!scaleToZero && (minimum == null || minimum < 1 || minimum > MAX_REPLICAS)) {
+ return `Min replicas must be 1–${MAX_REPLICAS}`;
+ }
+ if (maximum == null || maximum < 1 || maximum > MAX_REPLICAS) {
+ return `Max replicas must be 1–${MAX_REPLICAS}`;
+ }
+ if (minimum != null && minimum > maximum) return "Minimum replicas exceeds maximum";
+ if (idleSeconds == null || idleSeconds < MIN_IDLE_SECONDS || idleSeconds > MAX_IDLE_SECONDS) {
+ return `Idle timeout must be ${MIN_IDLE_SECONDS}–${MAX_IDLE_SECONDS.toLocaleString("en-US")} seconds`;
+ }
+ return null;
+}
+
function hourShortfall(balance: number, floor: number): string {
const owned = balance.toLocaleString("en-US");
const rate = floor.toLocaleString("en-US");
@@ -330,6 +352,7 @@ export function DedicatedDeploymentSection({
decision={model.inferenceContract === "decision"}
gpus={gpus.data}
model={model}
+ onDone={() => setOpen(false)}
row={row}
/>
) : null}
@@ -403,11 +426,13 @@ function GpuMenu({
decision,
gpus,
model,
+ onDone,
row,
}: {
decision: boolean;
gpus: DedicatedGpu[];
model: DeployedModel;
+ onDone: () => void;
row: DedicatedDeployment | null;
}) {
const [gpuType, setGpuType] = useState(row?.gpuType || gpus[0]?.gpuType || "");
@@ -444,16 +469,8 @@ function GpuMenu({
minReplicas: minimum ?? 0,
scaleToZero,
};
- const invalid =
- !gpuType ||
- credits == null ||
- minimum == null ||
- maxCount == null ||
- idleCount == null ||
- minimum > maxCount ||
- maxCount > 8 ||
- idleCount < 300 ||
- idleCount > 24 * 60 * 60;
+ const problem = configProblem(minimum, maxCount, idleCount, scaleToZero);
+ const invalid = !gpuType || credits == null || problem != null;
const balanceCredits = balanceUsd == null ? null : usdToOvermindCredits(balanceUsd);
const floorCredits = credits != null && minimum != null ? Math.round(minimum * credits) : null;
const hourWarning =
@@ -467,13 +484,16 @@ function GpuMenu({
: null;
const submit = () => {
- const onError = (error: unknown) =>
- notify.error(
- error,
- active ? "Couldn't update the deployment" : "Couldn't start the deployment"
- );
- if (active) update.mutate(body, { onError });
- else start.mutate(body, { onError });
+ const options = {
+ onError: (error: unknown) =>
+ notify.error(
+ error,
+ active ? "Couldn't update the deployment" : "Couldn't start the deployment"
+ ),
+ onSuccess: onDone,
+ };
+ if (active) update.mutate(body, options);
+ else start.mutate(body, options);
};
if (gpus.length === 0) {
@@ -566,19 +586,17 @@ function GpuMenu({
</div>
</TooltipProvider>
<div className="flex flex-wrap items-center justify-between gap-3 border-t border-border/70 pt-4">
- <span className="text-sm tabular-nums">
- {credits != null && minimum != null && maxCount != null
- ? `${(minimum * credits).toLocaleString(undefined, { maximumFractionDigits: 2 })}${minimum !== maxCount ? `–${(maxCount * credits).toLocaleString(undefined, { maximumFractionDigits: 2 })}` : ""} credits/hour`
- : "Price unavailable"}
+ <span className={problem ? "text-sm text-warning" : "text-sm tabular-nums"}>
+ {problem ??
+ (credits != null && minimum != null && maxCount != null
+ ? `${(minimum * credits).toLocaleString(undefined, { maximumFractionDigits: 2 })}${minimum !== maxCount ? `–${(maxCount * credits).toLocaleString(undefined, { maximumFractionDigits: 2 })}` : ""} credits/hour`
+ : "Price unavailable")}
</span>
<Button disabled={invalid || pending} onClick={submit} size="sm">
<Icon.play />
{pending ? "Saving" : active ? "Update" : "Deploy"}
</Button>
</div>
- {minimum != null && maxCount != null && minimum > maxCount ? (
- <p className="text-xs text-muted-foreground">Minimum replicas exceeds maximum</p>
- ) : null}
{hourWarning ? <p className="text-sm text-warning">{hourWarning}</p> : null}
</div>
);
diff --git a/frontend/src/routes/_auth/datasets.index.tsx b/frontend/src/routes/_auth/datasets.index.tsx
index 92f799eb..9c144cd9 100644
--- a/frontend/src/routes/_auth/datasets.index.tsx
+++ b/frontend/src/routes/_auth/datasets.index.tsx
@@ -9,10 +9,13 @@ import { DataProjectForm } from "@/components/onboarding/data-project-form";
import { OnboardingWindow } from "@/components/onboarding/onboarding-window";
import { ProjectRequiredEmptyState } from "@/components/project-required-empty-state";
import { QuickstartEmbed } from "@/components/quickstart/quickstart-embed";
+import { Button } from "@/components/ui/button";
+import { Icon } from "@/components/ui/icons";
import { PageHeader } from "@/components/ui/page-header";
import { PageShell } from "@/components/ui/page-shell";
import { useProjectDatasetsQuery } from "@/hooks/use-datasets";
import { useProjectCapabilitiesQuery } from "@/hooks/use-evaluations";
+import { useGuestGate } from "@/hooks/use-guest-gate";
import { useProjectsList } from "@/hooks/use-projects";
import { datasetWorkspaces } from "@/lib/dataset-workspaces";
import { featureFlags } from "@/lib/feature-flags";
@@ -52,6 +55,7 @@ function ProjectDatasets({ projectId }: { projectId: string }) {
const projects = useProjectsList();
const project = projects.data?.projects.find((project) => project.id === projectId);
const [createOpen, setCreateOpen] = useState(false);
+ const guard = useGuestGate();
const datasets = datasetWorkspaces(query.data ?? []);
useEffect(() => {
@@ -96,6 +100,14 @@ function ProjectDatasets({ projectId }: { projectId: string }) {
<PageShell
header={
<PageHeader
+ actions={
+ datasets.length > 0 ? (
+ <Button onClick={guard(() => setCreateOpen(true))} type="button">
+ <Icon.datasetAdd />
+ New dataset
+ </Button>
+ ) : undefined
+ }
count={query.data ? datasets.length : undefined}
description="Source data and step-by-step transformations for training and evaluation."
icon={