Song uses her sonic screwdriver and opens a hole in the hallway, letting the Doctor and the others to escape. Meanwhile, the Girl is watching their exploits on her television, even though her father can't see anything. The Girl switches channels to a TV show featuring a convalescence home, CAL, where an ambulance delivers a patient: Donna Noble. Donna finds herself in a room and Dr. Moon comes in to see her and says he's been treating her for two years. He takes her for a walk and asks her if she's come to grips with her dreams about the Doctor. He suggests they go down to the river and they find themselves there instantly. Moon introduces Donna to another man, Lee McIvoy, who invites her fishing. Events happen, instant to instant, as Donna dates Lee, gets married, and has two children. Dr. Moon visits and Donna notes that it seems that no time has apparently passed. Moon then fades out and briefly appears as the Doctor, talking about signal interference. Dr. Moon tells her that she saw the Doctor and then forgot, and she instantly forgets.
The Doctor and the others get to a well lit room but the sun is setting. The Doctor tries to seal the room but the Vashta Nerada are closing in. His sonic screwdriver starts to malfunction due to a signal interfering. When the Doctor is skeptical of Song's claim that she's his future companion, she whispers a single word in his ear to gain his trust, and he accepts her. He then concludes there's a new and much stronger signal interfering. They see the moon rising overhead and Lux explains that it is a doctor moon, which acts as a virus program for the planet's computer core. Using his sonic screwdriver, the Doctor accidentally summons an image of Donna. They're interrupted when Anita notices she has two shadows. Everyone dons their helmets and Song puts Anita's helmet on, and the Doctor tints her visor hoping the Vashta Nerada will think they're already there. Proper Dave's suited corpse, possessed by the Vashta Nerada, arrives and they're forced to run.
The Girl is watching Proper Dave on TV and switches channel to Donna with Lee and her two children Josh and Ella. She wonders where Dr. Moon is and looks outside to see a black-robed figure outside. She says she's tired and instantly finds herself in the bedroom with Lee. She hears a door open below and when Lee goes to investigate, she sees the robed figure in the street. Lee comes up with a note for her saying, "The world is wrong" and an invitation to meet with someone in the park the next day. As the Girl says "don't go," Donna goes to the park and sees the robed figure on a bench. Donna sits next to it and a female voice says that Donna got the note a few seconds ago, not the previous night. The figure explains that time progresses instantly and says they've met before in the library. Donna recognizes the voice and the figure reveals she's Miss Evangelista.
The Doctor stays behind with Other Dave and when the animated suit arrives, the Doctor tries to talk to it. The Vashta Nerada finally speak through the telepathic relay, explaining they hatched in the Library. The Doctor realized they hatched from spores in the books, but then sees that Other Dave has been killed as well. The two animated suits move in but the Doctor activates a trap door beneath him and plummets through, catching himself on the platform below.
Evangelista shows Donna the other children in the playground and explains that Donna has been programmed not to look. Donna starts to remember that Evangelista died, and Evangelista says the children were never alive. Donna looks and realizes that all of the children are the same single boy and girl. Donna rips aside Evangelista's veil to reveal a twisted, distorted face.
Song, Anita, and Lux have taken refuge in the Library and Song explains that she's uncomfortable with this early version of the Doctor, before he's first met her. She remembers her Doctor, who can send armies running and open the TARDIS with a snap of his fingers. The Doctor arrives and says it's not possible to open a TARDIS by snapping his fingers. Anita wonders why she's not dead yet and asks what it is that Song told him to win his trust, that his secret is safe with her. The Doctor realizes that when the computer said the survivors were "saved," it meant they were saved somewhere.
As the Girl watches, Evangelista explains that her face is distorted due to transcription errors, and that they are all "saved." The Girl screams at her not to tell.
The Doctor checks the computer system and confirms that there was a power surge a hundred years ago and the computer "saved" them: inside its database system.
Evangelista explains that Donna's body is stored as an energy signature and her mind inside the computer's hard drive. Donna's image is okay because she was teleported directly, but Evangelista is a corrupted data signal. She is also smarter because of the transcription error. When Donna wonders whose dream it is, Evangelista says the key is one word: CAL. The Girl changes the signal, and Donna's daughter injures her knee. Evangelista tries to explain that they're fictions sustained by Donna's beliefs, and she has to let them loose. The Girl screams at Evangelista, saying she'll spoil everything. When her father asks what's wrong, the Girl makes him disappear using the remote. She throws down the remote, and signals go off in the Library indicating that auto-destruct has been activated.
Donna takes her children home only to see that everything has turned red. The Doctor determines they have 20 minutes until self-destruct. Dr. Moon appears to the Girl and explains that she saved them all, but then she fvorgot. The Girl shuts him off… and the Doctor loses his data connection. Lux says they have to save CAL and must get to the main computer core.
Donna puts her children to bed and tries to reassure them, but they say that they're not real and disappear when she doesn't look at them. She promises to never close her eyes again… but then they disappear and she collapses, crying.
The Doctor and the others arrive at the computer core with time running out. The Girl cries out for help as the Doctor gets to a computer relays and hears her cry. The computer is in sleep mode and he tries to wake it, and her up. Lux activates a data Node to reveal the Girl. He explains that she is the computer and CAL: Charlotte Abigail Lux. Charlotte is Lux's grandfather's youngest daughter, who dying. They built a library and put her mind inside of it with all of human history for her to read and a moon to watch over. When the shadows came, CAL saved everyone in the library by storing them in the computer, but the information overwhelmed her systems and caused her to forget. CAL doesn't have enough memory space to teleport the survivors out of the core and the Doctor plans to use his own memory to supplement the computer. Anita wonders what will happen to the Vashta Nerada, and the Doctor says that they can roam to their heart's content. He then confronts "Anita," revealing the Vashta Nerada have already consumed her and have been talking through her using the telepathic link. The Vashta Nerada refuse to let her go and start to advance toward him. He tells them to look him up in the database and they agree to give him one day. Song realizes the Doctor can't get by without him and knocks him unconscious.
The Doctor wakes up handcuffed to a wall strut as Song hooks herself up into the memory system. She says that "her" Doctor in the future must have known it was time for her to go back and die, and gave her the sonic screwdriver. The Doctor can't die here or it will change history. She completes the circuit as in the virtual reality, Lee arrives to see Donna… and he fades out as she's teleported back to the real world. As he disappears she promises that she'll find him.
Groups of the survivors start appearing in the Library while Donna looks for Lee. The Doctor finds her as she says she hasn't found anyone named Lee. She wonders if he was real and they go to the TARDIS… just as Lee arrives. Back at the TARDIS, Donna wonders what happens to her since Song had never heard of her. The Doctor considers Song's diary and wonders if they should look to the future, and they both agree not to. The Doctor leaves it with Song's sonic screwdriver and walks away… and then comes back, realizing there was a reason he gave her the sonic screwdriver. He takes it to the computer core and activates a telepathic link inside of it. Inside the virtual reality, Song appears in the virtual reality with Charlotte and Moon, and Charlotte introduces Song to the Daves, Anita, and Evangelista, all stored within the computer.
The Doctor goes to the TARDIS… and snaps his fingers, opening it. He and Donna leave, while Song considers her diary, tucks in her new children Josh and Ella, and notes that sometimes… everyone lives.