With an all-but-certain recount looming in their primary contest, Republican Senate candidates Mehmet Oz and David McCormick have opened a new front in their battle over every ballot: the courts.

McCormick filed a lawsuit Monday in Pennsylvania’s Commonwealth Court seeking to compel all of the state’s counties to count ballots that were received on time but were missing a handwritten date on their envelope — a defect would previously have led to them being rejected under state law. He based that request on a ruling in an unrelated case issued before the U.S. Court of Appeals for the Third Circuit, which found last week that the date — or lack of one — on the ballot envelope was irrelevant to the vote’s legitimacy.

Meanwhile, the law firm that lost that before the Third Circuit on behalf of a GOP candidate for judge in Lehigh County pushed back. It told the Third Circuit’s judges Monday that it intended to challenge its decision at the U.S. Supreme Court — a move that could help the Oz camp. The law firm has also been representing the Oz campaign.

The legal wrangling, before two different courts, injected a new level of uncertainty into the contest as county elections boards scrambled to figure out what to do with undated mail ballots across the state while the Oz and McCormick campaigns urge them in opposite directions. The number of such ballots is not known.

Oz and McCormick were separated by fewer than 1,000 votes Monday afternoon — well within recount territory under state law. McCormick, who has been trailing in the vote count, has pushed to count as many votes as possible and sees every additional vote as an opportunity to help close the gap. He’s also done better with mail ballots than Oz has.

The undated mail “ballots were indisputably submitted on time — they were date-stamped upon receipt — and no fraud or irregularity has been alleged,” McCormick’s lawyers, Ronald L. Hicks and Charles J. Cooper, wrote in their suit Monday. “The … only basis for disenfranchising these voters is a technical error that is immaterial under both state and federal law.”

» READ MORE: What’s happening in Pennsylvania’s Republican Senate primary before a likely recount

State law requires voters to sign and date the outside mailing envelope when they return their ballots, and state courts had held that the requirement means undated ballots must be rejected.

But on Friday, a three-judge panel at the Third Circuit disagreed in a case centered on last November’s general election and 257 mail ballots in Lehigh County. Republican David Ritter appeared to win a county judicial seat by 74 votes, but counting the undated mail ballots could give Democratic candidate Zachary Cohen the win.

The circuit judges found that the date isn’t used in determining the legitimacy of vote. After all, they noted, the county had accepted ballots with the wrong dates on them, as long as they were dated at all. They ordered the county election board to count the undated ballots

Oz and McCormick immediately seized upon the decision.

Less than 90 minutes after the appeals court ruling Friday, a lawyer for McCormick sent an email to all 67 counties, attaching the order and asking them to count the undated mail ballots.

”We trust that in light of the Third Circuit’s judgment you will advise your respective boards to count any and all absentee or mail-in ballots that were timely received but were set aside/not counted simply because those ballots lacked a voter-provided date on the outside of the envelope,” wrote Hicks, McCormick’s attorney. “To the extent you are not willing to provide this advice, we ask for a formal hearing before your boards on this issue.”

The Oz campaign fired back Saturday night, with a lawyer sending a similar email to the counties — but in the opposite direction.

“The order … does not authorize election officials to ignore Pennsylvania law or to count mail-in or absentee ballots lacking a voter completed date in the May 2022 primary election,” wrote lawyer Britain R. Henry. “In the first place, that judgment is not final and is subject to further review.”

» READ MORE: The Oz and McCormick campaigns are already fighting over undated Pa. mail ballots as Senate primary recount looms

In its lawsuit Monday, McCormick’s campaign said that the majority of Pennsylvania’s counties had indicated they won’t count the undated ballots. It asked the Commonwealth Court to define a uniform standard.

Meanwhile, lawyers at Kleinbard LLC, which represent Ritter, asked the Third Circuit to stay the implementation of its order in the Lehigh County case, saying the Supreme Court should be allowed to weigh in before the undated ballots are counted in that 2021 race.

Joshua Voss added that should the Third Circuit deny Ritter a stay, they would seek one from the Supreme Court directly. A successful appeal in Ritter’s case would benefit the firm’s other client, Oz, and his position on undated ballots to be thrown out in his race.

“Absent a stay, Ritter’s opponent could wrongly assume office, and Pennsylvanians will be subject to the power of an official who was seated in error,” Voss wrote. “Ritter asks the Court not to preemptively cut off his right to further review.”

The Pennsylvania Department of State was poised to issue guidance to counties Monday on how the Third Circuit’s ruling in Ritter’s case should apply to this year’s vote count and the Oz-McCormick race.

But a stay in the Ritter case could further muddle the question — as it did in the 2020 presidential election, when Supreme Court intervention left about 10,000 challenged mail ballots in limbo for weeks after the vote was certified.

In that case, Samuel A. Alito Jr. — the Supreme Court justice who oversees matters for the court in Pennsylvania, New Jersey, and Delaware — ordered Pennsylvania counties not to include mail ballots that arrived during a three-day grace period after Election Day in their official tallies until the court could decide whether it would take up a challenge to their legitimacy.

The court ultimately declined to hear the case but made that decision well after state election officials were forced to certify the state’s results without them because of the stay. The votes at issue wouldn’t have changed the outcome of President Joe Biden’s victory in the state but also were never included in the certified vote.

In the current election, the margins between Oz and McCormick are so narrow that the fate of the undated ballots could play a role in determining the winner as they fight over every possible vote.

Read McCormick’s lawsuit before the Pennsylvania Commonwealth Court:

Read Ritter’s request to stay the Third Circuit decision on undated mail ballots in Lehigh County: