Per-State Safety Constraints That Stay Linear in the Number of Action Branches

Robots with many joints pose two problems for reinforcement learning at the same time. If each of $D$ joints can choose among $K$ discrete torque levels, the agent faces $K^D$ joint actions. The fix for this is action branching, which predicts one small head of $K$ values per joint on top of a shared network. The second problem is that the agent must not break hardware while it learns. The methods that keep an agent safe during training, not just at the end of it, do so by solving a small optimization over all actions at every step. With $K^D$ actions that optimization is hopeless. The methods that avoid it are on-policy: they throw away their data after each update, so they need millions of fresh, possibly unsafe, interactions.

We propose a safety layer for branched agents that keeps every step's safety check linear in $D \cdot K$. The idea is that, once the cost critic is factored the same way as the reward critic, the per-state "best safe action" problem stops being a search over $K^D$ joint actions. It becomes a multiple-choice knapsack: pick one bin per joint, maximize summed reward advantage, and keep summed cost advantage under the remaining budget. Its linear relaxation is solved exactly by a one-dimensional search over a single per-state price on cost. The optimum randomizes at most one joint. Joints the factored cost model cannot capture, such as collisions that depend on several joints together, are handled by checking the single chosen joint action with a joint cost model and raising the price if it fails. Because the agent is off-policy Q-learning with replay, the same mechanism also attacks the sample cost of current safe RL methods.

Core Claim

Coupling between action dimensions under a safety constraint does not require a coupled action search. It can be carried by one scalar per state, the price $\mu(s)$ on cost, while each branch still chooses its own bin independently given that price. Concretely, let $V_c(s)$ be a state cost value and $A^c_d(s,a_d)$ the cost advantages of branch $d$, built like the reward advantages $A^r_d(s,a_d)$ of the branching dueling network. Let $b(s)$ be the remaining budget, meaning the cost limit minus the cost already incurred in the episode. Let $m(s)$ be a pessimism margin. The per-state problem is then

$$\max_{a_1,\dots,a_D} \sum_{d=1}^{D} A^r_d(s,a_d) \quad \text{s.t.} \quad V_c(s) + \sum_{d=1}^{D} A^c_d(s,a_d) \le b(s) - m(s).$$

For a fixed price $\mu \ge 0$, branch $d$ simply takes $\arg\max_{a_d} A^r_d(s,a_d) - \mu A^c_d(s,a_d)$. The feasible $\mu$ is found by bisection over at most $DK$ breakpoints, at a cost of $O(DK\log(DK))$ per step. This follows the standard result that the linear relaxation of a multiple-choice knapsack has at most one fractional class. The resulting safe stochastic policy mixes two bins in one branch and is deterministic elsewhere.

What is new is three things together: a per-state constraint inherited from the backward-value-function view, a factored solver that avoids the $K^D$ blow-up, and a joint verification step that restores correctness when costs do not add up across joints.

Relation to Prior Work

Our architecture builds on the branching dueling Q-network of Action Branching Architectures for Deep Reinforcement Learning. That paper factors the action space into per-dimension advantage heads over a shared trunk and reaches the 17-joint Humanoid with $33^{17}$ joint actions. It has no notion of cost. Its ablation, in which heads without a shared trunk fail, tells us to share the trunk across reward and cost heads as well. Branching Reinforcement Learning gives polynomial regret for tree-structured branching dynamics in the tabular, unconstrained case. It motivates expecting factorization to help sample complexity, but supplies no safety machinery.

The safety half comes from two papers that motivate the proposal and also show where it breaks.

  • Constrained Markov Decision Processes via Backward Value Functions turns a trajectory-level cost budget into per-state constraints by tracking cost-so-far. It solves a per-state linear program over actions and enforces the constraint consistently during training. We reuse this reduction. Because our agent acts online, we substitute the realized accumulated cost for the estimated cost-so-far. We replace the $K^D$-variable linear program with the factored knapsack solve.
  • Learning Policies with Zero or Bounded Constraint Violation for Constrained MDPs obtains zero or $O(1)$ violations by being optimistic about reward and pessimistic about cost. Its linear programs have $\Theta(|S||A|H)$ variables, which makes them exponential in $D$ for multi-joint systems. We borrow its pessimism in the margin $m(s)$. We use its exact solver as a tabular reference for how much our factorization loses.

The proposal also responds to three constraints from prior work.

Research Program

Agent. The agent is a branching dueling Q-network with two sets of heads on a shared trunk: reward advantages with $V_r(s)$, and cost advantages with $V_c(s)$. Both are trained off-policy from one replay buffer, following the replay idea of Programming Robots Using Reinforcement Learning and Teaching. We use the branch-wise targets and $1/(D+1)$ gradient rescaling from the branching paper.

Joint verification. A small residual cost network $\rho(s,a)$ takes the full joint action and is trained on replay to predict the gap between the realized cost return and the additive estimate. It is never searched over; it only scores the single action the knapsack solver proposes. If $V_c + \sum_d A^c_d + \rho$ exceeds the allowance, $\mu$ is raised to the next breakpoint and the solve repeats. This loop costs a handful of network evaluations, not $K^D$.

Margin. The margin $m(s)$ is the disagreement of a small ensemble of cost heads, which shrinks as data accumulates, in the spirit of the decaying margins of the optimistic-pessimism work. When no $\mu$ is feasible, each branch takes its minimum-cost bin.

