Boundary Terms in Matrix Elements Recently I have become confused about how boundary terms in the action affect transition amplitudes.  Ultimately I am concerned about field theory, but I think my confusion can be demonstrated with a free point particle example as well.
Consider the matrix element $$ \,_{H}\langle x_2, t_2|x_1, t_1\rangle_{H} = \,_S\langle x_2|e^{iH(t_2 - t_1)}|x_1\rangle_S$$
Where $H, S$ denotes a Heisenberg and Schrodinger vector, respectively.  I am interested in understanding this matrix element from the path integral point of view: $$\,_{H}\langle x_2, t_2|x_1, t_1\rangle_{H} = \int_{q(t_1) = x_1}^{q(t_2) = x_2}\mathcal{D}q(t)\,e^{iS[q]}.$$
My confusion comes from the fact that there are many different representations of the action which could describe a free point particle, which differ by boundary terms.  For example, one could use $$S_1[q] = \frac{1}{2}\int_{t_1}^{t_2}dt\,\dot q^2.$$  Alternatively, one could also use $$S_2[q] = -\frac{1}{2}\int_{t_1}^{t_2}dt\,q\ddot q = S_1[q] - \frac{1}{2}\Big(x_2\dot x_2 -x_1\dot x_1\Big).$$
The first choice of action is traditionally what one would use, and it comes from the Hamiltonian $$H_1 = \frac{p^2}{2}$$ However, I am wondering if the second choice of action has any physical meaning. In particular my questions are the following:
(1) Does using $S_2$ actually compute a transition amplitude at all? For instance, if we use this action, we would have $$\,_{H}\langle x_2, t_2|x_1, t_1\rangle_{H} = e^{ - \frac{i}{2}(x_2\dot x_2 -x_1\dot x_1)}\int_{q(t_1) = x_1}^{q(t_2) = x_2}\mathcal{D}q(t)\,e^{iS_1[q]}$$ This does not seem like a well defined object because $\dot x_{1,2}$ are not well defined. If this path integral does not compute a transition amplitude, does it have another interpretation?
(2) What affect do the boundary terms in $S_2$ have on the Hamiltonian? Is there a different Hamiltonian $H_2$ that gives $S_2$?
Note: For question (1), one could argue that the problematic pieces only appear as a phase, and thus drop out after taking the modulus.  This is true for this simple example, but it may not be in general.  For instance, one might consider $$\,_H\langle x_2, t_2|\psi\rangle_H = \int dx_1\int_{q(t_1) = x_1}^{q(t_2) = x_2}\mathcal{D}q(t)\,e^{iS_2[q]}\,_{H}\langle x_1, t_1|\psi\rangle_H \\= e^{ - \frac{i}{2}x_2\dot x_2}\int dx_1 \,e^{\frac{i}{2}x_1\dot x_1}\int_{q(t_1) = x_1}^{q(t_2) = x_2}\mathcal{D}q(t)\,e^{iS_1[q]}\,_{H}\langle x_1, t_1|\psi\rangle_H $$ where the $x_1 \dot x_1$ piece does not appear as a phase.
 A: The point-particle path integral can allegedly be defined unambiguously in continuous time, but I'm not familiar with the high-brow details of that definition, so I'll do something barbaric: I'll discretize time. And to avoid issues with non-normalizable states, I'll use... normalizable states. Then the quantity of interest is
$$
\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}
 \la\tilde\psi,t_N|\psi,t_1\ra
 \equiv
 \int \prod_t dq_t\ e^{iS[q]}
  \tilde\psi^*(q_N)\psi(q_1).
\tag{1}
$$
This is well-defined as long as (a) $\psi$ and $\tilde\psi$ are normalizable, and (b) doing the integral over $q_1$ gives an expression of the same form but with a new "initial" state that is a normalizable function of $q_2$, and so on.
What happens if we add a total-derivative term to the lagrangian, so that the modified action $S'$ picks up terms that depend on $q_1$ and $q_N$? It modifies the initial and final states. It's the same model as before, with the same action as before, but with different initial and final states.
Now let's increase the number of spacetime dimensions from $1$ to $D$, still discretized. If we imposed periodic boundary conditions in the spatial dimensions, then nothing new would happen. The answer would be the same as above. But what if we don't impose periodic boundary conditions in the spatial dimensions? In that case, adding a total-derivative term to the lagrangian must change the boundary conditions on the spatial dimensions, in addition to changing the initial/final states. In other words, it changes the boundary conditions on all of the spacetime dimensions. I'm using the phrase "boundary conditions" in a broad sense: not just Neumann or Dirichlet, but also including generalizations like integrating over a function of the boundary-variables, just like we normally do to specify the initial/final states.
Just for fun, let's generalize even further. What if we cut a hole inside spacetime? Now we need to specify boundary conditions on the boundary of the hole, and adding a total-derivative term to the lagrangian will change those boundary conditions just like it changed the "outside" boundary conditions. How should we interpret this? If I'm not mistaken, cutting a hole and specifying its boundary conditions is equivalent to inserting a local operator into the path integral (I mean localized within the hole, not necessarily at a point), so that now we're calculating $\la\tilde\psi,t_N|O|\psi,t_1\ra$ for some nontrivial operator $O$. Which operator? That's what the boundary conditions specify. I infer that adding a total-derivative term to the lagrangian changes the operator that we inserted, in addition to changing the initial/final states and the boundary conditions at the far edges of space. Those two things (changing operators and changing states) look different in the canonical formulation, but from this perspective, they look like the same kind of thing, just in different parts of spacetime.
Disclaimer: I'm not an expert in this subject, and what little intuition I do have is based on local lattice QFT, which might not be sufficient to capture everything that can happen in local continuum QFT (cf the not-strictly-local overlap lattice Dirac operator).
A: *

*First of all, if one starts from the operator formalism and derives the path integral (in the standard fashion by inserting infinitely many completeness relations), then one would end up with the action $S_1$; not $S_2$.


*Secondly, if one starts from the path integral formalism and it is supposed to have a semiclassical expansion, then one needs to have a well-defined action principle. The action $S_2$ contains a second-order derivative $\ddot{q}$, which concretely implies that one must impose appropriate boundary conditions (BCs). There are several options but OP's 2 Dirichlet BCs
$$ q(t_i)~=~x_i\quad\text{and}\quad q(t_f)~=~x_f$$
are generically insufficient (except for the special case $x_i=0=x_f$).
For more on variational principles and BCs, see also e.g. this related Phys.SE post.


*For the above reasons, it is better to view $$Z_2~=~\int_{\rm BCs} \!{\cal D}q~e^{\frac{i}{\hbar}S_2}
~=~\int_{\rm BCs} \!{\cal D}q~{\cal O}~e^{\frac{i}{\hbar}S_1}$$ as an expectation value with an operator insertion ${\cal O}=e^{\frac{i}{\hbar}(S_2-S_1)}$, cf. the answer by Chiral Anomaly.
