Bhai Sahib,
From childhood I remember the sakhi about the Cobra through oral tradition. As an adult I never checked any books to verify these facts. But as an adult I think I did come across the story of the Cobra in Kavi Santokh Singhs book Suraj Parkash. Either way if it was shade of the tree or Cobra the shaded Guru Sahib I think the same message is the same " All nature, all of creation serves Guru Sahib" . This story can be verified by Gurbani.
I dont necessarily think written word is more authentic and truthful than oral word. History books mentioned Guru Sahib worshiped Durga ( Gurbilas, Sukha Singh) and performed Jhatka ( Panth Parkash, Rattan Bhangu). But relying on Gurbani intuitively ( bibek budhi) and oral traditions for verification we know this written history is false. We know through these methods that Guru Sahib was against worshipping of Gods and performance of Hindu Rituals. Even our nitnem we get from oral tradition there are no historical books that tell us what the daily nitnem is for Khalsa instead we just rely on Gurmat- Bibek and oral traditions.
I know that oral traditions often contradict one another the way written records can contradict one another, but at the end I think intuition has to play a role in which historical version you want to accept. Gurmat intuition should supersede logical inferences based on written records. I personally feel more comfortable with the Cobra story even though I feel nothing is wrong with the shaded tree version.