Analysis. We will characterize when the factored solve is exact. It is exact when per-step cost is additive across joints, as with summed actuator power. We will bound the extra violation in terms of the residual model's error.

Tabular study. In small factored constrained MDPs, the exact joint linear program from the zero-violation paper is solvable. There we can measure the suboptimality and violation gap of factorization as $D$ grows.

Baselines

Naive reference points. The first is unconstrained BDQ, which shows what safety costs. The second is BDQ with a fixed reward penalty for cost, tuned over a grid of penalty weights. This is the "just shape the reward" reference. Multi-Constraint Safe RL with Objective Suppression argues it fails because high-reward agents "buy" their way into danger. Our own grid will show whether that holds here.

Strongest existing on-policy method. On HumanoidCircle this is FOCOPS. First Order Constrained Optimization in Policy Space reports a reward of 1106.1 there, against 671.0 for CPO and 697.5 for TRPO-Lagrangian, with cost within the limit of 50. It is the strongest competitor because it handles constraints natively in continuous space with first-order updates. We run it from the SafePO implementations in Safety Gymnasium, alongside PPO-Lagrangian and the PID-Lagrangian variant. Every method gets the same environment-step budget, the same cost limit, and an equal number of hyperparameter-search runs.

Strongest existing off-policy method. This is the cost-constrained optimistic method of Off-Policy Safe Reinforcement Learning with Cost-Constrained Optimistic Exploration. It tests whether off-policy reuse alone, without branching, already delivers the gains. No reported result for it on these tasks was found on Lacuna.

Most important competitor: BDQ-Lagrangian. This is our own network with the same cost heads, but a single global multiplier updated by dual ascent instead of a per-state solve. It is the most important competitor because it isolates the claim that per-state pricing, not cost heads or replay, reduces training-time violations.

Ablations of the key ingredients. The first splits the budget equally across branches, with each branch filtering its own bins. This removes the shared price and shows why coupling matters. The second removes joint verification and shows when additivity fails.

What counts as winning. On HumanoidCircle, the proposal beats FOCOPS if it matches its 1106.1 reward within the cost limit using substantially fewer environment steps, or if it accumulates fewer total training-time violations at equal steps. It beats BDQ-Lagrangian if training-time violations drop markedly at no more than a small loss in final return.

Why not just…?

Why not just use continuous Gaussian policies with a Lagrangian, as FOCOPS or PPO-Lag do? Gaussian heads also scale linearly in $D$, so branching is not needed for tractability alone. The case for branching rests on two things. First, value-based branching beat continuous DDPG on Humanoid in the branching paper. Second, the safe Gaussian methods are on-policy and enforce constraints mainly at convergence. The branching paper also concedes that continuous methods with correlated noise win on easy, low-dimensional tasks. We therefore expect, and will report, a crossover: little or no advantage on Point and Car agents, with gains expected on Ant and Humanoid. If no gain appears at high $D$, the claim fails.

Why not just add a branched cost critic to BDQ with one Lagrange multiplier? This is the real threat, and it is why BDQ-Lagrangian is a headline baseline. A global multiplier enforces the budget on average and oscillates. Safety Gymnasium needed PID damping to tame this, and its PPO-Lag reduced violations by 98% only at a 45% reward drop on velocity tasks. If BDQ-Lagrangian matches our training-time violation curve, the per-state solve is unnecessary, and we will say so.

Why not wrap off-policy BDQ in an external safety shield? Projection onto a safe set over $D$ discrete branches is an integer program in general. In continuous form it brings action aliasing and 3–12x overhead, per Safe Reinforcement Learning using Action Projection. Our factored knapsack is exactly the tractable special case of such a shield, with a learned cost in place of a hand-built one. We will report wall-clock time per step against a brute-force joint check at small $D$.

Why not split the budget evenly across joints and filter each branch alone? This is the simplest factored safety rule. It ignores that one joint can spend budget another joint needs, so it is either too loose or too conservative. It is our first ablation. The proposal only stands if the shared price clearly beats it on tasks with coupled costs.

Proposed Experiments

Environments. We use the Safety-Gymnasium velocity tasks (HalfCheetah, Ant, Humanoid), the Circle and Goal tasks for Point, Car and Ant, and HumanoidCircle. Actions are discretized to 17 or 33 bins per dimension, as in the branching paper. We add a power-budget variant of Ant and Humanoid where cost is summed actuator power, so additivity holds exactly. Velocity and collision costs are non-additive and stress the verifier. The 8-joint Safe Mujoco-Ant from the objective-suppression paper is a further check. That paper reports a 33% collision reduction over Recovery RL at a 5% reward loss there, which gives a reference point. For the discretized Reacher tasks with 3–5 joints, we compare against an exact joint solve to measure how much the factored solve loses.

Metrics. We measure final return and final cost relative to the limit. We also measure cumulative cost above the budget summed over all training episodes, and environment steps needed to reach a fixed return with cost under the limit. Finally, we record wall-clock time per action and the cost critic's error on states near the boundary.

Decisive checks. There are four.

  • Violation curves during training against BDQ-Lagrangian. If they coincide, the per-state solve is pointless.
  • Steps-to-threshold against FOCOPS on HumanoidCircle and Humanoid velocity.
  • The gap between the power-budget and collision tasks, with and without joint verification. This shows whether the residual model, not luck, rescues the non-additive cases.
  • Tabular comparison to the exact joint program. Here we expect the reward gap to grow at most mildly with $D$, since only one branch is ever fractional. A gap that grows fast with $D$ would falsify the approach.