NASA astronaut Andrew Morgan rides a robotic arm while working outside the International Space Station on a spacewalk repair of the $2 billion Alpha Magnetic Spectrometer on Jan. 25, 2020.

It took four years of planning, 20 new tools shipped by spacecraft and an unprecedented four-part repair job, but a $2 billion experiment on the International Space Station is all patched up after a spacewalk by astronauts Saturday (Jan. 25).

NASA astronaut Drew Morgan and European Space Agency astronaut Luca Parmitano spent 6 hours, 16 minutes working outside station to finish repairs on the ailing Alpha Magnetic Spectrometer , a 9-year-old cosmic ray detector designed to seek out dark matter and antimatter. The instrument, launched in 2011, had lost two of four critical coolant pumps, which the spacewalkers restored. NASA aims to run a series of tests in upcoming days to make sure the repair worked.

It wasn't an easy job to perform. Parmitano and Morgan were on the fourth of four spacewalks to fix AMS, completing work that began on the instrument in November . The astronauts were using tools to fix an instrument that was initially, never even designed for spacewalking repairs. On this spacewalk, which was broadcast live on NASA Television, leak drama dominated the early hours of the work.

Related: The amazing spacewalks of Expedition 61 in photos

Image 1 of 4 (Image credit: NASA TV) European Space Agency astronaut Luca Parmitano works to repair the Alpha Magnetic Spectrometer on the International Space Station in this view from the helmet camera of his crewmate, NASA astronaut Andrew Morgan, during a spacewalk on Jan. 25, 2020. Image 2 of 4 NASA astronaut Andrew Morgan and European Space Agency astronaut Luca Parmitano spent more than 6 hours working outside the International Space Station on a spacewalk repair of the $2 billion Alpha Magnetic Spectrometer on Jan. 25, 2020. (Image credit: NASA TV) Another view of NASA astronaut Andrew Morgan on the space station's Canadarm2 robotic arm during the Alpha Magnetic Spectrometer spacewalk repair on Jan. 25, 2020. Image 3 of 4 (Image credit: NASA TV) European Space Agency astronaut Luca Parmitano snaps a photo in this view from crewmate Andrew Morgan's helmet camera during the Jan. 25, 2020 spacewalk. Image 4 of 4 (Image credit: NASA TV) A view of NASA astronaut Andrew Morgan with the Earth far below as seen by the helmet camera of ESA astronaut Luca Parmitano.

A leaky beginning

The first leak happened even before astronauts left the space station airlock.

Shortly after NASA astronauts Christina Koch and Jessica Meir buttoned down the interior hatch, the crew discovered extraneous airflow during depressurization to let the spacewalking astronauts go "outside" into space. "It seems we may have a leak in the upper right corner. We can hear the airflow," Meir reported to the ground as she hovered at the hatch.

Squeezed inside the airlock on the other side of the hatch, Parmitano spotted the problem in seconds: a strap from one of the tool bags was caught between the crew lock section (where the spacewalking astronauts were waiting to exit) and the equipment lock, where Meir and Koch were working on the inside of the station in the Unity module. The crew carefully repressurized the airlock, opened the hatch, checked the seal, and then closed the hatch again to restart depressurization. With no leaks happening this time around, Meir finished venting the airlock's oxygen into space.

The spacewalk officially started about 15 minutes late, at 7:04 a.m. EST (1204 GMT), when the spacewalking pair switched their spacesuits to battery power. Morgan was the first to emerge into space from the Quest Joint Airlock, with Parmitano following – legs first. The crew began their excursion to AMS, which is located on the S3 truss in a difficult-to-reach location high atop the ISS. Morgan rode there on the robotic Canadarm2, controlled by Koch.

Parmitano, who made his way to the workstation hand-over-hand, was the first to start routine leak checks on eight feeder tubes installed as part of the last AMS spacewalk , to splice in some newly installed coolant pumps. Parmitano began with tube No. 5, and that's where the crew discovered their second leak of the spacewalk. Parmitano tightened the connection on the tube. NASA procedures dictated the crew had to wait an hour until doing a second check on the leaky tube.

Morgan and Parmitano methodically examined the other seven tubes for leaks, and found nothing. NASA next decided to let the astronauts stay in place for the one-hour wait time to perform the supplementary leak check. This meant that, unusually, both ground control and the crew had several minutes of idle time to banter about the work so far — and the view of night lights from Japan.

"Luca, I've got to know what made you pick [leak checks on] No. 5 first," said Canadian Space Agency astronaut Jeremy Hansen, the capcom lead for the spacewalk, from Mission Control in Houston.

"It was the closest," Parmitano laconically responded.

"We wondered if you had some sort of intuition or something," said Hansen, who was on the team developing procedures to fix AMS.

"Like I say," Parmitano answered, "it's always better to be lucky than good."

Hansen joked it did save the crew "time on the clock" for Parmitano to find the leaking tube first, of the eight tubes that needed to be checked. "But there's no other way to create more drama," he continued, "than to give us that on the first one. I think everyone's heart stopped."

"I wonder what my flight surgeon saw on the download of my heart rate," Parmitano responded.

"Yeah, they're not allowed us to tell us, I don't think," Hansen answered, laughing.

