The textual problems of the novel are extremely complex and have excited much critical scrutiny, debate and conjecture in modern times. Cao did not live to publish his novel, and it is believed by some scholars that the original version of this novel consists of 110 or 108 chapters; however, for unknown reasons, only about 80 chapters were later circulated. Only hand-copied manuscripts survived after Cao's death, until 1791, when the first printed version was published. This printed version, presented by Cheng Weiyuan and Gao E, contains edits and revisions not authorised by the author. It is possible that Cao personally destroyed the last 30 chapters of the novel; or that at least parts of Cao's original ending were incorporated into the 120 chapter Cheng-Gao versions, and it was done with Gao E's "careful emendations" of original manuscripts.
Up until 1791, the novel circulated merely in scribal transcripts. These early hand-copied versions end abruptly at the latest at the 80th chapter. The earlier ones furthermore contain transcribed comments and annotations in red ink from unknown commentators. These commentators' remarks reveal much about the author as a person, and it is now believed that some of them may even be members of Cao Xueqin's own family. The most prominent commentator is Rouge Inkstone (脂硯齋), who revealed much of the interior structuring of the work and the original manuscript ending, now lost. These manuscripts are the most textually reliable versions, known as Rouge versions (脂本). Even amongst some 12 independent surviving manuscripts, small differences in some of the characters, rearrangements and possible rewritings cause the texts to vary a little.
The early 80 chapters brim with prophecies and dramatic foreshadowings that give hints as to how the book would continue. For example, it is obvious that Lin Daiyu will eventually die in the course of the novel; that Baoyu and Baochai will marry; that Baoyu will become a monk.
In 1791, Gao E and Cheng Weiyuan brought together the novel's first printed edition. This was also the first "complete" edition of The Story of the Stone, which they printed as Dream of the Red Chamber (繡像紅樓夢). While the original Rouge manuscripts have eighty chapters, the 1791 edition completed the novel in 120 chapters. The first 80 chapters were edited from the Rouge versions, but the last 40 were newly published.
In 1792, Cheng and Gao published a second edition correcting "typographical and editorial" errors of the 1791 version. In the 1791 prefaces, Cheng claimed to have put together an ending based on the author's working manuscripts.
The debate over the last 40 chapters and the 1791–2 prefaces continues to this day. Many modern scholars believe these chapters were a later addition. Hu Shih, in his 1921 essay Proofs on A Dream of the Red Chamber, argued that the ending was actually written by Gao E, citing the foreshadowing of the main characters' fates in Chapter 5, which differs from the ending of the 1791 Cheng-Gao version. However, during the mid-20th century, the discovery of a 120 chapter manuscript that dates well before 1791 further complicated the questions regarding Gao E and Cheng Weiyuan's involvement—whether they simply edited or actually wrote the continuation of the novel. Though it is unclear if the last 40 chapters of the discovered manuscript contained the original works of Cao, Irene Eber found the discovery "seems to confirm Cheng and Gao's claim that they merely edited a complete manuscript, consisting of 120 chapters, rather than actually writing a portion of the novel."
The book is normally published and read in Cheng Weiyuan and Gao E's 120 chapter version. Some editions move the last 40 chapters to an appendix. Also, some modern editions (like that of Zhou Ruchang's) do not include the last 40 chapters at all.