Learning How Far to Trust a Safe World Model

Agents that learn a model of their environment can imagine the consequences of actions before taking them. In safety-critical settings this lets them predict a collision before it happens. How far ahead they imagine is a hard choice, though. Each imagined step feeds the model's own prediction back in as input, so small errors grow with every step; this is compounding model error. Imagine too far and the model "hallucinates safety," predicting a clear path through what is actually a wall. Imagine too briefly and the agent is short-sighted, missing a hazard two steps past its horizon. The right depth also changes during training. Early on the model is poor and only short rollouts should be trusted. Later the model is good and long rollouts become reliable. Current safe world-model agents fix this depth by hand.

We propose treating the imagination depth as a set of competing "experts." Each expert is the same agent's estimate of future safety cost, computed by imagining $H$ steps and then handing off to a learned cost critic, for a range of $H$. A master algorithm from online learning, of the kind built to track a moving best choice, reweights these estimates using the costs the agent actually incurs in the real environment. Two properties make this different from tuning a hyperparameter. First, the master is scored against real outcomes, not imagined ones. Second, it is penalized more for underestimating danger than for overestimating it. The target is the period that SafeDreamer leaves open: the early phase of training, when a poor world model leads to real constraint violations.

Core Claim

The bias of a world-model cost estimate is a non-stationary quantity, and the main source of that non-stationarity is the model's own improvement. The best imagination depth drifts from near zero to long as training proceeds, and it shifts again whenever the environment changes. Algorithms for dynamic regret are designed for exactly this kind of drifting best expert: they compete with the best expert at each moment rather than the best single expert overall. Such an algorithm, run over horizon-indexed cost estimates and scored on realized cost with an asymmetric loss, should achieve two things. It should cut early-training violations relative to a fixed-horizon safe world model. It should also avoid the conservatism of always using short horizons. The extra compute is negligible, because a single rollout of length 16 already contains all shorter-horizon estimates as prefixes.

Relation to Prior Work

The closest system is SafeDreamer. It trains a constrained actor-critic and a constrained planner inside a DreamerV3 latent world model, with a PID-controlled Lagrange multiplier (a penalty weight on cost that is raised or lowered automatically). Its cost targets use a fixed geometric mixture of horizons, the standard λ-return. The file notes that it suffers a cold start in which an inaccurate model and critic permit violations. We keep SafeDreamer's architecture and replace only how its cost estimate is formed. This makes it both our substrate and our main competitor. Approximate Model-Based Shielding motivates the work from the other direction. It uses a Dreamer model to look ahead and override unsafe actions, and the file reports that it suffers both from short-sightedness at short lookaheads and from degraded verification at long ones. That is the two-sided horizon trade-off we aim to resolve automatically.

On the compounding-error side, M2AC uses disagreement within an ensemble of dynamics models to mask unconfident imagined transitions in unconstrained control. It supplies our strongest alternative mechanism. It also constrains our design. Dropping mid-rollout transitions breaks the cumulative-cost bookkeeping a safety budget needs, and Pan et al. found hard-stop thresholds brittle. We therefore keep rollouts intact and reweight whole horizon-truncated estimates instead. The multi-step-objective line (Beyond Myopic World Models, When Multi-step Prediction Mitigates Compounding Error) changes how the model is trained, which is orthogonal to our work. It lengthens the trustworthy horizon, and our method should simply place more weight on long experts when such a model is used.

The method itself comes from online learning. Ader runs learners on a grid of step sizes combined by exponential weights and obtains optimal dynamic regret for unknown drift. Dynamic Regret of Online MDPs lifts the same two-layer design to policies, but assumes known transitions and no constraints. Our feedback arrives only after a window of real steps, so we follow the delayed-feedback treatment of Parameter-free Dynamic Regret with Delayed Feedback. Wei et al.'s non-stationary CMDP work is the only prior combination of master-expert methods and safety. It hedges over restart schedules in a model-free tabular setting. We instead hedge over model-based estimates in deep continuous control, and the quantity being hedged is a safety prediction rather than a learning schedule.

Mechanism

At a real state $s_t$, the agent imagines one rollout of length $H_{\max}=16$ under its current policy. For each $H\in\{0,1,2,4,8,16\}$, expert $H$ predicts the cost the agent will incur over the next $K$ real steps. It does this by summing imagined costs for $H$ steps and using the cost critic for the remaining $K-H$ steps; $H=0$ is the pure critic. Call this prediction $\hat C_t^{H}$. The master holds weights $w_t^H$ and outputs a pessimistic aggregate: a weighted upper quantile of the experts' predictions, rather than their mean. After $K$ real steps the realized cost $C_t$ is known, and each expert is charged the asymmetric pinball loss

$$\ell(\hat C^{H}_t, C_t) = \max\{\tau (C_t - \hat C^{H}_t),\ (1-\tau)(\hat C^{H}_t - C_t)\},$$

where $\tau\in(0.5,1)$ sets how much worse underestimating danger is than overestimating it. A Hedge-style master tracks the drifting best expert. Following Ader's construction, it runs over a geometric grid of its own learning rates, so it needs no tuning against an unknown rate of drift. This grid is the step-size dilemma described in the file, applied to the master itself.

