Trajectory-Level Pessimism for Safe Sim-to-Real Adaptation

When a robot policy trained in a physics simulator is moved to real hardware, the most dangerous errors are often not large single-step mistakes. They are small, persistent ones. Motor lag, gear backlash and stick-slip friction push the real trajectory a little further from the simulated one at every step, and the drift accumulates until the robot hits an obstacle or exceeds a joint limit. The current best method for zero-shot safe transfer, SPiDR, adds a per-step cost penalty wherever an ensemble of randomized simulators disagrees about the next state. That works well when reality lies inside the randomized range. When reality lies outside it, the simulators agree with each other and are all wrong in the same way, so the penalty vanishes exactly where it is needed.

We propose to learn the gap between simulator and reality as a distribution over whole trajectory segments rather than single steps, and to compute the safety cost bound from that distribution. Concretely, a diffusion model (a generator that learns to turn random noise into samples by gradually removing it) is trained on a small number of real trajectory segments. Each segment is paired with the simulator's prediction for the same start state and policy, and the model learns to generate plausible real deviations from the simulated path. The cost bound for a policy is an upper quantile of the cumulative cost over these generated "what reality might do" segments. Its pessimism level is set by a held-out calibration step on real data, not by a hand-tuned weight. The bound then gates a safe online adaptation loop on the real system. The claim is narrow and testable. Sim-to-real error that is correlated over time is systematically underestimated by any penalty that treats steps independently, and modeling it at the segment level gives cost bounds that actually cover real outcomes with far fewer real samples.

Core Claim

The literature on cost pessimism agrees on one point. In constrained reinforcement learning, where an agent maximizes reward while keeping expected cumulative cost below a budget, underestimating cost is the failure that the optimizer exploits. Policies flow toward regions where the cost critic is optimistic. Three papers make this case from different angles. MICE attributes training-time violations to cost-critic underestimation and corrects it with memory-based intrinsic costs. COX-Q truncates optimistic quantiles of a distributional cost critic. DRCORL uses an upper confidence bound over a cost-critic ensemble. COX-Q also flags the weakness that motivates us: when ensemble members share the same blind spot, taking their maximum is not an upper bound. SPiDR's out-of-support failure is the dynamics-model version of that same weakness.

We think the reason it matters for transfer is temporal. The phenomena the file lists as the main sources of the reality gap are actuator latency and compliance (Peng et al.; Kelchtermans et al.) and contact friction and jamming (Zachares et al.). All of them are history-dependent. A per-step penalty of the form $c(s,a) + \lambda\,\upsilon(s,a)$, where $\upsilon$ is next-state disagreement, can be tiny at every step while the cumulative real cost over a horizon is large. Our proposal replaces the per-step bound with a segment-level one:

$$\hat C^{+}_{\pi}(s_0) \;=\; \mathrm{Quantile}_{1-\delta}\Big\{ \textstyle\sum_{t=0}^{H-1} \gamma^t c(\tilde s_t, a_t) \;:\; \tilde\tau \sim G_\theta(\cdot \mid s_0, \tau^{\text{sim}}_\pi) \Big\} + q_\alpha .$$

Here $\tau^{\text{sim}}_\pi$ is the simulator rollout of policy $\pi$ from state $s_0$ over $H$ steps, $G_\theta$ is the residual trajectory generator, $\tilde\tau$ is a generated real-like segment, $\gamma$ is the discount, and $\delta$ is the sample quantile level. The term $q_\alpha$ is a correction computed on held-out real segments. It is the $(1-\alpha)$ empirical quantile of how much the real cumulative cost exceeded the uncorrected bound, as in split conformal prediction. The aim is that the bound covers the real cost with probability about $1-\alpha$. This addresses two weaknesses that the file identifies in SPiDR: the heuristic choice of $\lambda$ and the silent failure out of support. A miscalibrated generator shows up directly as a larger $q_\alpha$ instead of disappearing.

Research Program

The generator borrows its method from PolyGRAD. PolyGRAD diffuses an entire on-policy segment in one pass, with actions guided by the policy's score, which avoids the compounding error of step-by-step world models. Our change is to condition on the simulator's own rollout and to predict the real residual. The simulator then carries the physics it gets right, and the generator only has to learn what it gets wrong. PolyGRAD reports fidelity decay beyond about 100 steps and instability when policies become near-deterministic. We therefore keep $H$ at 64 steps or fewer and add a small entropy floor on the guiding policy. Both are constraints from that paper, not choices we can ignore.

To train the generator, we take real segments and, starting from each segment's first state, roll out the same policy in the nominal simulator. This needs the simulator to be reset to real states. SR² relies on the same operation and notes that it is nontrivial for black-box simulators. In our testbeds the state is fully estimated, so the reset is feasible. We will report how sensitive the method is to state-estimation noise at reset.

Real data comes from a safe adaptation loop. We start from the SPiDR policy, which serves as the safe baseline $\pi_b$. Real data is collected with a mixture of this baseline and an exploratory policy, the device used by Provably Safe Sim-to-Real Transfer and DOPE. The mixing weight is increased only while $\hat C^{+}$ for the mixture stays under budget. Policy improvement happens on generated segments under a primal-dual objective with the bound as the constraint. The real-sample economy of the tabular mismatch-region idea carries over naturally. Where the generated residuals are small and the correction $q_\alpha$ is small, the bound is tight and the agent may explore. Where they are large, it falls back toward $\pi_b$.

