Constrained MDPs with Trajectory Constraints

Martino Bernasconi, Matteo Castiglioni, Alberto MarchesiNeurIPS 2026

TL;DR

Standard safe reinforcement learning either only cares about safety "on average" from the starting line—allowing dangerous behavior as long as it balances out across runs—or demands 100% deterministic guarantees that are often impossible in a random world. This paper introduces a middle-ground "trajectory safety" framework: no matter what messy path an agent has taken so far, its future expected costs from that exact moment onward must stay within budget. Despite proving that this requires memory of the past and is computationally intractable in general, the authors design an efficient dynamic programming algorithm that finds optimal, approximately safe policies when the number of constraints is constant.

What Problem Does This Paper Address?

In sequential decision-making, Constrained Markov Decision Processes (CMDPs) are the go-to tool for maximizing rewards while keeping costs (like fuel consumption or risk) below a threshold.

Traditionally, CMDPs fall into two extremes:

  1. Expected constraints from the start: You only require the overall average cost across all possible episodes to be safe. Imagine a navigation app trying to keep fuel use under $B$ liters/km. A classic CMDP is completely fine with burning $3B/2$ liters half the time, as long as it burns $B/2$ the other half. In high-stakes settings like robotics or autonomous driving, "averaging out" a catastrophic trajectory with a conservative one is unacceptable.
  2. Almost-sure (deterministic) constraints: Recent works demand that every single trajectory stays under budget with probability one. While great in theory, inherent randomness in the environment (like sudden wind or traffic) often makes finding any valid policy mathematically impossible.
Figure 1: Dashed arrows represent transitions (notice that arrows are not shown when transitions are determin- istic), while solid arrows denote ac- tions. Only rewards/costs different from zero are specified.

The authors propose trajectory safety to bridge this gap. At every intermediate step along any realized partial trajectory, the policy must ensure that its expected future costs from that point onward remain non-positive. As shown in Figure 1, if random chance pushes an agent down a costly path ($s_3 \to a_3$, incurring cost $c=1$), a trajectory-safe policy cannot ignore it and hope another run compensates; looking forward from $s_3$, it must plan to take recovery action $a_5$ ($c=-1$) at $s_4$ to keep future expected costs safe.

Methods

Because policies must adapt to the specific path taken, standard memoryless (Markovian) policies fail, and the number of possible histories grows exponentially with the time horizon $H$. How do you optimize over exponentially many histories without blowing up your computer?

The authors solve this in two stages:

  1. On-the-fly Characterization: Instead of computing a massive lookup table for every possible history, they recursively define polyhedral sets representing all achievable future (reward, cost) pairs from any state and step. Rather than tracking past cumulative costs (standard state augmentation), the agent tracks a target for future conditional expected costs—a target it "promises" to meet—and solves local optimization problems on the fly as the episode unfolds.
  2. Grid-Based Dynamic Programming: Because computing those exact polyhedral sets is quadratic and unrolls exponentially, the authors discretize the space of target expected costs into a finite grid with step size $\delta$. Working backward from the final step $H$ to $1$ (bottom-up dynamic programming), they approximate the achievable (reward, cost) sets as convex polytopes using linear inequalities, solving linear relaxations at each grid point. During execution, the agent simply looks up actions and next-step cost targets from these precomputed tables.

Datasets

Not discussed in the paper. (This is a purely theoretical planning paper.)

Key Insights and Ideas

  • Memory is mandatory, even for looking forward: Even though trajectory safety only constrains future expected costs from step $h$ onward, Markovian policies (which only look at the current state $s_h$) are suboptimal. Why? Because reaching $s_h$ via a costly transition at step $h-1$ creates a safety debt for the partial trajectory ending at $s_{h-1}$—forcing the agent to act differently at $s_h$ depending on how it arrived there.
  • Bucketing histories via "cost promises": While exponentially many trajectories can arrive at the same state, we don't need to distinguish all of them. We can bucket them together based on the discretized expected future cost target ($\tilde{\boldsymbol{c}}$) they need to achieve to keep prior steps safe.
  • The curse of many constraints: Adding constraints isn't just an annoyance; it fundamentally changes the complexity class. Computing even an approximately optimal, approximately safe policy is NP-hard when the number of cost constraints $m$ can be arbitrarily large.

Key Results

Because the work is theoretical, the main results are formal algorithmic guarantees for planning in a finite-horizon CMDP:

  • Optimality and $\epsilon$-Safety (Theorem 6.4): Given any allowed error $\epsilon > 0$, the proposed dynamic programming algorithm outputs a history-dependent policy that achieves at least the true optimal reward ($V^\pi \ge \text{OPT}$) while violating trajectory safety constraints by at most an additive $\epsilon$ along every possible partial trajectory.
  • Polynomial Runtime (Theorem 6.5): By setting the grid step size $\delta \approx \epsilon / (2H)$ and assuming the number of constraints $m$ is a constant, the algorithm runs in time polynomial in both $1/\epsilon$ and the size of the CMDP—cleanly bypassing the exponential blowup of trajectories and the NP-hardness of arbitrary constraints.

Limitations and Future Work

  • Planning vs. Learning: This paper strictly tackles the planning problem, assuming the MDP's transition probabilities, rewards, and cost functions are completely known in advance. Finding sample complexity bounds for learning in unknown environments is left for future work.
  • Recoverable Resources Only: The framework assumes at least one safe policy exists, meaning every reachable history must have a valid recovery path in expectation. It is well-suited for recoverable budgets (like energy or fuel replenishment), rather than irreversible failures (like crashing a drone) where strict pathwise guarantees are still needed.
  • Scaling with Constraints: Because the grid discretizes an $m$-dimensional hypercube of costs, the polynomial runtime relies heavily on the number of constraints $m$ being a small constant.

Summary updated

Abstract

We introduce a framework that models constrained MDPs subject to trajectory-wise safety constraints. These constraints require that expected future costs remain below zero conditioned to any possible trajectory---not merely in expectation from the initial state. This captures stronger and more realistic safety guarantees, which are crucial in high-stakes applications. We characterize the structure of optimal policies, and show that Markovian policies are in general suboptimal. Moreover, we show that computing approximately-safe optimal policies is NP-hard when the number of constraints can be arbitrarily large. Despite all these challenges, we provide an exact algorithmic characterization of optimal history-dependent (non-Markovian) policies, by exploiting a suitable recursive formulation of the sets of reachable reward-cost values. Then, we employ it to design a polynomial-time approximation algorithm that computes approximately-safe optimal policies by dynamic programming, when assuming a constant number of constraints.
BibTeX
@inproceedings{bernasconi2026constrained,
  author = {Martino Bernasconi and Matteo Castiglioni and Alberto Marchesi},
  title = {{Constrained MDPs with Trajectory Constraints}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=FvA1nYXCFk},
}

Loading related content...

Figure