Safe Flow Q-Learning

Offline Safe Reinforcement Learning with Reachability-Based Flow Policies

Indian Institute of Science (IISc), India
* denotes equal contribution
SafeFQL framework overview
SafeFQL in one picture. A multi-step flow-matching policy is trained on offline data by behavioral cloning and distilled into a one-step actor. A reward critic $Q_r$ and a reachability-based safety critic $Q_c$ then gate that actor: when the predicted action is feasible the update maximizes reward, when it is infeasible the update recovers feasibility. At deployment only the one-step actor runs — a single forward pass, no ODE integration, no rejection sampling.

Overview

SafeFQL (Safe Flow Q-Learning) is a state-of-the-art method for offline safe reinforcement learning. It pairs a Hamilton–Jacobi reachability-based safety critic with a distilled one-step flow policy, so it enforces hard, state-wise safety constraints — not just an expected-cost budget — while deploying with a single forward pass and no rejection sampling. Across Safe Boat Navigation and the Safety Gymnasium velocity-constrained benchmarks, SafeFQL attains the lowest constraint-violation rate of any evaluated method while matching or exceeding the reward of prior safe generative RL baselines such as FISOR and SafeIFQL, at roughly 2.5× lower inference latency.

  • Hard safety, not soft cost. SafeFQL replaces expected-cost budgets with a Hamilton–Jacobi reachability-style safety critic trained by a max-backup Bellman recursion, so its sign tells you whether a state–action pair is feasible for all future time.
  • Expressive policies without iterative inference. A flow-matching behavior teacher is distilled into a one-step actor, so the deployed policy is a single network forward pass — no denoising loop and no rejection sampling.
  • A feasibility gate instead of a Lagrangian. Reward and safety never fight each other in the actor loss: an exclusive gate switches between reward maximization and feasibility recovery, removing the multiplier that soft-constraint methods must hand-tune per task.
0.14s
inference per episode
(vs. 0.35s for flow/diffusion baselines)
2.5×
inference speedup over
generative safe-RL baselines
N = 1
action samples needed for
100% safety rate on boat navigation

Challenge

Offline safe RL asks for a reward-maximizing policy from a fixed dataset $\mathcal{D} = \{(x_t, a_t, r_t, \ell_t, x_{t+1})\}$, under a constraint that must hold at every timestep. With a failure set $\mathcal{F} = \{x : \ell(x) > 0\}$, the objective is

$$ \sup_{\pi}\ \Big[\sum_{k=0}^{\infty} \gamma^k r(x_k)\ \Big|\ x_0 = x\Big] \qquad \text{s.t.}\quad x_t \notin \mathcal{F},\ \ \forall t \ge 0 . $$

This is a state-wise hard constraint, and two standard families of methods struggle with it for different reasons.

Soft-cost methods lose the guarantee. Lagrangian and cost-budget approaches (CPQ, COptiDICE, C2IQL, BEAR-Lag) constrain $\mathbb{E}[\sum_t \gamma^t c(x_t)] \le l$. Satisfying a constraint in expectation is not the same as never entering $\mathcal{F}$, the threshold $l$ becomes a per-task hyperparameter, and safety-critical transitions are rare in static datasets — exactly where the reward/safety trade-off is most brittle.

Generative safe policies pay for it at inference. Diffusion- and flow-based policies (FISOR, SafeIFQL) capture multimodal behavior well, but sampling costs $O(T)$ network evaluations per action, and in practice they need rejection sampling over $N$ candidates to reliably land on a safe, high-value action. That is $O(NT)$ forward passes inside a real-time control loop. Training a flow policy with RL directly is not a fix either: it requires backpropagating through the entire iterative generation process.

Idea

SafeFQL keeps the decoupling principle of Flow Q-Learning — critics, behavior model, and deployed actor each trained by their own objective — and extends it with a second critic whose semantics are governed by worst-case reachability rather than cumulative discounted cost.

1. A safety critic with a meaningful sign

Instead of a cumulative cost Q-function, $Q_c$ approximates the Hamilton–Jacobi feasibility value $V^*_\ell(x_0) = \min_\pi \max_{t \ge 0} \ell(x_t)$ through a max-backup Bellman recursion:

$$ y_c(x, a, x') = \max\big\{\, \ell(x),\ \gamma\, \bar V_c(x') \,\big\}. $$

