It is the rarest of moments: President Bush and House Speaker Nancy Pelosi are on a collision course over a giant farm bill, but it is Bush who is broadly aligned with liberal Bay Area activists pushing for reform, while the San Francisco Democrat is protecting billions of dollars in subsidies to the richest farmers.

A conference committee approved on Thursday most of a nearly $300 billion farm bill that will lock in the nation's food policy and environmental stewardship on millions of acres of private land for the next five years. Hoping to survive a veto, lawmakers doled out money to everyone from thoroughbred racehorse owners to food-stamp recipients.

The package melds last year's House and Senate farm bills for votes in both chambers before going to the White House. Several controversies remain to be worked out this week. The administration threatened a veto, with Bush deriding a "massive, bloated" effort.

Lawmakers are betting that Bush will not dare kill a $10.3 billion increase in nutrition spending such as food stamps, which make up the bulk of the bill, or anger farm-state Republicans in an election year. If he does, they plan to override him.

Congress has its bases covered. Each interest group represented in the sprawling legislation - from tiny Santa Cruz organic vegetable growers to Georgia cotton magnates, from conservationists to prairie-plowers - gets enough money that it would prefer this bill rather than start over with a new president.

Farm bills come around just once every five years and usually fly under the radar of most lawmakers and the public, making it easy for Congress to tout the bills as aid to family farmers. The commodity supports - born as temporary economic aids in the 1930s - are mind-numbingly complicated and get little notice outside the farm press, despite their enormous impact on U.S. food policy. Urban lawmakers are normally happy to vote for crop subsidies in exchange for food-stamp votes from rural lawmakers. It is textbook political logrolling.

This year looked different. The local-food movement, concentrated in the Bay Area, increased attention on subsidy-driven distortions that supercharge the industrialization of agriculture, boost corn-based sugars, fats and starches in the U.S. diet and undermine poor farmers overseas.

California, the nation's farming giant, stepped into the bargaining. Produce growers, left out of crop subsidies since the 1930s, demanded marketing aid. Long-neglected organic growers were desperate for research help. Public health advocates wanted healthier school lunches. Environmentalists saw millions of acres of private land ripe for conservation and improved farming practices to reduce water and air pollution.

These groups allied with budget hawks to try to shift aid from commodities to healthier food and more sustainable farming.

The administration proposed a farm bill two years ago that would have cut off payments to wealthy farmers, modernized subsidies, and moved money to nutrition and environmental programs. When former Agriculture Secretary Mike Johanns told groups the administration's plans, "They didn't believe it," said Department of Agriculture spokesman Keith Williams. "He'd get jeers, and he'd say, 'No, it's in here.' "

Pelosi threw her weight behind farm-state Democrats, pushing a bill through the House last summer that protected subsidies, and ostensibly, the newly elected Democrats from rural districts.

"We've wondered if we weren't living in a parallel universe," said Ken Cook, president of Environmental Working Group. "The president has been to the left of the speaker."

Instead of cutting subsidies, Congress increased spending, raised taxes and engaged in budget acrobatics to make everything appear to fit.

As the commodities boom accelerated over the winter, boosting farm income to new records, the disconnect between the farm bill and economic reality grew more bizarre. Food riots broke out in Egypt, Haiti and other countries where the poor spend much of their earnings on food. At home, food inflation hit 4.4 percent, squeezing consumers already pinched by fuel prices.

The bill would spend about $5 billion a year on automatic payments, mostly to farmers of five crops - corn, wheat, cotton, rice and soybeans - giving two-thirds of the money to the top 10 percent of growers. Embarrassed by the spectacle, some farm-state lawmakers pushed for payment limits, fearing a loss of public support for farm aid.

Pelosi touted a ban on payments to farm couples earning more than $2 million, 10 times higher than Bush's $200,000 income limit.

At the same time, she backed a 50 percent increase in the actual amount of money each farmer could get. The Senate added a new $3.8 billion "permanent disaster" program to bail out farmers of drought-prone land, intensifying the push to plow fragile prairie.

"This is not even the illusion of reform," said Rep. Ron Kind, a Wisconsin Democrat who intends to fight a $1.7 billion cut in money added by the House for conservation. "Not when you dole out $50 billion in direct payments over 10 years that bear no relation to market prices or production. ... The president is right."

Ferd Hoefner, policy director of the Sustainable Agriculture Coalition, called the administration's proposals a mixed bag, saying administration officials "sit in the room with an incredible amount of leverage and don't negotiate."

To avoid a Bush veto, negotiators devised a complicated scheme to limit payments to extremely wealthy landowners. Hoefner calculated that married couples would have to earn $2.9 million to lose their federal checks.

"It's remarkable that anyone could call this reform with a straight face," Hassebrook said.

To secure votes, negotiators added a $93 million write-off for thoroughbred racehorses at the behest of Senate Republican leader Mitch McConnell of Kentucky, and Arkansas Democratic Sen. Blanche Lincoln. That is nearly as much money as organic farmers will get for research, data collection and certification help for small growers.

The organic money is "a very significant step, but it is very far away from a fair share" given the gains organic food has made in the market, said Mark Lipson, policy program director for the Organic Farming Research Foundation in Santa Cruz. Still, he prefers the bill to pass for fear of losing this money.

"It's just transactional politics at its worst," said Rep. Jeff Flake, a maverick Arizona Republican who plans to attack the bill on the House floor.

Pelosi threatened to blast Bush for killing the food-stamp increase if he vetoes the bill, issuing a statement urging Bush to sign the legislation to "ensure that 38 million Americans - especially children - have improved access to basic nutrition."

Adding to the likelihood that Congress could find the votes to override a veto: California fruit and vegetable growers would be furious if a veto kills their first-ever funding. Conservation groups fear losing $4 billion in new funding for environmental programs, even though that figure was cut back to make way for the disaster program.

Farm-state Republicans met with Bush to pressure him to sign the bill. "We need him to understand that this is good policy," said Sen. Saxby Chambliss, R-Ga.

Democratic presidential contenders Sens. Barack Obama of Illinois and Hillary Rodham Clinton of New York supported the farm bill last year. Likely GOP nominee Sen. John McCain of Arizona backed a failed effort at a radical overhaul and told Iowans last week that if he were president he would veto the bill, calling crop subsidies unnecessary.

For a list of senators and representatives serving on the conference committee, go to links.sfgate.com/ZDGB