Immediately following the events of the previous episode, "Silence in the Library", the Doctor and the exploration team manage to escape the Vashta Nerada and take refuge in a well-lit room. As they work out a plan, the Doctor is concerned about how he can trust River Song, so she whispers a single word in his ear which convinces him: his real name (the name is not revealed to the audience). Donna Noble finds herself at a care home named "CAL", apparently two years later, with Dr Moon treating her. He introduces her to another man, Lee, and is later seen visiting the married Donna and her family. However, Donna keeps noticing that something is wrong; she seems to skip from one place to another instantaneously at a whim, only to be reminded of the journey by Dr Moon, who does this frequently by ending his sentences with "...and then you remembered/forgot"). Meanwhile, the little girl watches both the Doctor and Donna by switching channels on her television.
In the library, the Doctor discovers that the moon is sending out electromagnetic signals that are interfering with his sonic screwdriver. Strackman Lux explains that the moon is a virus scanner for the planet-side computer core. The Doctor briefly interrupts this signal, and suddenly appears in Dr Moon's place next to Donna; Dr Moon is quite literally the "doctor moon". The Doctor then understands that the message "4022 saved" did not mean they were rescued, but that their teleport patterns were saved to the library's hard drive. They are found once more by the Vashta Nerada suit and forced to flee, but the Doctor stays behind to reason with it. Through the communicator on the suit, the Vashta Nerada explain that the library is their "forest"; the paper of the countless books in the library was made from trees filled with Vashta Nerada spores, from which they hatched after being shipped to the library. They manage to kill Other Dave and resume the chase. River still laments the non-appearance of the Doctor she knew, recalling him making whole armies run away and opening the TARDIS with a snap of his fingers. Anita notices she has two shadows, and the Doctor uses his sonic screwdriver to tint her visor to attempt to trick the Vashta Nerada into thinking they are already in there.
In the computer core, the truth of the situation is revealed to Donna by none other than Miss Evangelista. She reveals that her Data Ghost was captured by the library's wireless internet, but was corrupted and caused her face to become severely disfigured while increasing her intelligence, leaving her "brilliant but unloved" and able to see the false reality for what it really is. She points out that all the children are merely identical copies, and gets Donna to remember the library. However, the young girl, watching from her television, does not want Donna to know and uses her television remote control to injure one of Donna's children as a diversion. Donna leaves Miss Evangelista behind, but her acceptance of the simulated reality is nevertheless shaken, and her invented children disappear when confronted with the fact that they do not exist. The little girl, increasingly frustrated by events, "switches off" her father and throws the remote control to the floor, activating the computer's self-destruct mechanism. Dr Moon attempts to protect the girl as he is programmed to do, but he is also switched off.
To stop the self-destruct, the Doctor, River Song, and Lux make their way to the computer core. Here, Lux reveals the meaning of CAL: it is an acronym for the name Charlotte Abigail Lux, his grandfather's daughter, who was wired into the computer as a child because she was dying. In this manner, Charlotte could live forever with the sum total of human knowledge to pass the time. However, storing the patterns of 4022 unique people has filled her computer core, and is preventing normal operations. The only way to set things right is to reintegrate them in the library. As CAL cannot do this alone, the Doctor prepares to wire his own mind into the system as extra memory, though it will surely kill him. As he works, he uses his screwdriver to un-tint Anita's visor to reveal a skeleton inside - she had been dead for some time now. He speaks with the Vashta Nerada and insists that in exchange for getting to keep their forest, he will get to save the people in the computer core. The Vashta Nerada initially refuse, but when the Doctor tells them to search for his name in the library's archives, they immediately reconsider and give him a day to clear the planet. River, unwilling to let the Doctor die, which would rewrite history and erase their time together, knocks him out and takes his place, rescuing those trapped in the computer at the cost of her life instead of his.
As the rescued humans are teleported home, Donna meets up with the Doctor. Having been unable to find her husband from the virtual world, the pair walks to the TARDIS, unaware that he is in the next group being teleported out. As the Doctor mournfully leaves River's diary and her sonic screwdriver in the library, he realises the reason why his future self gave her the sonic screwdriver in the first place: it holds a communication device with a Data Ghost. He uses it to bring River back to life inside the computer. After returning to the TARDIS, he decides to test what River Song said about his future: he opens and closes the TARDIS doors by snapping his fingers, then continues his adventures. Meanwhile, River Song appears in the virtual world, where she is greeted by Charlotte and Dr Moon. Anita, the two Daves and Miss Evangelista (her face restored) also appear, their Data Ghosts having been saved in uncorrupted form by Charlotte and brought into the computer for eternity. Josh and Ella, the homogeneous children from CAL's world, are seen to live with Charlotte and River.
Doctor David Tennant (Tenth Doctor)
Companion Catherine Tate (Donna Noble)
Alex Kingston – River Song
Colin Salmon – Dr Moon
Harry Peacock – Proper Dave
Steve Pemberton – Strackman Lux
Jessika Williams – Anita
O-T Fagbenle – Other Dave
Eve Newton – The Girl
Mark Dexter – Dad
Jason Pitt – Lee
Eloise Rakic-Platt – Ella
Alex Midwood – Joshua
Talulah Riley – Miss Evangelista
Jonathan Reuben - Man
Writer Steven Moffat
Director Euros Lyn
Script editor Helen Raynor
Producer Phil Collinson
Executive producer(s) Russell T. Davies
Production code 4.9
Series Series 4
Length 2nd of 2-part story, 45 minutes
Originally broadcast 7 June 2008