Counterfactual Debugging the World Model Transfer Gap

Mingxuan Li, Kai-Zhan Lee, Michael D Dennis, Elias BareinboimNeurIPS 2026

TL;DR

Reinforcement learning policies trained inside learned simulators ("world models") often fail catastrophically when deployed in reality, yet pinpointing why is notoriously hard because benign visual glitches look just as anomalous as fatal physics errors. This paper introduces counterfactual debugging, a causal method that treats every time step in a trajectory like a suspect in a lineup—systematically swapping reality with simulation to isolate the exact moments responsible for a drop in performance. Using a clever divide-and-conquer search, it debugs trajectories up to a million steps long, telling engineers precisely where their world model needs fixing rather than drowning them in false alarms.

What Problem Does This Paper Address?

In reinforcement learning (RL), a world model is a learned internal simulator of an environment's physics and rewards. Agents can practice inside these "imagined" worlds before acting in reality. However, every learned model is slightly wrong. When an agent acing the simulator stumbles in the real world, we call that drop in score the world model transfer gap.

The catch is that not all model errors matter. A simulator might hallucinate background clouds (harmless) while subtly mispredicting tire friction on a single turn (catastrophic). Standard diagnostics—like average prediction error, pixel comparisons, or static explainability tools like SHAP and LIME—flag every discrepancy equally and ignore how early errors ripple forward in time.

Figure 1: Which transition discrepancy should be blamed for the performance degradation? A PPO policy on Atari Pong running under a world model (green) scores full mark, 21, while the same policy running against a turbulent “real world", where random blackouts occlude the screen (red) only scores 15. Crucially, most of the occluded frames have little bearing on the final outcome, only a small, hard-to-identify subset is causally responsible for the collapse. In this example, somewhat surprisingly, only two of the blackout frames are causally responsible for the performance degradation that happens more than 50 steps later. See more details in Sec. 4.1.

Consider an Atari Pong game where a faulty camera randomly blacks out 15 frames over an 1,860-step episode, dropping the agent's score from 21 to 15. Visually, all 15 blackouts look identical. In reality, only two of them caused the lost points—and the actual score loss didn't even happen until more than 50 steps after the blackout! How do we automatically find those needles in the haystack?

Figure 2: Observation blackout on Pong. Top row: the world model Mwm observations. Bottom row: real world Menv has blackouts at t = 536 but score loss does not surface until t = 600.

Methods

To separate harmless quirks from fatal flaws, the authors fuse Structural Causal Models with cooperative game theory (Shapley values):

  • Time Steps as Players (Novel Framing): Instead of attributing credit to an agent's actions or pixel features (standard practice), the authors treat each time step's dynamics selector—whether that step follows the real world's rules or the world model's rules—as a player in a game.
  • Counterfactual Hybrid Rollouts: Given one failed real-world trajectory, the method asks: "What score would the agent have gotten if, at a specific subset of steps, reality had behaved like the world model instead?" Crucially, this never requires resetting or re-querying the real world; all counterfactual branches are simulated purely inside the world model.
  • $\text{RECURSIVE-}\phi$ (Divide-and-Conquer Speedup): Computing exact Shapley values across $T$ steps normally takes $O(2^T)$ simulations—utterly intractable for long episodes. Because causal failures are usually sparse ($K \ll T$), $\text{RECURSIVE-}\phi$ groups contiguous steps into coarse blocks (e.g., splitting the timeline in half). If swapping an entire block changes nothing, that whole chunk of history is pruned. Surviving blocks are recursively split until the exact culprit steps are isolated, slashing complexity to $O(2^K \log T)$.

Datasets

Rather than static datasets, the method is evaluated across four interactive RL benchmarks:

  • Sim-to-Sim Controlled Shifts: Atari (Pong with sensor blackouts), ProcGen (CoinRun modified with "poisonous coins" that flip reward signs and "windy days" that shorten jumps), and a newly introduced custom MiniGrid environment (CenterGoal5x5) designed with loopable paths to test scaling from 100 up to 1 million steps.
  • Pretrained Neural World Models: Tested against real simulator physics using DIAMOND (a diffusion-based world model) on Atari Pong, and LeWM (a JEPA-based latent world model) on OGBench Cube robotic manipulation.

