In a midnight session, the Senate has voted down the USA Freedom Act, putting one of the legal bedrocks of the NSA's bulk surveillance programs into jeopardy. The Patriot Act is set to expire at the end of the month, and the USA Freedom Act would have extended large portions of the act in modified form. Tonight's failure to arrive at a vote makes it likely that many of those powers will automatically expire, although Senate Majority Leader McConnell (R-KY) scheduled a last-minute session on May 31st for one last shot at passing the bill.
In particular, the USA Freedom Act would have modified the Section 215 of the Patriot Act, a clause that allows the FBI to secretly order the collection of "tangible things" that could help in a national security investigation. Since its passage, Section 215 has been interpreted loosely — and likely illegally — by intelligence agencies. As whistleblower Edward Snowden revealed in 2013, the definition of both "tangible things" and "investigation" was broad enough to let NSA build a large database of American phone records for an ongoing, expansive national security effort.
After the program was discovered, President Obama ordered the NSA to get approval before searching the database, but the phone metadata orders have still been renewed every three months. Government reports have said that there's little evidence the phone records program foiled any terrorist plots, however, and a recent court decision found that it wasn't legal at all by the standards of Section 215.