"Either flatline or spike, one of the two," joked Parmitano.

Plumbing in space

The second check of tube No. 5 went much like the first one — another leak, another instruction to tighten the connection, another hour-long wait to verify it worked. The crew members readied backup tool bags in case they had to install a jumper to bypass the leaky spot altogether.

Hansen reassured his spacewalking colleagues that there was lots of oxygen left in their spacesuits to perform this supplemental fix, if necessary. "We have the equipment and procedures to get the AMS in a good final [configuration]," he radioed, "so overall, we're going in a good final direction here."

Fortunately, the third leak check of tube No. 5 — which NASA decided was safe to perform around 3 hours elapsed time in the spacewalk, and 17 minutes early — showed nothing.

"No red," Parmitano said, referring to an error indication on his visual leak indicator tool that would indicate trouble. "No leak!" With the AMS secured, Parmitano opened an accumulator valve to pressurize the coolant system.

The astronauts next moved to cleanup tasks on the instrument repair, with Parmitano now using Canadarm2 and Morgan floating on tethers: installing multi-layer insulation to replace an access panel removed in an earlier spacewalk, to protect AMS from the harsh temperatures of space; placing a "mud flap" (or cover) in between the AMS pump and a vertical support beam; and removing a temporary cap placed on a radiator during the third AMS spacewalk in December.

Cable cleanup

Around the four-hour mark of the spacewalk, Parmitano encountered lengthy problems in stowing all the necessary cables and a handrail underneath a "mud flap," but after eyeballing the work site and speaking with Mission Control, he said he had a way to fit everything in. "I think I have a plan to try and fight it," he said, as he dove into the work, chatting periodically with the ground and his crewmates to get advice on how to proceed.

"Just don't force anything, Luca, we have power cables back there," Hansen advised around 4 hours and 20 minutes into the spacewalk. The two continued to discuss how Parmitano planned to put the power cables underneath the thermal protection cover as the spacewalker carefully closed it over AMS. "That's good, Luca," Hansen said after Mission Control inspected the work through Parmitano's helmet camera. The spacewalking astronauts next moved to the radiator cap and took it off, with little issue.

As the spacewalk passed the five-hour mark, Mission Control and the spacewalking duo discussed a few options for approaching one of the planned "get ahead" tasks if the crew had a little extra time in their spacewalk, which would require them to move to cameras at the intersection of the P4 and P6 truss of the ISS

At issue was high oxygen consumption when Morgan exerted himself, so NASA wanted to make sure they were carefully monitoring how his spacesuit was performing. Morgan promised he would make his way to the worksite "super, super slow" to limit his oxygen use. They began the move at about the 5.5-hour mark. Subsequently, each astronaut successfully removed a fogged-up filter one of the two cameras.

"It's in the trash bag," Morgan said after taking off his assigned filter.

"Nice work, Drew," responded Hansen. After the spacewalking astronauts did a last check to make sure nothing would be left behind, Hansen directed them to go back to the airlock. "Let's go home," he said.

Reviving the Alpha Magnetic Spectrometer

The astronauts concluded the spacewalk at 1:20 p.m. EST (1720 GMT). Now that AMS is ready for activation, scientists at the European Organization for Nuclear Research (CERN) will spend two days "controlling and monitoring the experiment to prepare for more data-taking," according to a tweet from CERN . If these checks go as planned, AMS should be ready to collect good scientific data by Wednesday (Jan. 29), NASA said during the spacewalk.

The overall goal of AMS is to better understand the nature of dark matter , dark energy , cosmic rays and other cosmic phenomena, to learn about the history of the universe. The instrument began experiencing issues in 2014 when one of its four original carbon dioxide cooling pumps stopped working, and another one began degrading. In March 2017, NASA said, engineers switched AMS to the last fully functioning coolant pump.

It was around that time that AMS scientists and space station managers determined to design spacewalks to extend the instrument's lifetime. Since AMS was not designed to be serviced in space, ground teams spent several years preparing new tools and spacewalks to repair the instrument. The complexity of the work has been compared with the last spacewalk set to upgrade the Hubble Space Telescope in 2009.

Pending the success of these spacewalk repairs, AMS should now operate through the rest of the space station lifetime, which is currently projected for 2024, NASA added.

At five hours and two minutes into Saturday's spacewalk, Parmitano broke the record for accumulated time "outside" by a European astronaut, besting the 31 hours and 54 minutes Christer Fuglesang spent during five spacewalks from 2006 to 2009, according to an ESA Spaceflight tweet . Parmitano's accumulated time in spacesuits is 33 hours and nine minutes, NASA said during the broadcast.

Saturday's spacewalk was the sixth for Parmitano and the seventh for Morgan – who has 45 hours and 48 minutes in spacesuits, which is 16th on the all-time spacewalkers' list, NASA said. The extravehicular activity was also the 227th spacewalk overall for the International Space Station.

This excursion was the third spacewalk for the Expedition 61 crew in January 2020 alone, after two all-women spacewalks by Koch and Meir earlier this month to do battery work. The Expedition 61 crew has performed nine spacewalks overall, more than any crew increment.

Follow Elizabeth Howell on Twitter @howellspace. Follow us on Twitter @Spacedotcom and on Facebook.