Some OS-wide integration with sleep trackers would be great. While I've read that apparently these trackers are not so accurate, my experience with the Sleep Cycle app has been that it's probably accurate enough to detect me falling asleep, especially since I have a tendency to actively shake my phone if I'm motionless but awake for a while.
As others have mentioned, some kind of 'stay awake' feature would probably solve the issue too. I'm thinking a non-intrusive beep or shake the indicate that the phone is about to go into 'sleep mode', which can be dealt with by some feedback. the interval could then be set in the app or OS settings.
The nice thing about doing this system-wide is that it could do all sorts of other stuff: turn off notifications (I sometimes forget and get rudely awakened at night), go into low-battery mode, turn off the screen (in case I forget to put it facing down), etc.