General Mills has spent tens of millions of dollars at its Fridley flour mill to produce oat flour that’s free of gluten.

The company built a seven-story concrete monolith and filled it with expensive machines, all to weed out little bits of wheat, barley and rye — gluten-containing grains that sneak into shipments of oats from the farm.

The effort is critical to producing gluten-free Cheerios, one of General Mills’ biggest cereal offensives in recent years. The company also has invested in safeguards at its cereal factories, physically separating gluten-free production.

Yet four months into General Mills’ conversion to gluten-free Cheerios, its system failed. The company last week recalled 1.8 million boxes of Cheerios and Honey Nut Cheerios made at a plant in Lodi, Calif., after discovering the cereal accidentally contained wheat.

“They are trying to get off to a good start with these gluten-free products, and you don’t want a glitch,” said Jack Russo, a stock analyst at Edward Jones.

Cheerios’ Facebook page lit up with concerns over the recall. “It’s going to be harder than you know to regain our trust,” one person wrote. The company apologized on Facebook and on its Taste of General Mills blog, telling Cheerios fans it was “embarrassed.”

Gluten-free products are one of the hottest trends in the food industry, and General Mills is counting on them to help revive stagnant cereal sales. But making the nation’s largest cereal brand gluten-free is a daunting engineering task.

“In one way, I was surprised about [the recall], and in another way I wasn’t,” said Jon Faubion, a grain science professor at Kansas State University. General Mills “is really committed to this and it has put a lot of time and money into it. But I’m not surprised just given the huge challenge.”

How it happened

The national Cheerios recall occurred after federal food industry regulators and General Mills itself received complaints of illness from people who’d eaten Cheerios labeled as gluten-free. The Food and Drug Administration said that since mid-September, it has gotten 125 reports of “adverse” health effects, mostly gastrointestinal problems. The FDA wasn’t aware of anyone being hospitalized or dying.

People with celiac disease get sick from eating gluten, which can lead to damage in the small intestine. Some other people are gluten-sensitive, and ingesting the protein can cause issues such as bloating and diarrhea.

The FDA, after receiving the complaints, tested 36 samples of Cheerios labeled as gluten-free from different factories and production lots. One of them was above the FDA threshold for a product to be labeled gluten-free.

General Mills said oat flour became contaminated when it was offloaded from bulk railroad cars into trucks in Stockton, about 15 miles south of Lodi. The Lodi plant, which is scheduled to close by year’s end as part of a cost-cutting effort, is one of four General Mills cereal plants making Cheerios.

Normally, rail cars full of flour would go directly to the cereal factory. But train service to the plant — and several nearby factories — was down temporarily due to track maintenance, said Tom Forsythe, General Mills’ vice president of global communications.

Several trucks were used to transfer oat flour, and the company’s investigation is focusing on one of those vehicles. “It had hauled bread flour prior to being used by us,” Forsythe said.

The trucks, operated by an independent contractor, were supposed to be thoroughly cleaned. General Mills’ own flour-handling protocols call for documentation of such cleaning, but Forsythe said the company hasn’t been able to confirm there was a “wash tag” for that particular truck.

Once the gluten-tainted oat flour breached the factory, General Mills still could have caught the problem before it reached grocery stores. But during part of July, when the recalled cereal was produced, the company wasn’t doing daily testing of finished products for gluten. “We stopped [finished product] testing for a period, which turns out to be a mistake,” Forsythe said.

General Mills announced in February that it would make 90 percent of its Cheerios portfolio — original, Honey Nut, Frosted, and Apple Cinnamon and Multi Grain — gluten-free.

Oats don’t contain gluten. But stray grains of wheat, barley and rye inevitably make their way into oats between harvest and the time they end up at a flour mill. Oat farmers often rotate crops with wheat, rye and barley, and traces of last year’s harvest may remain. To harvest and ship oats, farmers might use equipment that’s also been used on wheat crops.

Oats made into Cheerios for the North American market — 1 billion pounds a year — all pass through General Mills’ Fridley mill. The plant produces most of General Mills’ oat flour, too, though some oats cleaned in Fridley are milled at a smaller flour factory in northeast Minneapolis.

The mill’s new seven-story “cleaning house” was completed early this year. “This is the critical point to make sure oat flour is gluten-free,” said Chad Hallowaty, an engineer in General Mills’ Big G cereal division who oversaw the cleaning house project.

The cleaning house is filled with dozens of bulky machines sporting large steel cylinders. As the cylinders roll, grain is sorted by size. Wheat, barley and rye seeds are generally smaller than oats, so they go by the wayside.

The cleaned oats — tested for gluten-bearing grains — then move to the mill, where they’re ground into flour. Samples of finished flour are taken hourly in Fridley and sent to General Mills’ research lab in Golden Valley, where they’re tested for gluten.

The company also is now regularly testing finished cereal from every production lot for gluten-free Cheerios coming from the factories, Forsythe said. Regular finished product testing was initiated before the FDA began receiving illness complaints about gluten-free Cheerios.

General Mills plans to improve finished product testing by localizing it, thus speeding up the process, Forsythe said.

A gluten-free push

General Mills’ gluten-free Cheerios initiative is the largest of its kind among breakfast cereal makers. Next up is another of General Mills’ bestselling cereals — Lucky Charms, which is also made of oats.

But this isn’t the company’s first foray into gluten-free cereal.

Back in 2008, General Mills retooled all of its Chex line except Wheat Chex into gluten-free recipes. Chex is made primarily from corn and rice, grains that aren’t as difficult to work with as oats in excluding gluten-bearing grains.

Gluten-free Chex has been a big success for General Mills. From 2010 through 2014, Chex posted 5.1 percent average annual sales growth, according to a research report by Alexia Howard, a Sanford C. Bernstein stock analyst. Overall cereal sales declined or flatlined during that time.

The gluten-free market has boomed along with a greater awareness of gluten sensitivity. Gluten-free diets have also gained a reputation as way to lose weight or be healthier, though evidence for those benefits is scant.

Overall, about 28 percent of Americans are seeking to avoid gluten in their diets, according to a research note last week from David Palmer, a stock analyst with RBC Capital Markets.

Palmer wrote that Cheerios sales have improved “behind gluten-free news and marketing in the early weeks of the fall.” But with the recall, “we now wonder to what extent the new gluten-free effort may have been set back,” he wrote.

Russo, the Edward Jones stock analyst, said that he thinks consumers will still respond well to gluten-free Cheerios, despite the recall. “It’s not something General Mills can’t overcome. They caught it early,” he said.