Sonja Farak, a state forensic chemist in western Massachusetts, was minutes away from testifying in a drug case in early 2013 when attorneys learned she was about to be arrested on charges of tampering with evidence and stealing drugs from her workplace. Prosecutors stopped her from taking the stand, and the case was dismissed.

Thanks to that quick thinking, one fewer case was tainted by Ms. Farak’s misconduct, which she pleaded guilty to in January 2014. When she was sentenced to 18 months in prison, Superior Court Judge Mary-Lou Rup expressed her dismay at the damage the chemist’s conduct may have done to “dozens, hundreds” of other cases where she did testify.

But the scope of the damage may be in the tens of thousands, not the hundreds, according to newly public documents.

For some experts, this development in the Farak case is just the latest illustration of flaws in America’s forensic laboratories, embarrassing state prosecutors and haunting drug convicts. Critics of the labs have called for significant “upstream changes” to the process.

“The longer you ignore the problem, the greater the problem becomes, and that’s what [lab] administrators nationally must learn,” says Steven D. Benjamin, a defense attorney and partner at the law firm Benjamin & DesPortes in Richmond, Va.

But drug labs can take concrete steps to minimize the frequency and scale of scandals, Mr. Benjamin says. Administrators of such labs must not only increase oversight, he says, but also make it easier for lab employees to report possible errors in their work or in a colleague’s.

“Too many labs across the country are too fearful of acknowledging error,” he says. “They act as if they don’t want to hear that mistakes are being made.”

He adds, “Too many forensic laboratories regard themselves as law enforcement agencies or an arm of the prosecution.”

Farak’s arrest came as Massachusetts was already reeling from a similar scandal at another state drug lab, this one in Boston. Chemist Annie Dookhan was discovered to have committed widespread misconduct affecting as many as 40,000 drug cases. She pleaded guilty in 2013 and was sentenced to three to five years in prison.

The Massachusetts inspector general concluded a review of the Dookhan case in 2014, finding among other things that Ms. Dookhan was the sole bad actor at the lab and that management failures contributed to her ability to tamper with drug samples. There are two ongoing state investigations into the Farak scandal.

Among the lessons prosecutors can learn from Farak’s misconduct: Crime labs should be held to the same rigorous accountability that is expected of law enforcement agencies when they deal with controlled substances, says David LaBahn, president and CEO of the Association of Prosecuting Attorneys in Washington, D.C. Narcotics officers, he notes, go through deep background checks, studies of their lifestyle habits, and regular drug testing.

“Crime labs should look more like [a] law enforcement agency, in the sense that there should be stronger background done on folks doing the analysis and those folks should be regularly tested,” Mr. LaBahn says.

Farak was charged in only two cases at first – involving the theft of two samples and their replacement with counterfeit substances. Then-Massachusetts Attorney General Martha Coakley said that no suspects’ due process rights were violated and that the contraband stolen was “a small amount,” The Boston Globe reported at the time.

But the newly public documents – which include medical intake records from when she was arrested, as well as notes from her conversations with a clinical social worker in the late 2000s – suggest that Farak’s misconduct went on much longer than Ms. Coakley’s office initially acknowledged. The documents also suggest that Farak may have been using a variety of illegal substances while working as a forensic chemist as early as 2004.

She has claimed to have tested 29,000 samples throughout her career.

Police recovered some of the documents from her car after her arrest. They were referred to in the police report as “assorted lab paperwork.”

Luke Ryan, an attorney based in Northampton, Mass., asked Coakley’s office multiple times for the recovered evidence. Mr. Ryan, who has represented clients potentially affected by the Farak scandal, says he was first allowed to review the evidence on Oct. 30, 2014. Based on what he saw, he and another defense attorney asked a judge to order the full records from Farak’s therapy sessions.

All those documents were under seal until last month, when Judge C. Jeffrey Kinder ordered them to be made public. The Globe first reported the findings from the documents.

The current Massachusetts attorney general, Maura Healey, is leading an investigation into the scope of Farak’s misconduct. LaBahn of the Association of Prosecuting Attorneys says that the approach – soliciting input from defense attorneys and local prosecutors – is “proper” but is likely to be time-consuming.

“They’re going to have to go case by case,” he says. “It’s going to have to be individualized.”

This should have been done from the get-go, he adds. "I think the latest lesson shows that the starting point in the initial investigation should be the beginning of the [accused’s] employment rather than a date which might have been provided by the offender," he says.

On top of Ms. Healey’s investigation, her office has appointed Peter Velis, a retired Superior Court judge, to conduct an independent investigation into the initial prosecution of Farak. Among other things, that investigation is potentially looking into allegations by defense lawyers that the attorney general’s office under Coakley deliberately withheld evidence.

Although Healey appointed him, Mr. Velis will report his findings to Hampden County Superior Court in Springfield, Mass.

Coakley’s office was criticized for its handling of both the Dookhan and Farak cases. Some other states, however, have responded more decisively to forensic scandals.

Matthew Segal, legal director of the American Civil Liberties Union of Massachusetts, points to a case in Houston, Texas, where – within months of an internal investigation linking misconduct to a crime lab technician – investigators had tabulated every piece of evidence that the individual had touched.

Mr. Segal criticizes the “attitude [that] Massachusetts prosecutors have brought to their work.” But, says, “I don’t think that attitude is shared by prosecutors around the country.”

Instead, Segal sees the repeated scandals in forensic drug labs as an indictment of the US war on drugs.

“If you set up a system of sending people to prison for drugs, and if that decision hinges on the type and weight of those drugs, then years of freedom will depend on the work of chemists, and there will be scandals,” he says.

In many drug busts, a person is holding the substance “for minutes or seconds at the most” before he or she is arrested, says Ryan, the Northampton attorney. The individual often doesn’t know whether the material is a controlled substance, or is counterfeit (“of which there are a lot on street,” Ryan adds). As a result, the fate of such defendants often lies squarely in the hands of the chemist analyzing the drug sample that was being held.

For the tens of thousands of defendants across Massachusetts with potentially tainted drug convictions, relief may be slow in coming. Of the roughly 40,000 “Dookhan defendants,” only 1,187 had filed for post-conviction relief by the end of 2014, according to court documents. While there may be considerably fewer “Farak defendants,” a decade of criminal cases won’t be reviewed overnight.

One of Ryan’s clients in a drug case pleaded guilty in the fall of 2011, but after the Farak scandal broke, he was released on a motion to stay the conviction in April 2013. He had to go back to state prison last year, however, because public evidence in the Farak case at the time showed that her misconduct hadn’t started until the summer of 2012 – months after he’d pleaded guilty.

With the new documents suggesting that misconduct could have dated back to 2004, the court has allowed another motion to stay his conviction. Ryan says he’s also filed a motion for a new trial. If it is denied, his client will have to go back to prison for the six months remaining on his sentence.

He described the process of defending clients affected by the Farak case as “incredibly frustrating and disconcerting.”

“Your job as a prosecutor is not to win at all costs. It’s to do justice,” he adds. “Part of that obligation is that prosecutors have to disclose exculpatory evidence that would undermine their prosecutions and make it more difficult for them to prevail.”

Since that didn’t happen in the early days of the Farak case, state officials now have to track down thousands of former inmates who may be unaware that their drug convictions are tainted.

“I don’t think there’s been nearly the amount of motions to stay that there should be,” says Ryan. “There are a lot of people on probation and parole that I suspect have no idea.”