Here I am asking more generally. If we have 5 minutes highest granularity. How does downsampling work?

I don't agree with the behavior you are describing. You are mixing granularity (which is used for downsampling) with way how derivation works (which has nothing with downsampling). Now that I am thinking, we are approaching this wrong. We should not combine deriving with downsampling. Deriving maps raw data to raw data. In a reasonable way. How downsampling is done is something completely different.

I will comment this in new pull request and let's continue discussion there.