  The Hamilton-Jacobi equation on metric spaces has been studied by several
authors; following the approach of Gangbo and Swiech, we show that the final
value problem for the Hamilton-Jacobi equation has a unique solution even if we
add a homological term to the Hamiltonian.
  In metric measure spaces which satisfy the $RCD(K,\infty)$ condition one can
define a Laplacian which shares many properties with the ordinary Laplacian on
$\R^n$; in particular, it is possible to formulate a viscous Hamilton-Jacobi
equation. We show that, if the homological term is sufficiently regular, the
viscous Hamilton-Jacobi equation has a unique solution also in this case.
