As we can know from the scripts below, Ultron was trying to breach world cybersecurity systems to crack nuclear codes, but he failed thanks to the prevention by a party unknown. Stark went to Oslo and found out that it was Jarvis who's behind the scene.
But I have difficulty understanding what Stark said in the following bold part.
Did Stark create a fail-safe procotol for Jarvis in the first place? If he did, why couldn't he figure out immediately it was Jarvis who's helping before he went to Oslo? Besides, how did Jarvis know Ultron would crack nuclear codes?
[Back at Barton's house, Fury meets with the rest of the team]
Bruce Banner: It's the world internet hub in Oslo, every byte of data flows through there, fastest access on earth.
Clint Barton: So what'd they say?
Nick Fury: He's fixated on the missiles, but the codes are constantly being changed.
Tony Stark: By whom?
Nick Fury: Parties unknown.
Natasha Romanoff: Do we have an ally?
Nick Fury: Ultron's got an enemy, that's not the same thing. Still, I'd pay folding money to know who it is.
Tony Stark: I might need to visit Oslo, find our "unknown."
[NEXUS Internet Hub, Oslo, Norway]
Tony Stark: A hacker who's faster than Ultron? He could be anywhere. And as this is the center of everything, I'm just a guy looking for a needle in the world's biggest haystack.
World Hub Tech: How do you find it?
Tony Stark: Pretty simple. You bring a magnet. Oh, I'm decrypting nuclear codes and you don't want me to. Come and get me.
After the Avengers retrieved the Generation Crade,
Tony Stark: Our ally? The guy protecting the military's nuclear codes? I found him. [he brings up the 3D image of Jarvis's consciousness]
JARVIS: Hello, Dr. Banner.
Tony Stark: Ultron didn't go after JARVIS cause he was angry. He attacked him because he was scared of what he can do. So JARVIS went underground. Okay? Scattered, dumped his memory. But not his protocols. He didn't even know he was in there, until I pieced him together.