One by one, U.S. Magistrate Judge William Gallo called the names of 14 defendants who were charged with entering the country illegally. Defense attorneys told him the government had already deported them to Mexico, making it impossible for them to appear.

In a rebuke to the government, the judge immediately dismissed all charges and ordered that their bond money be returned.

The scene played out every day for several weeks in San Diego another example of judges challenging President Donald Trump's moves on immigration in ways large and small. Last month, a different judge halted an administration policy to deny asylum to people who enter the country illegally.

Federal prosecutors introduced the mass hearings on immigration charges in California in July, adopting a model that has been in place for years elsewhere on the U.S.-Mexico border. The hearings soon began running past 6 p.m. regularly.

Defense attorneys frequently objected that they didn't have enough time to consult with their clients, who appeared in the same clothes they wore crossing the border a day or so earlier.

Then, on Sept. 17, Gallo announced that judges would no longer accept guilty pleas at initial appearances, as they do in Arizona and Texas. Instead, they began setting second hearings for five days later. Immigrants who posted bail before their return dates were deported.

'The government, in many respects, was duplicitous,' Gallo said on a recent Friday, referring to the decision to deport defendants before they could return to court for resolution of their cases.

On the same day, Gallo dismissed charges against the 14 defendants, many of them Mexican men who were caught hiding amid boulders and thick brush in rugged mountains east of San Diego.

The administration countered on Oct. 9, saying it would not deport people until their criminal cases were completed. That stopped cases from being dismissed but introduced new problems: Keeping people in custody for longer periods strained detention space and imposed higher costs.

'They wanted it to be a one-day thing, like it is across the whole border, because it's cheaper,' said Jami Ferrara, who represents defense attorneys on a panel with judges and prosecutors working on the changes. 'It's not a cheap system.'

It is unclear how many cases were dismissed in San Diego, but defense attorneys estimate it was hundreds.

While dismissing the cases did not free people in the U.S., it undermined the purpose of Trump's 'zero tolerance' illegal immigration policy: to notch criminal convictions. First-time offenders are punished by up to six months in prison and can be charged with a felony if caught again.

The legal skirmishes in San Diego court have not drawn a public reaction from Trump, and the Justice Department and Customs and Border Protection agency declined to comment.

It costs the Marshals Service an average of almost $90 a day to house a defendant. In San Diego, space is at a premium, with room for only 815 people at the main holding facility.

To address any space limitations, the Marshals Service has agreements with state and local governments and the federal Bureau of Prisons, as well as contracts with private companies, spokesman Drew Wade said.

Defendants received a lift from The Bail Project, a nonprofit group launched in January that has established revolving bail funds in San Diego and six other cities across the U.S. Robin Steinberg, its chief executive, said the group came to San Diego on Aug. 20 and provided bail to 700 immigrants in its first seven weeks.

The Bail Project has yet to expand to other border courts that hold mass hearings for illegal entry.

'Our current focus is to assist as many people as we can in San Diego,' Steinberg said.

For now, many defendants are unable to make because some judges insist they be released to 'a third-party custodian' in California, often a relative who is responsible for making sure they return to court. But some family members may be reluctant to come forward if they are in the country illegally, and many live far from San Diego.

Defense attorneys have objected to the requirement.

'It is extremely unusual for courts to require a third-party custodian in misdemeanor cases,' said David Loy, legal director for the ACLU of San Diego and Imperial counties. 'These are basically federal petty offenses at the lowest level.'

Mass hearings on immigration charges were introduced in Del Rio, Texas, in 2005 and spread within a few years to other federal courts on the border except California. Courtrooms in Tucson, Arizona, and McAllen, Texas, filled with about 70 people a day who pleaded guilty at their first appearance and were typically sentenced to time already served.

The administration said in May that it would prosecute every illegal entry under zero tolerance. But after a backlash over widespread separation of families, officials retreated in June by generally exempting adults who come with their children. Days later, a federal judge ruled against separating families.

In San Diego, each defense attorney is assigned no more than four clients a day and, on most days there are only 10 attorneys, resulting in a cap of 40.

Fred Sheppard, an assistant U.S. attorney, recently said in court that the Border Patrol arrests 90 to 140 people a day in San Diego, implying that many are not prosecuted. (The administration says there has been a 'slight uptick' in families crossing illegally and turning themselves in since a large caravan of Central American migrants reached Tijuana, Mexico, last month.)

The prosecutor spoke as the government presented 43 people for prosecution, three over that day's cap. Three men entered the jury box and were told by Gallo that their cases were being dismissed because they had not had a chance to speak with an attorney.