  The HR 8799 system uniquely harbors four young super-Jupiters whose orbits
can provide insights into the system's dynamical history and constrain the
masses of the planets themselves. Using the Gemini Planet Imager (GPI), we
obtained down to one milliarcsecond precision on the astrometry of these
planets. We assessed four-planet orbit models with different levels of
constraints and found that assuming the planets are near 1:2:4:8 period
commensurabilities, or are coplanar, does not worsen the fit. We added the
prior that the planets must have been stable for the age of the system (40 Myr)
by running orbit configurations from our posteriors through $N$-body
simulations and varying the masses of the planets. We found that only assuming
the planets are both coplanar and near 1:2:4:8 period commensurabilities
produces dynamically stable orbits in large quantities. Our posterior of stable
coplanar orbits tightly constrains the planets' orbits, and we discuss
implications for the outermost planet b shaping the debris disk. A four-planet
resonance lock is not necessary for stability up to now. However, planet pairs
d and e, and c and d, are each likely locked in two-body resonances for
stability if their component masses are above $6~M_{\rm{Jup}}$ and
$7~M_{\rm{Jup}}$, respectively. Combining the dynamical and luminosity
constraints on the masses using hot-start evolutionary models and a system age
of $42 \pm 5$~Myr, we found the mass of planet b to be $5.8 \pm
0.5~M_{\rm{Jup}}$, and the masses of planets c, d, and e to be
$7.2_{-0.7}^{+0.6}~M_{\rm{Jup}}$ each.
