How borders are drawn and enforced has far-reaching consequences, whether we live on either side of them or halfway across the world.

American consumers are particularly interested in sugar this week: Halloween is tomorrow, which means people are debating how much to spend on handouts for trick-or-treaters, how to ration servings of candy for their own kids, and whether Snickers bars are “healthier” than Reese’s Peanut Butter Cups. In any case, they’re buying candy.

One supposes, then, that US candy makers would find this time of year pretty sweet. If only they weren’t so stressed about the high cost of sugar—a perpetual problem for American food and drink manufacturers that’s been exacerbated in recent months by a trade spat with Mexico.

US sugar prices are always higher than world prices. In the winter of 2013-2014, though, the prices edged too close to each other for the American Sugar Alliance’s comfort.

The American sugar industry is highly protected, with strict quotas and tariffs on imports of the stuff—except for supplies from Mexico, for reasons we’ll get to shortly. The protections have kept domestic sugar prices higher than world prices.

The American Sugar Alliance, which represents growers, harvesters, and refiners of sugar cane and sugar beet in the US, wants to keep things that way. That’s why, in March, the ASA accused the Mexican government of subsidizing its own sugar industry and flooding the US market with cheap cane sugar—prompting the US government to impose tariffs on Mexican sugar imports.

As the effects of the import duties worked their way into the market, US sugar prices started pulling away again from world prices.

US sugar prices crept up and away from world prices over the summer, partly in anticipation of anti-subsidy and anti-dumping tariffs (on Mexico’s sugar exports to the US), which were handed down in August and October.

American food and beverage companies, represented by the Sweetener Users Association, were not pleased. Last week—before the US and Mexico reached a truce, of sorts, regarding how much sugar Mexico could export to the US and at what prices—the SUA claimed that the trade war would end up costing food manufacturers $2.4 billion in 2014-2015.

Though consumers presumably would prefer to pay less for Halloween candy (and everything else we eat that has added sugar) this issue really is between the sugar producers and the big food and beverage companies, like Mondelez International and Hershey, which bear the brunt of the inflated costs.

The US and Mexico are the world’s 5th and 6th biggest producers of sugar.

The whole affair has been a rare moment of discord in the US-Mexico sweetener trade under the North American Free Trade Agreement. Aside from a late 1990s dispute over US high-fructose corn syrup exports, it’s been a rather uneventful history—but not the one that was expected to play out.

The NAFTA provisions of 1994 were designed to gradually give Mexico liberal access to the US sugar market. When the last of the sugar trade restrictions were lifted in 2008, the US hadn’t anticipated that Mexico would ever become a major sugar supplier, but thanks to a combination of factors between 2009 and 2012, that’s what happened. One of the more interesting trends fueling the imports: as consumption of US-supplied high-fructose corn syrup increased in Mexico, sugar consumption there decreased, which meant more Mexican sugar was sent to the US.