SAN FRANCISCO -- By American standards, the departure of Soviet President Mikhail Gorbachev was, well, a bit messy. The send-off crowd, whipped by winds that seemed to be coming straight across the Bering Strait from Siberia, stood in a shivering cluster by the stairway to the aircraft. The sounds of "I Left My Heart in San Francisco," sung in Russian by a local choral group, were lost in the roar of the Aeroflot's engines.

A Secret Service agent, who may be wondering whether to consider another line of work, tried to shove President Bush's senior adviser on Soviet affairs, Condoleezza Rice, into a pen for lesser VIPs. The Soviet baggage handlers misplaced one important suitcase, that of Alexander A. Bessmertnykh, Soviet ambassador to the United States.

But even with some of the ragged edges and a few protocol glitches, when Gorbachev and his wife, Raisa, stood at the top of the aircraft's stairs and waved their goodbye to San Francisco, the Soviets seemed downright happy. One U.S. official reported that even the stone-faced head of the KGB unit guarding his president seemed to smile as he boarded the plane for home, but this could not be confirmed.

"It fell apart here a little at the end," acknowledged one U.S. official working on trip details. "But I think the Soviets had a good trip."

Once the Gorbachevs left Washington, their tour of the United States was in a kind of governmental twilight zone. Bush sent along Joseph V. Reed Jr., his chief of protocol, and about 20 other Americans to ease the way. But the Americans, including State Department advisers and seasoned advance agents, were not in control of the trip. Instead of telling people what to do, they had to make suggestions.

"It's a little awkward," said one of those aboard the protocol plane working for Reed. "We have to exercise a lot of diplomacy."

For Reed, an energetic man who seemed to be earning the informal title of "great facilitator" as he directed an orchestra of cars, officials and crowds, the entire exercise was not so much a nightmare as an adventure, it seemed.

"We're making protocol history," he declared the moment the State Department airplane left Andrews Air Force Base on Sunday ahead of Gorbachev's Ilyushin-62. Usually officials from the host country wave goodbye from the tarmac as the head of state departs first.

The switch, Reed explained, came because this was no longer a state visit in the ordinary sense. Reed also noted that Bush wanted Reed and other Americans on the ground to help with the welcoming of the Gorbachevs in Minneapolis and San Francisco.

The U.S. team's other job was to tidy up protocol details, of course. The Soviets had started by using two small Soviet flags on their limousines. They were reminded by protocol experts that it was a one-flag visit outside of Washington.

More important in the heavily symbolic etiquette exercised between superpowers, the U.S. and Soviet flags were in the wrong spots -- twice, in California. Californians had decided that the Soviet flag should be fixed at the right of podium and the U.S. flag on the left. A definite no-no, Reed explained, but he changed the flag positions only once -- when Gorbachev gave what was described as a major political address at Stanford University.

Later, at a meeting with business leaders in the Fairmont Hotel in San Francisco, Reed said he did not have the heart to reposition flags in mid-proceeding, thereby mortifying the San Francisco woman in charge of such details.

But would it have been such a scandal? Reed was asked by reporters on the protocol plane.

"What? Oh, yes," he said, waving a long arm at a group of Soviet and American officials nearby. "They all noticed." Also, as an official serving this particular president, Reed certainly would have heard about it if the American flag was out of position for any major event.

The U.S. coterie was supposed to guide the Soviets away from hazardous political territory, but a luncheon given by Minnesota Gov. Rudy Perpich turned out to be a quagmire that the Soviets waded into innocently.

Perpich, a Democrat, had set up a three-star luncheon with the Gorbachevs. Invited were the rich and powerful -- "the Rockefellers of Minnesota," as one U.S. official put it. The problem, it seemed, was that Perpich had shunted the congressional delegation elsewhere, including the state's two Republican senators, Rudy Boschwitz and David Durenburger.

Thus, Perpich presided at the governor's mansion over what even protocol veteran Reed called a "world-class" lunch. For example, one sauce contained morel mushrooms that grow only on dead elm trees and were plucked personally from their hiding place by the chef himself, Reed reported. Also, the centerpiece of each table included a rare lady's slipper, a protected species. Perpich had to issue a special proclamation to have them picked, Reed said.

But next door, for the second string, there was a modest buffet that seemed only more fodder for a feud between Perpich and the Republicans. Boschwitz and Durenburger looked a little stricken as they waited a house away from the action, and other Minnesota politicians seemed merely disappointed until U.S. and Soviet officials hastily arranged a meeting on the governor's front lawn so the Gorbachevs at least could shake every hand.

For protocol chief Reed, this trip meant something of a rapprochement with an old enemy, former secretary of state George P. Shultz. In 1988, when Reed was undersecretary general for political affairs at the United Nations, he agreed to allow Yasser Arafat into New York to speak at the United Nations. But Shultz refused to give Arafat a visa.

So Reed took most of the United Nations to Geneva for the session addressed by Arafat, with the United States paying its usual share, and he wrote a letter to President Reagan explaining his point of view. The next time Reed saw Shultz, the secretary refused to shake his outstretched hand.

Reed admitted to being stunned and hurt by Shultz's snubbing and a tad nervous about the encounter with Shultz on the Gorbachev trip, even though he said Bush had predicted that Shultz would have put the incident behind him.

Indeed, a tanned and healthy-looking Shultz stopped Reed when they met at Stanford, shook his hand and praised his work as head of protocol.

"That page is now over," Reed said with a sigh of relief. "President Bush was right."

For the Gorbachevs, much of the trip seemed like a movie set, Americans were told by some Soviets. At Stanford University, the Gorbachevs worked a huge, mostly blond, tan California crowd, shaking hands with students and smiling for a sea of expensive-looking automatic cameras that were raised skyward and aimed in their general direction.

Once, the Soviet leader stopped and shook hands with a girl who looked Asian. He said to her, "Where are you from?"

"Philadelphia," she answered. Gorbachev looked a little puzzled, and then moved on.

As Gorbachev's motorcade drove from Stanford to San Francisco, it passed by California mansions and some of the state's most beautiful horse country. At one point, a powerful stallion could be seen standing on top of a hill, looking like something out of a John Wayne movie.

"I had a very hard time carrying him up there," said one U.S. official as the motorcade swept past.