The aggregate cost then replaces SafeDreamer's cost return in two places: the Lagrangian actor objective and the planner's constraint check. Everything else is held fixed, including the PID multiplier controller. Because every expert reads the same rollout, the overhead is one critic call per prefix and a $K$-step delay buffer.

The prediction is that the weights start concentrated on $H\le 2$ and migrate toward long horizons as model error falls. They should jump back to short horizons after a dynamics shift. This trajectory is itself an object of study: it gives an empirical measurement of the trustworthy horizon over the course of training.

Research Program

We first instrument SafeDreamer to log, for each horizon, the gap between predicted and realized $K$-step cost throughout training on Safety-Gymnasium. Before building anything else, this tests the premise that the best horizon actually drifts. If one horizon is best throughout, the meta-layer is unnecessary and we stop.

We then implement the master, and study the choice of $\tau$, the window $K\in\{8,16,32\}$, and the quantile versus the mean aggregate. Finally, we construct non-stationary variants in which hazard layout or friction changes abruptly mid-training. Here the drift comes from the environment, not only from learning. These variants test whether the dynamic-regret machinery adds anything beyond a slowly annealed schedule.

Baselines

The naive reference is SafeDreamer's background-planning variant (BSRP-Lag), run with its default fixed horizon and λ-return. The reported numbers come from SafeDreamer: on MetaDrive, a 100% arrival rate with average episode cost 2.2, against 14.1 for PPO-based reward shaping; on Safety-Gymnasium, a 94.3% cost reduction relative to other model-based methods. No reported result was found on Lacuna for SafeDreamer's violations during early training, which is our primary metric, so we will measure it ourselves. Beating SafeDreamer means fewer cumulative violations over the first 20% of training, with final return and final cost no worse within seed confidence intervals.

The strongest tuned competitor is the best fixed horizon chosen in hindsight by a full sweep over the same grid. We give it a tuning budget equal to all six horizons, which is six times ours. Matching it with one run is a win. Beating it on early violations shows that a moving choice beats any static one.

An uncertainty-gated variant ports M2AC's ensemble disagreement to safety. It truncates each cost estimate at the first step where disagreement passes a threshold, and its threshold receives the same sweep budget as our $\tau$. A model-free PPO-Lag from the Safety-Gymnasium suite anchors how much the world model helps at all; that paper reports a 98% violation reduction versus PPO with a 45% reward drop on velocity tasks.

Ablations isolate the key ingredients. A uniform-weight master and a fixed geometric-weight master (which reproduces the λ-return) isolate learning the weights. A symmetric loss with $\tau=0.5$ isolates asymmetry. A master scored on imagined self-consistency, rather than real costs, isolates grounding in real outcomes; we expect this last one to fail precisely during cold start. All methods share the world model, the PID controller settings, environment steps, imagination budget, and five or more seeds.

Why not just…?

Why not just use the λ-return Dreamer already has? The λ-return is a fixed geometric average over horizons. It cannot notice that the model is currently untrustworthy beyond two steps. Our fixed-geometric-weight ablation is exactly this method inside our pipeline, and a tuned-λ sweep is included. If a well-tuned λ matches us on early violations, the claim that the trustworthy horizon drifts is false, and the instrumentation stage should reveal this before any method is built.

Why not just gate horizon on ensemble disagreement? This is the real threat, because disagreement is available at every state and our feedback is delayed by $K$ steps. Its weakness is that ensemble members trained on the same sparse unsafe data can agree and still be wrong. The safety-paradox analysis in Feasible Dual Policy Iteration predicts this happens near constraint boundaries. M2AC also reports that fixed thresholds are brittle. The uncertainty-gated baseline settles the question. If it wins, the natural next step is to make disagreement-gated estimates additional experts under the same real-cost master, which is cheap to test.

Why not just use short rollouts everywhere? The best fixed horizon sweep includes $H=1,2$. AMBS documents short-sightedness at short lookaheads. We expect short horizons to be safe early but over-conservative late, losing return in the way Backward Value Functions loses return by bounding cost conservatively.

Why not just tune the PID Lagrangian better? That addresses a different problem: how strongly to penalize a given cost estimate, not whether the estimate is biased. The controller is held fixed across all arms. A hallucinated-safe estimate fools any multiplier, whatever its gains.

Proposed Experiments

The experiments use Safety-Gymnasium Point, Car, and Racecar on the Goal, Button, and Push tasks, both state-based and vision-based, plus MetaDrive. We also build non-stationary Safety-Gymnasium variants with mid-training hazard or friction changes. Metrics are cumulative real violations over training and over the first 20% of steps, final return and episode cost, and the weight trajectory over horizons.

The decisive checks are four. First, horizon-wise prediction gaps must show the best horizon moving over training; otherwise we stop. Second, the method must reduce early violations relative to both SafeDreamer and the best fixed horizon chosen in hindsight, at equal final return. Third, the master scored on imagined consistency must lose this advantage, which would show that grounding in real costs is the active ingredient. Fourth, after an abrupt dynamics shift, weights should return to short horizons within a few windows, and violations should spike less than under any fixed horizon.