Key Insights and Ideas

  • Prediction error is a terrible proxy for causal impact: In neural world models like DIAMOND and LeWM, the steps with the highest one-step pixel or latent prediction error rarely caused the task failure; fixing them left the bad outcome intact, whereas fixing a single step flagged by $\text{RECURSIVE-}\phi$ repaired the trajectory.
  • Errors compound rather than cancel: Across dozens of neural world model rollouts, performance gaps were consistently one-sided (e.g., DIAMOND over-predicted Pong scores by +23.9 points over 2,000 steps). This empirical insight validates a core mathematical assumption behind $\text{RECURSIVE-}\phi$: grouping steps into blocks won't hide errors via accidental cancellation.
  • Temporal distance breaks standard credit assignment: Classic RL tools like eligibility traces weight errors by how close in time they are to a lost reward. Counterfactual debugging ignores the clock and tracks causal propagation, effortlessly linking a sensor glitch at step 536 to a missed ball at step 600.

Key Results

Attribution spikes across 1,860 steps of Pong; only Recursive-phi isolates the two true causal steps without noise.

  • Pinpoint Accuracy: On Pong (up to 3,000 steps) and both CoinRun variants (up to 1,000 steps), $\text{RECURSIVE-}\phi$ explained 100% of the transfer gap across all seeds. Naive non-recursive Shapley ($\text{FLAT-}\phi$), SHAP, and LIME collapsed to 0–30% as trajectories lengthened.
  • Massive Sample Efficiency: On 300-step Pong, $\text{RECURSIVE-}\phi$ needed just 34 rollouts vs. 4,200 for $\text{FLAT-}\phi$. On MiniGrid, scaling the horizon $10,000\times$ (from 100 to 1,000,000 steps) increased $\text{RECURSIVE-}\phi$'s rollout budget by less than $5\times$, while $\text{FLAT-}\phi$ blew past $10^5$ rollouts at just 500 steps.
  • Sparse Neural Repairs: Injecting real transitions at steps ranked by $\text{RECURSIVE-}\phi$ repaired DIAMOND's Pong hallucinations in 2.7 ± 1.7 injections (vs. 6.0 for frame-error and 7.3 for latent-error rankings).

Limitations and Future Work

The theoretical guarantees of $\text{RECURSIVE-}\phi$'s coarse-to-fine pruning rely on two conditions: causal sparsity (only a small number of steps $K \ll T$ drive the failure) and sign consistency (world model errors compound in the same direction rather than canceling each other out within a block—for instance, one bug costing a point while another accidentally gifts a point). Additionally, on less accurate models like LeWM where errors accumulate rapidly, more injections were needed to repair failures. For future work, the authors highlight using these localized, high-attribution time steps as principled targets to guide continual learning, targeted data collection, and calibration in world models.

Summary updated

Abstract

Policies achieving strong performance in simulators or learned world models can fail when deployed into the real environment. While there must be environmental differences that account for these failures, not all differences are equally responsible. A benign error of irrelevant visual details may co-exist with a failure to predict a single critical transition causing an inevitable catastrophic failure. In this paper, we introduce \emph{counterfactual debugging} as an approach for \emph{world model transfer gap attribution} to identify the time steps whose transition or reward errors are \emph{causally responsible} for a performance degradation exhibited in a real trajectory, rather than only visually or statistically different. We develop a scalable algorithm for computing these attributions that exploits the sparsity of causal errors by recursively divide-and-conquer, significantly reducing computational costs, achieving an exponential speedup while maintaining a high attribution quality. Experiments across distinct environments with various common world model failures (observation corruption, reward misprediction, and physics violations) demonstrate that counterfactual debugging correctly identifies the errors that cause the transfer gap, providing principled, actionable insights for continual learning in world models.
BibTeX
@inproceedings{li2026counterfactual,
  author = {Mingxuan Li and Kai-Zhan Lee and Michael D Dennis and Elias Bareinboim},
  title = {{Counterfactual Debugging the World Model Transfer Gap}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=5SUeNVcFWj},
}

Loading related content...

Figure