import { createFileRoute, Link, notFound } from "@tanstack/react-router"; import { useState } from "react"; import { z } from "zod"; import { getArtifactsHealth } from "~/fns/artifacts-health"; import type { ArtifactsFailure, ArtifactsOperationStats } from "~/fns/artifacts-health"; import { Button } from "~/ui/Button"; import { EmptyState } from "~/ui/EmptyState"; import { PageContainer } from "~/ui/PageContainer"; import { Panel } from "~/ui/Panel"; import { RelativeTime } from "~/ui/RelativeTime"; import { TextLink } from "~/ui/TextLink"; import { Heading } from "~/ui/Heading"; const WINDOWS = [1, 24, 168, 720] as const; const MAX_REPORT_REFERENCES = 50; export const Route = createFileRoute("/admin/artifacts")({ validateSearch: z.object({ hours: z.number().int().optional(), operation: z.string().optional() }), beforeLoad: ({ context }) => { if (!context.viewer?.isAdmin) throw notFound(); }, loaderDeps: ({ search }) => search, loader: ({ deps }) => getArtifactsHealth({ data: { hours: WINDOWS.find((hours) => hours === deps.hours) ?? 24, operation: deps.operation }, }), component: ArtifactsHealthPage, }); function rate(stats: ArtifactsOperationStats): string { return stats.calls === 0 ? "—" : `${((stats.failures / stats.calls) * 100).toFixed(2)}%`; } const HOURS_PER_DAY = 24; function windowLabel(hours: number): string { return hours < HOURS_PER_DAY ? `${hours}h` : `${hours / HOURS_PER_DAY}d`; } /** Plain-text incident report for Cloudflare support; mirrors docs/artifacts-report-template.md. */ function buildReport( hours: number, operation: string | null, operations: ArtifactsOperationStats[], failures: ArtifactsFailure[], ): string { const withReference = failures.filter((failure) => failure.reference); const end = Date.now(); const start = end - hours * 60 * 60 * 1000; const lines = [ 'Subject: Artifacts (beta) internal errors: "internal error; reference = …"', "", "Product: Cloudflare Artifacts (beta), Workers binding", `Window: last ${windowLabel(hours)} (${new Date(start).toISOString()} to ${new Date(end).toISOString()})`, "", "Failure rate by operation (untyped failures / calls):", ...operations .filter((stats) => stats.failures > 0 && (!operation || stats.operation === operation)) .map((stats) => `- ${stats.operation}: ${stats.failures} / ${stats.calls} (${rate(stats)})`), "", `Reference ids${operation ? ` for ${operation}` : ""} (${Math.min(withReference.length, MAX_REPORT_REFERENCES)} most recent of ${withReference.length}):`, ...withReference .slice(0, MAX_REPORT_REFERENCES) .map( (failure) => `- ${failure.reference} ${new Date(failure.created_at).toISOString()} ${failure.operation} ${failure.target} attempts=${failure.attempts}`, ), "", "Observed behaviour: the binding call rejects with an untyped error (no ArtifactsError code) whose message is", '"internal error; reference = ". Idempotent reads are retried up to 3 times with jittered backoff; the', "listed failures persisted through every attempt.", "Expected: a typed ArtifactsError code, or success.", "Impact: ", "Account / namespace: / ", ]; return lines.join("\n"); } function ArtifactsHealthPage() { const { hours, operation, operations, failures } = Route.useLoaderData(); const [copied, setCopied] = useState(false); const totals = operations.reduce( (sum, stats) => ({ operation: "all", calls: sum.calls + stats.calls, failures: sum.failures + stats.failures }), { operation: "all", calls: 0, failures: 0 }, ); const copy = async () => { await navigator.clipboard.writeText(buildReport(hours, operation, operations, failures)); setCopied(true); }; return (
Artifacts health

Untyped Artifacts failures (“internal error; reference = …”) by operation. Overall{" "} {rate(totals)} of {totals.calls} calls.

{WINDOWS.map((window) => ( {windowLabel(window)} ))}
{operations.length === 0 ? ( ) : ( {operations.map((stats) => ( ))}
Operation Calls Failures Rate
{stats.operation} {stats.calls} {stats.failures} {rate(stats)}
)}
Show all operations ) } > {failures.length === 0 ? ( ) : (
    {failures.map((failure) => (
  • {failure.reference ?? "no reference"} {failure.operation} {failure.target} attempts {failure.attempts}

    {failure.message}

  • ))}
)}
); }