Project length will be determined by the last event written to the file.
This could be anything - an audio clip, midi event, envelope node, tempo change, meter/key change, markers etc
Also, Sonar doesn't know when your Fx tails die out to complete silence. If you do have anything that you don't want cut off, just extend one of your clips - any clip - way out past where you think it might end, start playback, listen intently and hit 'm' when you're satisfied it's silence you're hearing.
Now you can shrink the clip back up to it's original length and you have an end marker in place