In Landau/Lifshitz' "Mechanics", $\S43$, 3ed, the authors consider the action of a mechanical system as a function of its final time $t$ and its final position $q$. They consider paths originating at some point $q^{(1)}$ at a time $t_1$, and terminating at the same point $q$ after different times $t$. The total derivative of the action is then
$$ \frac{dS}{dt}=\frac{\partial S}{\partial t}+\sum_i\frac{\partial S}{\partial q_i}\dot{q}_i\tag{p.139}. $$
The authors then claim that $\frac{\partial S}{\partial q_i}$ can be replaced by $p_i$. I don't understand this step. L+L derived this formula for $p_i$ by considering paths starting from the same point $q^{(1)}$, but passing through different endpoints after a common time interval. Why should $$p_i=\frac{\partial S}{\partial q_i}\tag{43.3}$$ continue to hold when the action is varied in a different way?