Temporal Consistency Improves Generalization in Contextual Offline Meta Reinforcement Learning

Mohammadreza Nakhaeinezhad, Aidan Scannell, Kevin Sebastian Luck, Joni PajarinenNeurIPS 2026

TL;DR

Teaching a reinforcement learning agent to adapt to brand-new tasks solely from static, historical datasets is notoriously difficult because the agent has to figure out what task it is doing without explicit labels. This paper shows that forcing the agent to predict multiple steps into the future within a compressed "latent" mental space—rather than reconstructing raw observations or just playing spot-the-difference between tasks—unlocks vastly superior task understanding. The result is an agent that generalizes to unseen challenges faster, cleaner, and with stronger theoretical guarantees.

What Problem Does This Paper Address?

Imagine trying to learn how to drive every vehicle on Earth—sports cars, icy-road sedans, heavy trucks—solely by watching dashcam footage, and then being dropped into a mystery vehicle and expected to drive it immediately. This is the core challenge of Offline Meta-Reinforcement Learning (OMRL): learning a master policy from static datasets of related tasks so an agent can rapidly adapt to unseen tasks at test time.

Because test tasks don't come with handy name tags, agents use context encoders to read recent history (states, actions, rewards) and compress it into a latent vector $\mathbf{z}$—an implicit "task representation."

Existing methods stumble on how to train this encoder:

  1. Contrastive learning teaches the encoder to pull representations from the same task together and push different ones apart. It’s great at telling Task A from Task B, but terrible at capturing the actual physics or reward rules that make them different.
  2. Reconstruction forces the model to predict the exact next raw state. However, one-step raw state predictions get bogged down in irrelevant details and fail to capture long-horizon, task-specific dynamics.

How do we learn a task representation $\mathbf{z}$ that actually understands how a task works over time, without explicit supervision?

Methods

The authors bridge context-based OMRL with self-predictive world models. Instead of reconstructing noisy raw observations, they map states $\mathbf{s}_t$ into a compact latent state $\mathbf{x}_t$ and enforce multi-step temporal consistency in that latent space.

Figure 1: Contextual World Model. Left: A context encoder Eθ maps transitions from each task to a task representation z, which serves as an implicit task identifier. Middle: An observation encoder maps observations st to latent vectors xt. A task-conditioned latent dynamics model Dϕ predicts future latent states given the current latent state, action, and task representation. The world model is trained using multi-step temporal consistency. Right: An offline policy is trained using the latent states xt and task representation z.

Here is what is novel: the authors jointly train the context encoder alongside a task-conditioned latent world model (comprising an observation encoder, latent dynamics model, and reward predictor). Given a starting latent state $\mathbf{x}_t$, a sequence of actions, and the inferred task vector $\mathbf{z}$, the dynamics model unrolls multiple steps into the future, predicting future latent states and rewards. Its predictions are checked against target latent states generated by a slowly updating (EMA) copy of the observation encoder, optionally paired with a contrastive loss (InfoNCE) for extra task sharpness.

Crucially, the world model isn't even needed for planning at test time—it acts purely as a representation-learning crucible. Once the encoders are forged, a standard offline RL algorithm—Implicit Q-Learning (IQL)—trains the policy and value functions directly inside this clean, learned latent space $(\mathbf{x}_t, \mathbf{z})$.

Datasets

The authors generate offline datasets by training separate Dropout Q-learning (DroQ) agents per task over 1M steps, collecting 1,000 trajectories per task spanning random to near-expert behavior. They evaluate across three standard benchmark suites (no new benchmarks are introduced, though task splits test both in-distribution and out-of-distribution variation factors):

  • MuJoCo & Contextual DeepMind Control (DMC): 9 environments total, using 20 training tasks, 10 in-distribution test tasks, and 10 out-of-distribution test tasks (e.g., varying torso length and target speed).
  • Meta-World: Standard robotic manipulation suites—ML1 (goal generalization), ML10 (10 train / 5 unseen test environments), and ML45 (45 train / 5 unseen test environments).