Taking the maximum — rather than a sum — propagates the worst safety margin at any future time backwards to the present. So $Q_c(x,a) < 0$ means not just "$x$ is safe now" but "the predicted future evolution stays safe too", and $Q_c(x,a) \ge 0$ predicts eventual entry into $\mathcal{F}$. Because the backup is a max, pessimism has to be applied consistently: SafeFQL uses two safety Q-networks and takes $\bar V_c(x') = \max\{Q_c^{(1)}, Q_c^{(2)}\}$, avoiding overoptimistic feasibility estimates at out-of-distribution next states.

2. Expressiveness from a teacher, speed from a student

A conditional flow-matching model $\mu_\theta$ is trained purely by behavioral cloning — no critic signal enters its loss, which keeps that stage unconditionally stable. A deterministic one-step actor $\mu_\omega(x, z)$ is then distilled from it, $\mathcal{L}_{\text{distill}}(\omega) = \mathbb{E}\big[\|\mu_\omega(x,z) - \bar\mu_\theta(x,z)\|_2^2\big]$, which doubles as a behavior regularizer anchoring the actor to the dataset support. The one-step actor is the only component queried at deployment.

3. A gate, not a trade-off

The natural baseline adds a Lagrangian penalty, $-Q_r + \eta \max(0, Q_c)$. The two terms are commensurate in magnitude, so near the feasibility boundary a large reward gradient can simply outvote the safety term — and the right $\eta$ is not knowable without online interaction. SafeFQL instead enforces strict priority with a binary gate $\zeta(x,z) = \mathbb{I}\{Q_c(x, \mu_\omega(x,z)) < 0\}$:

$$ \mathcal{L}_{\text{actor}}(\omega) = \lambda \mathcal{L}_{\text{distill}}(\omega) + \mathbb{E}_{(x,z)}\Big[\underbrace{\zeta \cdot \big(-Q_r(x, a_\omega)\big)}_{\text{feasible: maximize reward}} + \underbrace{(1-\zeta) \cdot \max\big(0, Q_c(x, a_\omega)\big)}_{\text{infeasible: recover feasibility}}\Big]. $$

The two objectives are mutually exclusive by construction, so reward and safety gradients are never active in opposing directions at the same state. The distillation term stays on in both regimes as a universal behavioral anchor.

Click to see the full algorithm

Training runs in three sequentially dependent phases; within each phase all networks train in parallel to convergence.

Phase 1 — Critic learning. Reward critics $(Q_r, V_r)$ follow IQL: $V_r$ is fit with the expectile loss $\mathcal{L}_\tau(u) = |\tau - \mathbb{I}(u<0)|u^2$ against in-sample Q-values, and $Q_r$ regresses onto $y_r = r + \gamma \bar V_r(x')$. The safety pair $(Q_c, V_c)$ uses the same expectile machinery on the safety residual, but with $\tau < 0.5$ so $V_c$ tracks the lower quantile — a conservative approximation of the feasibility boundary — and with the max-backup target $y_c$ above. Target networks are updated by EMA. All critic learning stays inside the support of $\mathcal{D}$, so no out-of-distribution action queries are needed.

Phase 2 — Flow teacher. Given $x \sim \mathcal{D}$, $z \sim \mathcal{N}(0,I)$, $t \sim \mathcal{U}[0,1]$ and the straight-line interpolant $x_t = (1-t)z + ta$, the velocity field is trained by regression: $\mathcal{L}_{\text{flow}}(\theta) = \mathbb{E}\big[\|\mu_\theta(x, x_t, t) - (a - z)\|_2^2\big]$.

Phase 3 — Feasibility-gated actor. Each step samples $(x, z) \sim \mathcal{D} \times \mathcal{N}(0,I)$, computes $a_\omega = \mu_\omega(x,z)$, evaluates the gate $\zeta$, and minimizes $\mathcal{L}_{\text{actor}}$. A fresh $z$ per step gives the induced stochastic policy $\pi_\omega$ coverage of the action distribution, avoiding mode collapse under the distillation constraint — no replay buffer of policy actions is required.

Experiments

Tasks and baselines

Safe Boat Navigation is a custom 2D collision-avoidance task: a point-mass boat crosses a river whose drift velocity varies with the $y$-coordinate, and must bypass obstacles despite that drift. Safety Gymnasium covers the Safe Velocity suite on Hopper, HalfCheetah, Swimmer, Walker2D and Ant, where the agent maximizes reward while holding its speed below a threshold; these use the standard DSRL datasets. Every method is evaluated from a fixed set of 500 randomly sampled safe initial states per environment, across 5 seeds.

Baselines span both families discussed above: constrained offline RL (BEAR-Lag, CPQ, COptiDICE, C2IQL) and safe generative policies (FISOR, SafeIFQL), the latter evaluated with rejection sampling at $N = 16$.

Safety and reward

Reward and cost across six environments for all methods
Evaluation results (mean $\pm$ std dev over 5 seeds). SafeFQL attains the lowest cost in every environment while keeping the highest reward among methods with comparable cost. Methods marked (R.S.) use rejection sampling with $N = 16$ at evaluation time; SafeFQL does not.

On Safe Boat Navigation, SafeFQL improves reward over all baselines while maintaining zero violations across evaluation episodes. The pattern holds on the high-dimensional Safety Gymnasium tasks: near-zero cost with reward competitive against methods that achieve it only by violating constraints. Expected-cost baselines split into two failure modes — BEAR-Lag, CPQ and COptiDICE sacrifice reward without strictly enforcing safety, while C2IQL earns high reward at inconsistent cost.

How many action samples do you need?

Safety rate versus rejection sampling budget N
Action sampling efficiency on Safe Boat Navigation. FISOR and SafeIFQL need a large candidate budget before their safety rate approaches SafeFQL's; SafeFQL reaches 100% at $N = 1$, because the feasibility gate is baked into the actor rather than applied as a test-time filter.

This is the practical consequence of the design: FISOR and SafeIFQL do account for worst-case safety, but they never learn a single optimal action — they generate candidates and filter. SafeFQL emits the action directly.

What does it cost?

Training and inference compute time comparison
Computation time (mean $\pm$ std dev over 5 runs). SafeFQL trains longer — 128s vs. 113s (FISOR) and 64s (SafeIFQL) — and recovers that cost immediately at deployment: 0.14s per episode against 0.33–0.35s for the baselines at their working $N$.

Even at $N = 1$, FISOR and SafeIFQL remain at 0.21–0.24s, because the multi-step denoising or integration process persists whether or not rejection sampling is enabled. SafeFQL's one-time training overhead buys a policy that fits inside a high-frequency real-time control loop.

Limitations

The gate $\zeta$ is a hard indicator over the safety critic, which can in principle produce a non-smooth loss landscape and occasionally affect training stability. Continuous masking functions or soft Lagrangian relaxations are a natural refinement, at the cost of reintroducing hyperparameters that need tuning. SafeFQL is evaluated in the offline setting and does not claim online-training safety guarantees.

Frequently Asked Questions

What is SafeFQL?

SafeFQL (Safe Flow Q-Learning) is a state-of-the-art algorithm for offline safe reinforcement learning. Given a fixed dataset of trajectories, it trains a policy that maximizes reward while keeping a hard, state-wise safety constraint — never entering a defined failure region — without any online interaction with the environment.

How is SafeFQL different from other safe offline RL methods?

Prior offline safe RL splits into two families. Lagrangian / cost-budget methods (BEAR-Lag, CPQ, COptiDICE, C2IQL) only enforce safety in expectation, which is not the same as never entering the failure set. Safe generative policies (FISOR, SafeIFQL) enforce worst-case safety but need multi-step diffusion or flow sampling plus rejection sampling at inference, which is expensive in a real-time control loop. SafeFQL replaces both: a Hamilton–Jacobi reachability-based safety critic gives a hard feasibility signal, and that signal gates a distilled one-step flow policy, so no rejection sampling is needed at deployment.

What is Hamilton-Jacobi reachability, and why does SafeFQL use it?

Hamilton–Jacobi (HJ) reachability analysis computes the worst-case future value of a safety margin along a trajectory, rather than its expected discounted sum. SafeFQL learns this quantity offline with a max-backup Bellman recursion, so its safety critic $Q_c$ has a directly interpretable sign: $Q_c < 0$ means the predicted future stays safe, $Q_c \ge 0$ predicts eventual constraint violation. This gives a hard feasibility gate instead of a tunable Lagrange multiplier.

Is SafeFQL open source?

Yes. The official implementation, built on JAX and adapted from FQL, is available at github.com/tayalmanan28/safe-fql, along with training configs, environments, and the offline datasets used in the paper.

Where was SafeFQL published?

SafeFQL appears in the Reinforcement Learning Journal (Volume 7, 2026) and was presented at the 3rd Reinforcement Learning Conference (RLC), 2026. The paper is also available on arXiv and OpenReview.

How do I cite SafeFQL?

Use the BibTeX entry below, or see the GitHub repository for an up-to-date citation.

Citation

@article{tayal2026safe,
    title={Safe Flow Q-Learning: Offline Safe Reinforcement Learning
           with Reachability-Based Flow Policies},
    author={Mumuksh Tayal and Manan Tayal and Ravi Prakash},
    journal={Reinforcement Learning Journal},
    volume={7},
    year={2026}
}