House Speaker Paul D. Ryan (R-Wis.) on Thursday headed to vote on the federal budget at the U.S. Capitol. (Shawn Thew/EPA-EFE/REX/Shutterstock)

Teachers, social workers and other public servants at risk of missing out on federal student loan forgiveness because they enrolled in the wrong repayment plan now have a shot at debt relief under the spending bill signed into law Friday.

The sweeping $1.3 trillion bill includes a measure that temporarily expands Public Service Loan Forgiveness, a program that cancels federal student debt after 10 years of on-time payments for people who take jobs in the public sector.

The program requires borrowers to be enrolled in specific repayment plans, primarily those that cap monthly loan payments to a percentage of a borrower’s income. But some people have complained about loan servicing companies failing to provide consistent and clear guidance, leading them to believe they were making qualifying payments when they were not.

Now, those borrowers could apply to have their ineligible payments counted toward loan forgiveness. But there’s a twist: Their most recent monthly payment and the one made a year before applying for forgiveness must be as much as they would have paid in a correct plan.

Congress has created a $350 million fund to cover the cost of canceling more loans, but once the money runs out, so will the offer. Forgiveness under this measure is being offered on a first-come, first-served basis. The U.S. Department of Education must reach out to borrowers and develop a simple way for them to apply, according to the budget bill.

The measure is based on a bill introduced by Sens. Sheldon Whitehouse (D-R.I.) and Tim Kaine (D-Va.) in November that would have provided relief to all borrowers who qualified. Reps. Brendan Boyle (D-Pa.), Ryan Costello (R-Pa.), John Sarbanes (D-Md.) and Brian Fitzpatrick (R-Pa.) sponsored the companion legislation in the House. Their measure failed to advance earlier, but was revived during budget negotiations.

“Americans who honorably serve our communities have earned much-deserved relief from crushing student loan debt in return for their time and commitment,” Kaine said in a statement. “But unfortunately because of confusion around a provision in the program, we were at risk of breaking that promise to Virginia teachers, social workers, nurses and military service members.”

Problems in the loan forgiveness program were documented in a scathing report released in June by the Consumer Financial Protection Bureau. The watchdog agency said flawed payment processing, botched paperwork and inaccurate information from FedLoan Servicing, the company handling the program for the government, had derailed hundreds of public-sector workers from receiving loan forgiveness.

Borrowers told the consumer bureau they were placed in ineligible payment plans even after identifying themselves as public servants, a misstep that delayed their ability to obtain loan forgiveness. Others said they were never told that payments made before enrolling in a qualifying repayment plan would not count toward forgiveness. In some instances, borrowers said the servicing company provided an inaccurate count of their qualified payments and gave them a hard time as they fought to have the error corrected.

The administration of President George W. Bush introduced the loan forgiveness program in 2007 to encourage college graduates to pursue careers as teachers, social workers, public defenders or rural doctors — public service fields that traditionally pay relatively low wages.

The program has been criticized as a backdoor subsidy for graduate school. It has also received flak for helping doctors and lawyers who have the earning potential to repay their student loans. The Trump administration has proposed eliminating it, as have House Republicans in their higher education bill.

“Congress created this program so bright, talented people could use their college education for public service,” Whitehouse said in a statement. “There’s more to do, but I’m proud that a version of our legislation will help public servants continue their important work.”