Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): a job id that is not a UUIDv7 is not found, not a Bigtable outage (#4892)

Gergő Móricz28bbead4da7b
diff --git a/apps/api/src/lib/bigtable-row-key.ts b/apps/api/src/lib/bigtable-row-key.ts
index fa25f9a21..f2fe4ebf3 100644
--- a/apps/api/src/lib/bigtable-row-key.ts
+++ b/apps/api/src/lib/bigtable-row-key.ts
@@ -3,6 +3,15 @@ import crypto from "crypto";
const UUID_V7 =
/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
+/**
+ * Whether `id` could name a row at all. Every Bigtable job row is keyed by a
+ * UUIDv7, so any other id has no row to find: callers answer "not found"
+ * without a read, rather than treating the key error as an outage.
+ */
+export function isUuidV7Id(id: string): boolean {
+ return UUID_V7.test(id);
+}
+
export function saltedUuidV7RowKey(id: string): string {
if (!UUID_V7.test(id)) {
throw new Error(`Expected a UUIDv7 row id, received ${id}`);
diff --git a/apps/api/src/lib/operational-job-access.test.ts b/apps/api/src/lib/operational-job-access.test.ts
index 9a074393c..d71478f92 100644
--- a/apps/api/src/lib/operational-job-access.test.ts
+++ b/apps/api/src/lib/operational-job-access.test.ts
@@ -88,6 +88,14 @@ describe("operational job access", () => {
await expect(getScrapeJobAccess(JOB_ID)).resolves.toBeNull();
});
+ it("answers not found for an id that is not a UUIDv7, without reading", async () => {
+ await expect(
+ getScrapeJobAccess("817f931c-89b5-472d-977c-b7061ac3ce1c"),
+ ).resolves.toBeNull();
+ await expect(getCrawlJobAccess("not-a-uuid")).resolves.toBeNull();
+ expect(readApiJobAccess).not.toHaveBeenCalled();
+ });
+
it("rethrows a failed Bigtable read instead of reporting a missing job", async () => {
readApiJobAccess.mockRejectedValue(new Error("Bigtable unavailable"));
await expect(getScrapeJobAccess(JOB_ID)).rejects.toThrow(
diff --git a/apps/api/src/lib/operational-job-access.ts b/apps/api/src/lib/operational-job-access.ts
index 353321b77..15d53c7e5 100644
--- a/apps/api/src/lib/operational-job-access.ts
+++ b/apps/api/src/lib/operational-job-access.ts
@@ -1,3 +1,4 @@
+import { isUuidV7Id } from "./bigtable-row-key";
import { logger } from "./logger";
import {
readApiJobAccess,
@@ -24,6 +25,8 @@ async function resolveOperationalJobAccess(params: {
id: string;
kinds: readonly ApiJobKind[];
}): Promise<OperationalJobAccess | null> {
+ // An id that is not a UUIDv7 names no row: not found, not an outage.
+ if (!isUuidV7Id(params.id)) return null;
let access: ApiJobAccess | null;
try {
access = await readApiJobAccess(params.id);