Solution (source code)

= Solution

For an autonomous <Lagrangian>, the <canonical momentum> and <energy> are
$$
p=L_{\dot q},\qquad E=p\dot q-L.
$$
Along a solution of the <Euler-Lagrange equation>,
$$
\frac{dE}{dt}
=(\dot p-L_q)\dot q-L_t=0.
$$
The absence of explicit time dependence is essential to this conservation law.

The classical <action> is $S_c(q_I,q_F,T)=\int_0^TL(q_c,\dot q_c)\,dt$. If the final endpoint is moved along one fixed classical trajectory, while the initial endpoint is held fixed, the <fundamental theorem of calculus> gives
$$
\frac{dS_c}{dT}=L(q_c(T),\dot q_c(T)).
$$
This total derivative is different from the partial derivative with fixed final position.

For a family of nearby classical trajectories, integration by parts gives the endpoint variation
$$
\delta S_c=\int_0^T(L_q-\dot p)\delta q\,dt+
p_F\delta q_F-p_I\delta q_I+(L_F-p_F\dot q_F)\delta T.
$$
To obtain the final term, the endpoint change in the variation at fixed parameter time is $\delta q(T)=\delta q_F-\dot q_F\delta T$, while the changing upper integration limit contributes $L_F\delta T$. The interior integral vanishes by the <Euler-Lagrange equation>. Therefore, on any smooth branch of classical boundary-value solutions,
$$
\boxed{\frac{\partial S_c}{\partial q_F}=p_F,\qquad
\frac{\partial S_c}{\partial q_I}=-p_I,\qquad
\frac{\partial S_c}{\partial T}=-E.}
$$
The chain rule along the endpoint trajectory now reads $dS_c/dT=p_F\dot q_F-E=L_F$, consistently with the direct calculation.