                                            Safety-Polarized and Prioritized Reinforcement Learning



A. Why State-agnostic Masking Threshold is not Enough







                                                                                                          Unsafe Rate

                                                                                                                         Ours

                              𝑎0 , 0.9       𝑠2                              0.40                                        SafeQ(0.28)

                                                                                                                         SafeQ(0.36)

            𝑎0 , 0.8     𝑠1                                                                                              0.28

                                                                             0.35                                        0.32

                          𝑎1 , 0.8           𝑠3             𝑠4

          𝑠0                                                                 0.30

                                 𝑎1 , 0.6

                                                                                 0.0           0.2        0.4      0.6     0.8      1.0

                                                                                                                                  1e4

                                     (a)                                                                     (b)

Figure 4. (a) The MDP structure: the reward is always 0. Taking action a ∈ A = {a0 , a1 } transitions to the next state with probability p

or to a fixed unsafe state (termination) with probability 1 − p; blue arrows indicate transitions to the pointed state regardless of action. (b)

Learning curves of unsafe rates using our algorithm and SafeQ over 10 seeds. The x-axis represents the number of steps. Lower is better.





Our proposed optimal action masking (state-dependent) enjoys a convergence guarantee as shown above. In contrast, we will

show that the direct ε-masking method used by SafeQ, which masks actions with an estimated unsafe probability exceeding

a fixed, state-agnostic threshold ε, may fail to achieve the minimum unsafe probability εmin , even when ε is set to εmin . To

be more specific, we write SafeQ in the form of Q-learning and use the SA-REF ψ to be its unsafe probability estimator







                                            Qt+1 (st , at ) ← (1 − βt )Qt (st , at )+

                                                                 βt (rt + γ ′ max            Qt (st+1 , a′ )),                            (22)

                                                                             a ∈Cε (st+1 )









where Cε (s) := {b ∈ A | ψt (s, b) ≤ ε} is the action mask based on ε, and the ψ-update of SafeQ is







                                         ψt+1 (st , at ) ← (1 − βt )ψt (st , at )+

                                                                                                                                          (23)

                                                             βt max{I[st ∈ Su ], ψt (st+1 , π̃t (st+1 ))},







where π̃t (s) := arg maxa∈Cε (s) Qt (s, a) is the learned policy by SafeQ.

Our bad example is based on the intrinsic shortcoming of SafeQ: if ∃a ̸= b ∈ Cε (s) while Qt (s, a) = Qt (s, b), then SafeQ

policy π̃t could not identify which action is better. The MDP structure of the bad example is presented in Figure 4(a)

where s0 is the fixed initial state and the reward function is set to 0. Clearly, the optimal policy is π ∗ (s0 ) = a0 and

π ∗ (s1 ) = a0 , achieving the minimum unsafe probability εmin = 0.28. The sub-optimal policy πsub (s0 ) = a0 and

πsub (a0 |s1 ) = πsub (a1 |s1 ) = 12 has unsafe probability 0.32. We run our method and SafeQ in this example and find that,

even setting ε = 0.28 for SafeQ (the SafeQ(0.28) in Figure 4(b)), it only learns the sub-optimal policy πsub with unsafe

probability 0.32. This is because at state s1 , the unsafe probability of executing action a0 or a1 is smaller than εmin = 0.28

and the action mask Cε (s1 ) with ε = 0.28 could not distinguish the difference between a0 and a1 since Qt ≡ 0 by our MDP.

Thus, SafeQ may only uniformly choose actions at s1 . The same argument holds for larger ε, e.g., ε = 0.36 (SafeQ(0.36) in

Figure 4(b)) which is the unsafe probability of policy π(s0 ) = a0 , π(s1 ) = a1 . In contrast, our safe Q-learning with optimal

action masks converges to a minimum unsafe probability of 0.28, which aligns with our Theorem 4.4.



                                                                        12

