Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(jobs): resolve model source bucket for legacy pre-assembler uploads

Sidwebworkse434ab25b656
diff --git a/packages/jobs/src/inngest/functions/tasks/assembler-client.ts b/packages/jobs/src/inngest/functions/tasks/assembler-client.ts
index a574a012bf..5ba57a6d3a 100644
--- a/packages/jobs/src/inngest/functions/tasks/assembler-client.ts
+++ b/packages/jobs/src/inngest/functions/tasks/assembler-client.ts
@@ -1,5 +1,5 @@
import { createHmac } from "node:crypto";
-import type { Json } from "@carbon/database";
+import type { Database, Json } from "@carbon/database";
import {
ASSEMBLER_SERVICE_API_KEY,
ASSEMBLER_SERVICE_URL,
@@ -9,6 +9,7 @@ import {
SESSION_SECRET,
SUPABASE_URL
} from "@carbon/env";
+import type { SupabaseClient } from "@supabase/supabase-js";
import { NonRetriableError } from "inngest";
// Shared client for the assembler service's `/v1` action-RPC API. Submit
@@ -51,6 +52,23 @@ export function assemblerBaseUrl(): string {
return ASSEMBLER_SERVICE_URL;
}
+/**
+ * Resolve which bucket a model's raw source lives in. Current uploads land in
+ * `temp-staging`; rows from before the assembler pipeline live in `private` —
+ * signing against the wrong bucket fails with "Object not found", so probe
+ * temp-staging and fall back (same resolution as the ERP model.artifacts route).
+ */
+export async function resolveModelSourceBucket(
+ client: SupabaseClient<Database>,
+ modelPath: string
+): Promise<"temp-staging" | "private"> {
+ const staged = await client.storage
+ .from("temp-staging")
+ .info(modelPath)
+ .catch(() => ({ data: null, error: true as const }));
+ return staged.error || !staged.data ? "private" : "temp-staging";
+}
+
/**
* Dev-only URL surgery on assembler-bound signed storage URLs. The portless
* `.dev` proxy exists only on this machine (/etc/hosts + local CA), so: a LOCAL
diff --git a/packages/jobs/src/inngest/functions/tasks/assembly-convert.ts b/packages/jobs/src/inngest/functions/tasks/assembly-convert.ts
index e7654c9791..75babc185a 100644
--- a/packages/jobs/src/inngest/functions/tasks/assembly-convert.ts
+++ b/packages/jobs/src/inngest/functions/tasks/assembly-convert.ts
@@ -4,6 +4,7 @@ import { inngest } from "../../client";
import {
assemblerEnabled,
internalizeStorageUrl,
+ resolveModelSourceBucket,
runAssemblerJob
} from "./assembler-client";
@@ -124,10 +125,14 @@ export const assemblyConvertFunction = inngest.createFunction(
logger,
buildBody: async () => {
const client = getCarbonServiceRole();
- // Raw source lives in `temp-staging` (2.5 GB cap); assembly artifacts
- // (glb/graph) are written to `private`.
+ // Legacy (pre-assembler) raws live in `private`, current ones in
+ // `temp-staging`; assembly artifacts (glb/graph) are written to `private`.
+ const sourceBucket = await resolveModelSourceBucket(
+ client,
+ job.modelPath
+ );
const source = await client.storage
- .from("temp-staging")
+ .from(sourceBucket)
.createSignedUrl(job.modelPath, SIGNED_URL_EXPIRY);
if (source.error) {
throw new Error(`Failed to sign source URL: ${source.error.message}`);
@@ -140,7 +145,7 @@ export const assemblyConvertFunction = inngest.createFunction(
let contentHash: string | undefined;
try {
const info = await client.storage
- .from("temp-staging")
+ .from(sourceBucket)
.info(job.modelPath);
const etag = info.data?.etag?.replaceAll('"', "");
if (!info.error && etag) {
diff --git a/packages/jobs/src/inngest/functions/tasks/assembly-plan.ts b/packages/jobs/src/inngest/functions/tasks/assembly-plan.ts
index ba934648a0..a8998359c7 100644
--- a/packages/jobs/src/inngest/functions/tasks/assembly-plan.ts
+++ b/packages/jobs/src/inngest/functions/tasks/assembly-plan.ts
@@ -7,6 +7,7 @@ import {
internalizeStorageUrl,
POLL_GAP,
pollAssemblerJobOnce,
+ resolveModelSourceBucket,
submitAssemblerJob
} from "./assembler-client";
import { loadPlanUnits } from "./plan-units";
@@ -218,9 +219,14 @@ export const assemblyPlanFunction = inngest.createFunction(
await step.run("submit", async () => {
const client = getCarbonServiceRole();
- // Raw source lives in `temp-staging` (2.5 GB cap).
+ // Legacy (pre-assembler) raws live in `private`, current ones in
+ // `temp-staging`.
+ const sourceBucket = await resolveModelSourceBucket(
+ client,
+ job.modelPath
+ );
const source = await client.storage
- .from("temp-staging")
+ .from(sourceBucket)
.createSignedUrl(job.modelPath, SIGNED_URL_EXPIRY);
if (source.error) {
throw new Error(`Failed to sign source URL: ${source.error.message}`);
diff --git a/packages/jobs/src/inngest/functions/tasks/model-optimize.ts b/packages/jobs/src/inngest/functions/tasks/model-optimize.ts
index e665d33f8c..919b850a8b 100644
--- a/packages/jobs/src/inngest/functions/tasks/model-optimize.ts
+++ b/packages/jobs/src/inngest/functions/tasks/model-optimize.ts
@@ -5,6 +5,7 @@ import { inngest } from "../../client";
import {
assemblerEnabled,
internalizeStorageUrl,
+ resolveModelSourceBucket,
runAssemblerJob
} from "./assembler-client";
@@ -74,7 +75,13 @@ export const modelOptimizeFunction = inngest.createFunction(
.update({ optimizeStatus: "Processing", optimizeError: null })
.eq("id", modelUploadId);
}
- return { modelPath: upload.data.modelPath, format };
+ // Legacy (pre-assembler) raws live in `private`, current ones in
+ // `temp-staging` — signing the wrong bucket 404s.
+ const sourceBucket = await resolveModelSourceBucket(
+ client,
+ upload.data.modelPath
+ );
+ return { modelPath: upload.data.modelPath, format, sourceBucket };
});
if (!model.format) {
@@ -102,10 +109,9 @@ export const modelOptimizeFunction = inngest.createFunction(
logger,
buildBody: async () => {
const client = getCarbonServiceRole();
- // Raw source lands in `temp-staging` (2.5 GB cap); optimised artifacts are
- // written to `private` (50 MB served cap) below.
+ // Optimised artifacts are written to `private` (50 MB served cap) below.
const source = await client.storage
- .from("temp-staging")
+ .from(model.sourceBucket)
.createSignedUrl(model.modelPath, SIGNED_URL_EXPIRY);
if (source.error) {
throw new Error(`Failed to sign source URL: ${source.error.message}`);
@@ -164,8 +170,11 @@ export const modelOptimizeFunction = inngest.createFunction(
// change. Already-compacted (`.zst`) raws are skipped. Best-effort: a
// compaction failure must not fail the already-succeeded optimise (the
// scheduled big-raw TTL prune is the safety net).
+ // Only temp-staging sources compact: the flow writes the .zst there, deletes
+ // the fat original there, and the TTL prune covers strays there. Legacy
+ // `private` raws predate the pipeline — leave them where they are.
const alreadyCompacted = model.modelPath.toLowerCase().endsWith(".zst");
- if (!alreadyCompacted) {
+ if (!alreadyCompacted && model.sourceBucket === "temp-staging") {
// Flat, mirroring the original raw (`${id}.step` → `${id}.step.zst`), so the
// model id stays recoverable from the path (CadModel's `modelIdFromPath`)
// and the download route resolves the underlying format from the extension.