Samples in a Markov chain are only drawn with the marginal distribution \(p(\theta | y,x)\) after the chain has converged to its equilibrium distribution. There are several methods to test whether an MCMC method has failed to converge; unfortunately, passing the tests does not guarantee convergence. The recommended method for Stan is to run multiple Markov chains, initialized randomly with a diffuse set of initial parameter values, discard the warmup/adaptation samples, then split the remainder of each chain in half and compute the potential scale reduction statistic \(\hat{R}\).
If the effective sample size is too low to make inferences with the desired precision, double the number of iterations and start again, including rerunning warmup and everything. Often, a small effective sample size is the result of too few warmup iterations. At most, this rerunning strategy will consume about 50% more cycles than guessing the correct number of iterations at the outset.
The estimation of effective sample size is described in detail in the 'Markov Chain Monte Carlo Sampling' chapter of the Stan Modeling Language User's Guide and Reference Manual.