Cross-Task Cost Potentials for Safer Exploration

Safe reinforcement learning methods usually promise that the final policy respects its safety budget. They say little about the thousands of crashes the agent commits while learning. A large share of those crashes happen because, at the start of each new task, the agent's estimate of "how much future danger follows from this state" is empty. It has to rediscover hazards by hitting them. We propose to give the agent a learned prior over that danger, built from other tasks. The prior enters as potential-based shaping of the safety cost: an extra per-step term of the form $\gamma\Phi(s') - \Phi(s)$, which is known not to change which policy is optimal. Because of that property, the prior can only change how the agent learns, never what it converges to. Our bet is that it changes how the agent learns in exactly the right place: the agent anticipates hazards before touching them, and it stops "forgetting" danger once it has become safe.

The second half of the idea concerns cost. Learning shaping functions through bi-level meta-learning, where an outer loop differentiates through an inner training run, is notoriously expensive. We argue that for cost potentials most of that machinery is unnecessary. A first-order regression of cost values across tasks, followed by tuning a handful of scale parameters in a tiny outer loop, should recover nearly all the benefit of full meta-gradients at a small fraction of the compute and memory. The project tests this directly, and it also identifies the regime where the cheap route breaks.

Core Claim

Constrained RL trains a policy to maximize reward subject to expected discounted cost $J_c(\pi) \le \epsilon$. Our proposal shapes each cost signal $c_i$ with a cross-task potential $\Phi_i$:

$$\tilde c_i(s,a,s') = c_i(s,a) + \gamma\,\Phi_i(s') - \Phi_i(s), \qquad \tilde J_{c_i}(\pi) = J_{c_i}(\pi) - \mathbb{E}_{s_0}[\Phi_i(s_0)].$$

Here $\gamma$ is the discount and $s_0$ the start state. The second identity follows from the telescoping sum, given $\Phi_i = 0$ at terminal states and with time-limit truncation handled by bootstrapping. It means the original budget is enforced exactly by tightening the shaped budget to $\epsilon_i - \mathbb{E}[\Phi_i(s_0)]$. No feasible policy is gained or lost.

The new claim has two parts. First, a fixed potential protects against the safety paradox identified by Breaking Safety Paradox with Feasible Dual Policy Iteration: once a policy becomes safe, its cost critic sees almost no violations and its estimates drift toward "nothing here is dangerous," which causes safety regression. With a potential in place, the critic only learns the residual $V_{c_i} - \Phi_i$. When violation data dries up, that residual decays toward zero, so the effective cost estimate decays toward the cross-task prior rather than toward zero. Second, the best $\Phi_i$ can be obtained without unrolled bi-level optimization. Reward Shaping via Meta-Learning shows that the ideal shaping potential for credit assignment is the optimal value function, which makes plain regression onto cost values a principled first-order target.

Relation to Prior Work

Three lines of work learn reward shaping with bi-level optimization. Differentiable Evolutionary Reinforcement Learning composes rewards from primitives using meta-gradients from validation performance. LECO meta-learns a modulator on intrinsic exploration bonuses. Reward Shaping via Meta-Learning uses MAML to extract a value-function potential. All three shape task reward in unconstrained problems. DERL and LECO both name inner-loop unrolling as their scaling bottleneck. We shape safety costs inside a constrained problem, and we treat the unrolling cost as something to remove rather than tolerate. That last point is motivated by Bridging Multi-Task Learning and Meta-Learning, which shows first-order multi-task training matching gradient-based meta-learning while training 23 times faster (3.7 vs. 85.6 hours on mini-ImageNet). Its evidence comes from supervised classification, so whether it transfers to RL is an empirical question we test rather than assume.

Meta-safe RL supplies our closest competitors and also constrains our design. A CMDP-within-online framework for Meta-Safe Reinforcement Learning and Online Constrained Meta-Learning meta-learn initializations and learning rates and prove sublinear task-averaged violation bounds. Sublinear bounds still permit many early violations, and neither work shapes costs. The CMDP-within-online paper also reports that plain multi-task pretraining fails when tasks are dissimilar. That negative result warns us that a regressed prior can mislead, so we build a correction for it. Safe Reinforcement Learning through Meta-learned Instincts cut adaptation violations from 75.9 to 0.05 with an evolved override network, but only on a 2D toy domain, using a genetic algorithm and with no preservation of the optimum. Our potential is gradient-learned, never overrides actions, and provably leaves the constrained optimum unchanged.

Single-level geometric methods address related symptoms at a different level. Boundary-Seeking Policy Gradient projects updates onto the constraint boundary, but handles only a single constraint. Gradient shaping for multi-constraint safe RL filters conflicting constraint gradients. Both act on the update direction once the cost critic exists; our method improves the critic's signal itself, so the two are composable rather than rivals. Finally, ROSARL shows that scalar penalties alone suffice for terminal failures. Its scope is limited to episode-ending hazards and it induces extreme risk aversion, whereas potential shaping handles non-terminal costs and adds no bias at convergence.

Research Program

The work proceeds in three stages. In the first stage, meta-training, we run a standard constrained learner (PPO-Lagrangian) on a distribution of training tasks. We then regress one network $\Phi_i(s)$ per cost signal onto discounted cost-to-go targets pooled across tasks. This step is ordinary supervised learning with no differentiation through training. Every violation incurred during meta-training is logged and reported, so the prior's own safety price is visible.

