The USA Patriot Act has been at the nexus of the debate over privacy and civil liberties since it was passed in the wake of the Sept. 11, 2001, terrorist attacks. But a looming legislative deadline, a recent court ruling against a controversial program that collects the details of millions of Americans' phone calls and a filibuster threat mean that the government's spying abilities face an uncertain future.

The National Security Agency's domestic phone records program -- which collects information about the times, lengths and what numbers are associated with calls, but not their content -- is authorized by a part of the Patriot Act known as Section 215. But Section 215 is set to expire June 1, and last week, a federal appeals court ruled that the phone records program is illegal under that law, ruling that it stretched the definition of what information was relevant to an investigation to "unprecedented and unwarranted" lengths.

The court declined to place an injunction to halt the program. "In light of the asserted national security interests at stake, we deem it prudent to pause to allow an opportunity for debate in Congress that may (or may not) profoundly alter the legal landscape,” U.S. Court of Appeals Second Circuit Judge Gerard E. Lynch wrote.

But the court's decision raised the stakes on Capitol Hill, where Senate Majority leader Mitch McConnell (R-Ky.) is advocating for an extension of Section 215 through 2020.  But that would likely push the issue to the Supreme Court to settle.

On the other side of the debate, long-time government surveillance critic Sen. Ron Wyden (D-Ore.) threatened in an interview with MSNBC to filibuster a short-term extension of the law "unless there are major reforms like getting rid of this bulk phone record collections."

Wyden is a supporter of the USA Freedom Act, a compromise bill that supporters say would effectively end the government's bulk collection of phone records by requiring the agency to request information from service providers instead of maintaining its own database.

But the bill, which would extend the altered version of Section 215 through 2019, has split privacy advocates.  Some groups argue that the legislation  might impede the progress being made in court challenges of surveillance programs or more comprehensive legislative reform efforts.

The deciding factor, more than anything at this point, may be time.

While the official deadline for Section 215 is June 1, Congress has a recess scheduled for the last week of May -- meaning the effective deadline is more like May 22.

The House Judiciary Committee has passed a version of the USA Freedom legislation and the bill is scheduled for a floor vote this week -- which it is expected to pass. The real action is likely to be in the other chamber.

"Start popping your popcorn and find a comfy chair, because it looks to be a dramatic couple of weeks in the Senate," said Kevin Bankston, the policy director at New America's Open Technology Institute and a supporter of the bill. "There’s no way there are 60 votes in the Senate for a clean [Section 215] reauthorization, and the clock is running down fast."

And the intelligence community is likely unwilling to risk a straight up sunset of Section 215, especially in light of the court ruling -- which could have broad implications for reducing other authorities that could be used to continue the phone records program. "Allowing it to expire entirely because of a disagreement over the NSA program would be a disaster — the most feckless and irresponsible choice that Congress could make," Stewart Baker, a former NSA general counsel and a partner at Steptoe & Johnson, told The Post.

The court ruling and the looming deadline could help give USA Freedom a boost: "Congress is hurdling towards this moment where they have fewer and fewer options that are realistically on the table before 215 sunsets," said Harley Geiger, a proponent of the legislation and the advocacy director and senior counsel at the Center for Democracy & Technology.

But for now, the future of government spying remains in flux. "You'll be seeing this play out in Congress for the next few weeks," Adm. Michael Rogers, director of the NSA, said during comments at George Washington University on Monday. "In the end, the National Security Agency executes a legal framework that is set out by Congress and tested by our courts."