I haven’t studied your entire post, but I’m giving a qualified guess, here.
There is a long story to this, but the short one is this: When running the server, we clear the Page.Scratch when we rebuild, and this may have some unwanted side-effects.
We recently added $.Store.Set etc. which behaves exactly like Scratch, but is never cleared.
Not in beta, but there are some missing pieces in the docs. I’m in the process of redoing the documentation site with a complete reference section.
Using Scratch in different places requires you to think a little:
Hugo renders pages in parallel, so there is no guarantee that, say, the home page gets rendered before any other.
If you want to access a scratch value in a render hook you need to make sure to set it before any of the content methods gets called (e.g. {{ $.Store.Set "foo" "bar" }} {{ $tmp := .Content }}. I don’t have your source code, so I have no idea about the details here.
One trick that can be used to overcome some this is to set up a output format that prepares some global state (in e.g. the home page template) and make sure that is ordered first (either by prefixing it with e.g. _ or set a weight on the output format definition). That way you will be guaranteed to not have multiple threads/goroutines mixing up…