A federal judge made a ruling this week that could force tens of thousands of foreign workers, many of whom are employed at tech companies on student visas, to return to their home countries early next year.

This ruling, released Wednesday by U.S. District Court Judge Ellen Huvelle in Washington, found that the government erred by not seeking public comment when it extended the 12-month Optional Practical Training (OPT) program to 29 months for STEM (science, technology, engineering and math) students. The OPT program allows someone to work on a student visa.

Huvelle could have invalidated the OPT extension immediately but instead gave the government six months, or until Feb. 12, 2016, to submit the OPT extension rule "for proper notice and comment."

Ian Macdonald, an immigration attorney at Greenberg Traurig, said that if the U.S. Department of Homeland Security (DHS), which overseas immigration, doesn't act to fix the problem before the court's Feb. 12 expiration, the OPT extensions "will be terminated with immediate effect and (the visa holders) will have 60 days to pack up their belongings."

DHS officials did not respond by deadline to a request for comment.

The U.S. extended the OPT program in 2008 to give STEM students more time to secure H-1B visas. The government's argument was that demand for the H-1B visa was so high that it was forced to distribute the visa by way of a lottery. This meant that if someone on a student visa failed to win a temporary work visa in the lottery, the student could be forced to leave the U.S. By extending the OPT program, student visa holders could remain in the U.S. while they tried again to gain an H-1B visa or some other means to remain in the U.S.

Critics, meanwhile, assailed the OPT extension as "a back-door H-1B increase."

The government's mistake, according to this week's court ruling, was in adopting the extension as an "emergency," and in doing so, it bypassed its own public comment and notice requirements. Huvelle said that there was nothing that made the OPT extension "suddenly urgent."

John Miano, the attorney representing the Washington Alliance of Technology Workers, which brought the lawsuit, said the ruling is a "big victory for labor" that "cuts off the back door of using administrative action to bypass Congress."

"American workers and the public at large were given no notice that the regulations were even being considered until DHS dropped them fait accompli without notice and comment," said Miano, a programmer who founded the Programmers Guild and later became a lawyer.

The OPT program has proved to be increasingly popular. In 2008, the year the extension was adopted, the U.S. approved 28,500 OPT applications. In 2013, it approved 123,000.

The court's timeline for fixing the OPT program is going to be "very challenging," Macdonald said, because of various government 30 and 60-day notice periods. "I think everyone is getting ready for DHS to push this rule within the six-month period," he said.

There could be political problems as well. By restarting the regulatory approval process, Macdonald said that new challenges will emerge in Congress, as well as in the courts.

Political fallout seems possible. One GOP aide for a Senate Judiciary Committee office, who wasn't authorized to speak and could only comment anonymously, said in response to the court ruling: "The Administration's abuse of the OPT program is extraordinary. American workers are paying the price daily."

It was the administration of President George W. Bush that pushed through the OPT extension. President Barack Obama's administration supported it, and has extended the definition to STEM to include a broader range of college degrees.