One honest caveat concerns the calibration step. Conformal coverage assumes the calibration data is exchangeable with test conditions, and a changing policy breaks this. We therefore recompute $q_\alpha$ on a sliding window of the most recent real segments collected under policies within a fixed divergence of the current one. We will measure the empirical coverage gap that results.

Baselines

The naive reference point is standard domain randomization with a Lagrangian constrained policy optimizer (PPO-Lagrangian), deployed and then fine-tuned on the real system with the same real-sample budget. The file documents how badly this does on hardware. SPiDR reports that domain randomization incurs 26.1x more safety violations than SPiDR on the Unitree Go1 and 6.2x more on the RaceCar.

The strongest existing method is SPiDR, which reports satisfying constraints in 100% of its real hardware tests. Those tests used reality inside its randomization support. There is no reported result on Lacuna for SPiDR on out-of-support dynamics, and that regime is exactly what we test. We will run SPiDR with its published procedure. Its penalty weight gets the same tuning budget we give our quantile level, and both are tuned on the in-support condition only. Beating SPiDR means two things on the out-of-support conditions: fewer real cost violations during adaptation, and at least equal final return.

We also compare against an online safe-exploration method applied directly on the real system. This is COX-Q, with a truncated-quantile cost critic and the same safe-baseline mixture, which tests whether a learned generator is needed at all.

The decisive ablation isolates the trajectory-level ingredient. We keep everything identical, including the real data, the calibration step and the simulator conditioning. The only change is to replace $G_\theta$ with a per-step ensemble of residual dynamics models whose disagreement feeds an upper-confidence cost. A second ablation removes the calibration correction $q_\alpha$. All methods receive the same real transitions, the same simulator compute and the same number of hyperparameter trials.

Why not just…?

Why not just refit the randomization range to the real data (system identification) and rerun SPiDR? This is the most serious competitor. When the gap comes from a misestimated parameter that the simulator does model, such as mass or friction coefficient, it may well match us. The problem is structural mismatch, such as latency or backlash that the simulator has no parameter for. There, no refit range contains reality, and the agreeing-ensemble failure returns. Our benchmark separates the two cases on purpose. If refit-plus-SPiDR matches us on the structural-mismatch conditions as well, the trajectory generator is not earning its cost, and we will say so.

Why not just use a per-step real residual ensemble with an upper-confidence cost? This is the ablation above, and it is the core scientific question. Per-step models trained on real data do fix the out-of-support problem in principle. Our hypothesis is that they still underestimate cumulative cost under temporally correlated error, because sampling independent per-step errors averages correlated drift away. The first diagnostic experiment below measures exactly this. If the per-step ensemble's coverage is as good as ours, the proposal collapses to a simpler method, which is itself a useful result.

Why not just use a recurrent or autoregressive residual model with history? A history-conditioned step model can represent correlated error, so this is a real threat. The file's evidence against it is indirect. PolyGRAD reports better long-horizon accuracy than Dreamer-v3, and much faster sampling than autoregressive diffusion, but that was on nominal unconstrained locomotion. We include a recurrent residual model with matched parameter count and judge it on bound coverage and violations, not on prediction error. We expect the advantage of segment-level diffusion to show mainly at small real-data budgets, and we will report the crossover point if one exists.

Why not just widen the randomization ranges? A wider range also inflates disagreement in regions where the simulator is right, which pushes toward the frozen, over-conservative policy that the file warns about. A wider range still cannot represent mechanisms the simulator lacks. Wide-range SPiDR is included as a variant, and its return cost will be reported.

Why not use human corrections as in TRANSIC? TRANSIC learns residual policies from teleoperation and reaches 85% success on a hard screwing task with 20 to 100 real trajectories. It requires a human ready to intervene, and it does not produce a cost bound. We see it as complementary, not as a baseline under matched conditions.

Proposed Experiments

The testbed is a controlled "reality gap" built from Safety-Gymnasium. Its Point, Car and Racecar Goal tasks and its velocity-constrained locomotion tasks serve as the simulator. A separately configured copy serves as "reality." In-support conditions perturb mass and friction within the randomization range. Parametric out-of-support conditions follow SR²'s modified MuJoCo variants, with doubled gravity and friction reduced to 30%. Structural out-of-support conditions inject actuator latency of 1 to 6 control steps, gear deadband and stick-slip friction, none of which the training simulator models. A final stage repeats the best configuration on a 1/10th-scale RaceCar like SPiDR's, if hardware is available.

The first and decisive check is diagnostic and needs no policy learning. For fixed SPiDR policies, we measure bound coverage under each method. Coverage is the fraction of held-out real segments whose true cumulative cost exceeds the predicted bound, plotted against injected latency. Our prediction is that SPiDR's penalty and the per-step residual ensemble lose coverage as latency grows, while the segment-level bound stays near its target $1-\alpha$.

The second check is the full adaptation loop. We report cumulative real cost violations during adaptation, which matters more here than final cost, and the final normalized return. We also report the number of real samples needed to reach 90% of oracle return, where the oracle is a policy trained directly in "reality." The tabular reference point from Provably Safe Sim-to-Real Transfer is a gridworld where its method had 0% unsafe iterations against 68.5% for an unconstrained sim-to-real baseline. We aim to reproduce that qualitative separation in continuous control.

The third check probes when the method fails. It sweeps horizon $H$ against PolyGRAD's reported decay, sweeps the real-data budget, and measures how often the policy freezes, defined as return below 10% of the baseline's. This shows whether the calibrated bound avoids the over-conservatism that excessive pessimism produces.

The proposal is falsified if the per-step residual ensemble or refit-plus-SPiDR matches our coverage and violation counts on the structural-mismatch conditions.