As was mentioned, this can vary depending on the local office, but in most cases they stamp your passport if it's valid on the day of stamping (I would imagine some marginal expiration conditions apply though).
My passport expired 8/2004 and I got stamped on December 2003 with no problems at all.
If your passport nears expiration, make sure to bring an extra photograph (in addition to the 2 photos required for standard I-551/I-89 processing) - instead of stamping the passport, they will use the standard I-94 form, which they affix the extra photo to and stamp with I-551.
Hope this helps