The second stage is a small outer loop. For each constraint we learn a scale $\beta_i$ that multiplies the potential, together with a shared clipping level. These few scalars are tuned on held-out validation tasks to minimize cumulative training-time cost subject to final return. With so few parameters, a one-step truncated hypergradient or even a zeroth-order search is cheap. The scale is what lets the method retreat toward $\beta_i \to 0$ when the prior transfers poorly, which is the failure mode the CMDP-within-online results predict.

The third stage is the full, expensive reference. Here we learn $\Phi_i$ end to end with an unrolled meta-gradient (LECO-style, truncated at the deepest horizon memory allows) against the same outer objective. This tells us how much performance the cheap route leaves behind.

For multiple constraints, each constraint gets its own potential and budget correction. A secondary analysis measures whether per-constraint priors reduce the cosine conflict between constraint gradients that GradS documents.

Baselines

The naive reference point is unconstrained PPO, which bounds how many violations occur with no safety mechanism at all.

The standard constrained learners are PPO-Lagrangian and CPPO-PID from the SafePO library in Safety Gymnasium. These are the strongest widely used competitors because their dual variables already adapt the reward–cost weighting automatically and cheaply. The reported figure to beat is that in velocity tasks PPO-Lag achieved a 98% reduction in safety violations relative to PPO, at the cost of a 45% drop in total reward. Beating PPO-Lag means fewer cumulative training-time violations at equal or higher final return, with final cost at or below the budget. No reported numeric result was found on Lacuna for CPPO-PID. BSPG is included for single-constraint tasks; its paper reports higher reward than CRPO with cost residual near zero on SafetyPointGoal1-v0, but no exact values were found on Lacuna for BSPG.

The strongest existing meta-safe method is Meta-SRL from the CMDP-within-online paper, which meta-learns initializations and learning rates. We run it on the same task splits with the same meta-training interaction budget. No reported numeric result was found on Lacuna for Meta-SRL on its Half-Cheetah or Humanoid suite. On MLIN's 2D grid, the bar is its reported 0.05 hazard violations against 75.9 for pure RL. ROSARL's Minmax penalty is run only on terminal-hazard variants, since that is its scope.

Three ablations isolate the key ingredients. The first initializes the cost critic from the same cross-task regression but adds no persistent potential. It tests whether the fixed residual structure, rather than the prior itself, prevents safety regression. The second removes the budget correction, to show that ignoring the start-state offset produces measurable asymptotic bias. The third pits regression with scale tuning against the full unrolled meta-gradient, to measure the cost of skipping bi-level optimization.

Fairness rules apply throughout. All methods get equal environment steps per test task and identical network sizes. Every method that uses training tasks gets the same set of meta-training tasks. Each method gets the same number of hyperparameter trials (we propose 20) on validation tasks. Wall-clock time and peak memory are reported for every arm.

Why not just…?

Why not just use PPO-Lagrangian or CPPO-PID, since the multiplier already learns the weighting? The multiplier is a single scalar that reacts only after costs have been incurred. It cannot tell the agent where danger is before the agent meets it. The Safety Gymnasium result shows the price: violations fall sharply, but reward drops 45%. Its listed limitations add dual oscillations and "safe but useless" freezing. Our method keeps the Lagrangian unchanged and only adds a cost prior, so the comparison isolates exactly what the prior contributes.

Why not just pretrain the cost critic across tasks and initialize from it? This is the most serious threat, because in exact tabular settings potential shaping and value initialization are nearly equivalent. The difference we predict appears late in training. An initialized critic can be overwritten toward zero cost once violations stop, while the potential is never overwritten. The critic-initialization ablation, run long past convergence, settles the question. If it matches us on cost regression, we will report that the prior alone carries the benefit.

Why not just learn the shaping with full meta-gradients, as DERL and LECO do? We run exactly this as an arm of the study. Our hypothesis is that it buys little over regression with scale tuning while costing much more memory and time, which both papers flag. If the unrolled version wins clearly on dissimilar tasks, that is a useful finding about when bi-level optimization is worth paying for.

Why not just meta-learn the initialization, as Meta-SRL does? Initializations erode under further training, and that paper's own evidence shows pooled pretraining failing under low task similarity. Both methods are compared on the same splits, and we also test whether the two combine.

Proposed Experiments

All experiments use Safety-Gymnasium. Task distributions are built by randomizing hazard, vase and button layouts in the Goal and Button families for Point and Car agents, with level 2 layouts held out as an out-of-distribution test. Multi-constraint tasks combine hazard costs with a velocity cost. Continuous-control transfer uses the Meta-SRL Half-Cheetah head-height and Humanoid joint-limit suite, and a sanity check uses MLIN's 2D grid. The headline metric is cumulative training-time cost per test task. We also report final return, final cost relative to budget, wall-clock time, and peak memory, with at least 10 seeds per arm.

Four checks are decisive. First, at matched final return, the potential method must cut cumulative training violations relative to PPO-Lagrangian on in-distribution layouts. Second, in extended post-convergence training, the persistent potential must show less cost regression than critic initialization; this is the direct test of the safety-paradox claim. Third, with the budget correction on, final constrained performance must match the unshaped learner, confirming that the optimum is unchanged. Fourth, regression with scale tuning must come within a small margin of the unrolled meta-gradient at a fraction of its compute, and a sweep over task similarity must show the learned scale $\beta_i$ shrinking on held-out layouts. If $\beta_i$ fails to shrink and violations rise there, the cheap route is unsafe under distribution shift, and we will report that boundary explicitly.