A typical sequence is rough machine, harden (Q + T), near-finish machine, stress relieve (if necessary), and finish machine. Whether stress relief is needed depends upon the material (brittle? work hardens?), the nature of the final machining (creates heat or deforms? coolant/lubricant used?), whether the parts will be plated, and the application (loading and fatigue issues). For example, steel of hardness HRC 40 or higher which has been ground after heat treatment must be stress relieved prior to electroless nickel plating per AMS 2024. ASTM B733 is more strict (HRC 31), as is chromium plating per QQ-C-320, to avoid cold working which both increases hydrogen embrittlement susceptibility and lessens fatigue resistance.
Machinery’s Handbook, 25th Edn., p. 522 mentions stress relieving high-speed steel after sub-zero cooling treatment.
Stress relief in some cases improves corrosion resistance.