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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(mes): use the authoritative modelUpload id in the model viewer
Sidwebworks7cf538a33843
diff --git a/apps/mes/app/components/JobOperation/JobOperation.tsx b/apps/mes/app/components/JobOperation/JobOperation.tsxindex 795b797040..78c01141c7 100644--- a/apps/mes/app/components/JobOperation/JobOperation.tsx+++ b/apps/mes/app/components/JobOperation/JobOperation.tsx@@ -324,6 +324,10 @@ export const JobOperation = ({: null;const modelPath = operation.itemModelPath ?? job.modelPath ?? null;+ // Prefer the authoritative id (mirrors the modelPath precedence) over deriving+ // it from the path — legacy paths whose basename isn't the id would otherwise+ // resolve a phantom id and 404 the artifacts/reoptimise lookups.+ const modelUploadId = operation.itemModelId ?? job.modelId ?? null;const {artifacts,awaitingModel: modelPending,@@ -333,7 +337,7 @@ export const JobOperation = ({retryLabel: modelRetryLabel,cancel: onModelCancel,actionBusy: modelActionBusy- } = useOptimizedModel({ modelPath, companyId });+ } = useOptimizedModel({ modelPath, modelUploadId, companyId });const fetcher = useFetcher<Result>();diff --git a/packages/viewer/src/useOptimizedModel.ts b/packages/viewer/src/useOptimizedModel.tsindex ffd7081344..2fc745194c 100644--- a/packages/viewer/src/useOptimizedModel.ts+++ b/packages/viewer/src/useOptimizedModel.ts@@ -78,6 +78,7 @@ async function postModelAction(action: string, modelUploadId: string) {*/export function useOptimizedModel({modelPath,+ modelUploadId: explicitModelUploadId = null,companyId,/** A just-dropped local File (ERP upload flow) — counts toward the raw tier. */file = null,@@ -86,13 +87,21 @@ export function useOptimizedModel({paths = DEFAULT_PATHS}: {modelPath: string | null;+ /**+ * The authoritative `modelUpload.id`, when the caller has it (MES has it as+ * `operation.itemModelId ?? job.modelId`). Preferred over deriving the id from+ * `modelPath`: legacy rows whose stored path isn't `${company}/models/${id}.ext`+ * derive a phantom id, which 404s the artifacts/reoptimise lookups and hides an+ * already-optimised model. Falls back to path derivation when not supplied.+ */+ modelUploadId?: string | null;companyId: string;file?: File | null;enabled?: boolean;paths?: typeof DEFAULT_PATHS;}) {const queryClient = useQueryClient();- const modelUploadId = modelIdFromPath(modelPath);+ const modelUploadId = explicitModelUploadId ?? modelIdFromPath(modelPath);const gracePolls = useRef(0);const query = useQuery<ModelArtifacts>({