This note extends the works of Spear and Srivastava (1987) and Phelan and Townsend (1991) on the use of recursive techniques for finding optimal mechanisms given repeated moral hazard. Specifically, it relaxes the assumption that the stochastic process determining privately observed shocks is time-independent, allowing instead such shocks to follow an n-stage Markov process. The techniques developed make transparent the fact that optimal mechanisms with history-dependent privately-observed shocks will, in general, be ex-post inefficient. The main trick is expand the set of state statistics from a singleton denoting the expected discounted utility of the agent at a point in time, to a vector of utilities denoting the expected discounted utility of the agent for each possible deviation strategy for the preceding n-periods. This method solves an ex-post adverse selection problem, and with a slight extension, an ex-ante adverse selection problem as well.