Skip to content

Commit be2136a

Browse files
alanshurafaclaude
andcommitted
fix: atomic job execution CAS and graceful embedding fallback
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e196e9c commit be2136a

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

integrations/smart-ingest/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,17 @@ async function handleExecuteJob(req: Request): Promise<Response> {
786786
.from("ingestion_items").select("*").eq("job_id", jobId).order("id");
787787
const items = itemRows ?? [];
788788

789-
await updateJobById(jobId, { status: "executing" });
789+
// CAS: only transition dry_run_complete -> executing; concurrent requests get 409
790+
const { data: casRow, error: casErr } = await supabase
791+
.from("ingestion_jobs")
792+
.update({ status: "executing" })
793+
.eq("id", jobId)
794+
.eq("status", "dry_run_complete")
795+
.select("id, status")
796+
.maybeSingle();
797+
if (casErr || !casRow || casRow.status !== "executing") {
798+
return json({ error: "Job execution conflict — another request may have claimed this job" }, 409);
799+
}
790800

791801
let addedCount = 0, skippedCount = 0, appendedCount = 0, revisedCount = 0;
792802
const sourceLabel = job.source_label ?? null;
@@ -1001,7 +1011,12 @@ Deno.serve(async (req) => {
10011011

10021012
try {
10031013
const fingerprint = await computeContentFingerprint(thought.content);
1004-
const embedding = await embedText(thought.content);
1014+
let embedding: number[] = [];
1015+
try {
1016+
embedding = await embedText(thought.content);
1017+
} catch (embedErr) {
1018+
console.warn(`embedText failed for thought (fingerprint=${fingerprint}), proceeding with null embedding:`, embedErr instanceof Error ? embedErr.message : String(embedErr));
1019+
}
10051020
const reconciled = await reconcileThought(thought, embedding, fingerprint, jobFingerprints);
10061021
jobFingerprints.add(fingerprint);
10071022
items.push({ ...reconciled, status: "pending", error_message: null });

0 commit comments

Comments
 (0)