You can harvest gains out of a 401(k) whenever you can take penalty-free distributions. You can't harvest losses. There's no way to realize a loss out of a 401(k) plan.
If you're doing after-tax 401(k) rollovers/conversions it can be beneficial to try to time them when the market is break-even or down from when the contributions went in. That's not harvesting a loss, but it is avoiding a taxable event.