These last days of autumn were supposed to be cold and gray for Dick Thornburgh.

All the forecasters said so. The weather would turn sour. The bright yellow, red and orange leaves of October would fall, and bury Thornburgh and one of the Republican Party's few hopes of recapturing a major governorship this year.

But the forecasters goofed. The temperatures never turned cold. The leaves didn't bury Dick Thornburgh and his Brooks Brothers suits.

Instead, people here woke up less than two weeks ago and suddenly found that Pennsylvania had a gubernatorial race on its hands, a tough race, as the sportswriters say, down to the wire.

Unlike most things in politics, it's easy to pinpoint precisely when this happened. It was Oct. 26, the day a Gallup Poll was released showing Thornburgh trailing Democrat Peter Flaherty, the former mayor of Pittsburgh, by a razor-thin 49 to 45 per cent among likely voters. This meant that the momentum had swung sharply toward Thornburgh, who had trailed by 32 percent points last June.

From Thornburgh's perspective, it could hardly have come at a better time. Flaherty's quixotic campaign, which had been viewed as having a certain bizarre charm to it, was beginning to fall apart. And newspaper endorsements from around the state were rolling in.

Almost every major newspaper in the state weighed in for Thornburgh, who made his reputation as a U.S. attorney prosecuting corrupt officeholders. Among the newspapers were the Pittsburgh Press and Post-Gazette in Flaherty's and Thornburgh's hometown.

"Dick Thornburgh would be a more imaginative, articulate and compassionate governor, and a Thornburgh administration would stand a better chance of reducing government corruption," the Post-Gazette editiorialized.

Flaherty, meanwhile, was having the kind of problems that politicians have nightmares about. First, his lieutenant governor running mate, Robert P. Casey, stuck his foot in his mouth.

Casey, a high school biology teacher and a political unknown, won the nomination by a fluke: voters mistook him for another Robert P. Casey, a popular former state auditor general. Considering him a liability, the Flaherty camp has kept him on the sidelines.

But in an interview, Casey complained that deaf children didn't deserve special school programs. "Put those kids at the front of the classrooms if they can't hear," he said.

This was like throwing Thornburgh, who has a severely retarded son, a soft pitch. He hit out of the park. "I don't hink this man deserves to hold any office," he said.

Flaherty also began getting caught in a series of embarrassing situations. A week after he indignantly charged into the office of Rep. Joshua Eilberg (D-Pa.), who was about to be indicted on a conflict of interest charge, and demanded that Eilberg remove Flaherty's name from his campaign literature, the Democratic nominee slipped away from reporters to attend a dinner with Rep. Daniel J. Flood, another Pennsylvania Democrat also under indictment.

This leads to a far more serious problem for Flaherty: his uneasy relationship with fellow Democrats. Flaherty, a maverick loner, has tried to disassociate himself from the scandal-ridden Democratic administration in Harrisburg, refusing, for example, to attend its major fund-raising event of the year, featuring Vice President Mondale. He also beat Thornburgh to the punch in denouncing Philadelphia Mayor Frank Rizzo's attempt to amend the city's charter to enable him to run for a third term.

But now, Flaherty needs the very people he has run away from all year to win the election. He'll probably get their help, which may provide him a victory margin.

"He'll get our support, but he hasn't earned it," Rizzo said the other day.

Meanwhile, Thornburgh is riding high. "I'm able to look you in the eyes and for the first time in 18 months tell you we're winning," he said here the other day.