Key Insights and Ideas

  • Control doesn't require reconstruction: Backed by a theoretical value-error bound (building on the simulation lemma), the authors prove you don't need to reconstruct raw observations $\mathbf{s}_t$ to learn an optimal policy—preserving information sufficient to predict future latent states and rewards is enough.
  • Task inference is the true bottleneck: By decomposing value estimation error into abstraction error, world-model error, and task-inference error, empirical probes reveal that task-inference error dominates. Figuring out which rules apply right now is harder than modeling the physics themselves—and joint temporal consistency drives all three errors down simultaneously.
Figure 4: Estimating different error sources. Joint training of the context encoder and world model reduces all error terms, with task error dominating; their sum upper-bounds the temporal consistency loss. Abstraction error arises from mapping states to a latent space, model error reflects world model accuracy, and task error measures how well the context encoder identifies the task. Shaded regions denote 95% confidence intervals over three random seeds.
  • Temporal consistency prevents "brain rot" in neural networks: Compared to reconstruction, multi-step latent prediction keeps the context encoder's dormant neuron ratio low and its matrix rank high, meaning the network uses its full expressive capacity rather than collapsing into redundant features.
  • Complementary forces: Temporal consistency naturally disentangles underlying physical task factors (like speed vs. body length), while contrastive learning sharpens task distinguishability. Combining them (TC + InfoNCE) gives the best of both worlds.
Figure 2: Disentanglement metrics (DCI, InfoMEC) for the Cheetah-length-speed (LS) environment. Temporal consistency disentangles the variation factors more effectively, while contrastive learning enhances task distinguishability. TC denotes training the context encoder solely with the temporal consistency objective, and AR denotes auto-regression. Averaged over 6 random seeds.

Key Results

  • Superior Few-Shot Generalization: Across 9 MuJoCo/DMC environments, TC + InfoNCE achieves the highest Interquartile Mean (IQM) normalized return (~94, beating reconstruction and contrastive baselines like FOCAL, CSRO, and UNICORN, which cluster around 80–90) and the lowest optimality gap (~17).
  • Robotic Manipulation: Across 30 Meta-World environments, TC + InfoNCE pushes IQM success rates to ~88% (compared to ~77–84% for baselines) while cutting the optimality gap down to ~21.
  • Faster Overall Convergence: Although unrolling multi-step predictions makes each individual training step slightly heavier, the richer learning signal allows the framework to converge in far fewer iterations, resulting in faster end-to-end wall-clock training.

Limitations and Future Work

  • Shared State and Action Spaces: The current setup assumes all tasks share identical state and action dimensions. Extending latent temporal consistency to handle cross-embodiment tasks with varying morphologies is left for future work.
  • State-Only Inputs: All experiments use low-dimensional proprioceptive state vectors rather than raw pixels, though the authors note the observation encoder could naturally be swapped for a CNN or ViT to handle visual observations.
  • Unseen Environments Remain Tough: On Meta-World ML10 and ML45, while the method outperforms baselines, generalizing zero/few-shot to completely novel manipulation environments without task IDs remains challenging across the board.

Summary updated

Abstract

Offline meta-reinforcement learning seeks to learn a policy that generalizes to new related tasks online. Context-based methods infer a task representation from transition histories, yet learning an effective task representation without supervision remains challenging. Existing methods relying on contrastive learning learn discriminative task representations, but fail to identify task-specific dynamics, while relying on reconstruction can be insufficient to model long-horizon dependencies, limiting generalization to new tasks. We investigate the impact of temporal consistency in latent space on task representation learning, showing that enforcing multi-step predictions in latent space encourages task representations that are able to capture task-dependent dynamics while preventing representation collapse. We provide theoretical analysis characterizing sources of error in value estimation and show through extensive experiments on MuJoCo, Contextual DeepMind Control, and MetaWorld benchmarks that temporal consistency significantly improves both zero-shot and few-shot generalization. Code is available at [https://github.com/MohammadrezaNakhaei/SPC](https://github.com/MohammadrezaNakhaei/SPC).
BibTeX
@inproceedings{nakhaeinezhad2026temporal,
  author = {Mohammadreza Nakhaeinezhad and Aidan Scannell and Kevin Sebastian Luck and Joni Pajarinen},
  title = {{Temporal Consistency Improves Generalization in Contextual Offline Meta Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=KOlHCpKZ40},
}

Loading related content...

Figure