Manuscript Offprint

arXiv:2610.23445

RECREG: Recovery-based Shielding for Regular Safety Properties in Reinforcement Learning

Alexander W. Goodall, Francesco Belardinelli

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

In many real-world scenarios we need to consider formal requirements, such as safety and constraint compliance, to deploy Reinforcement Learning (RL) agents. In this paper we introduce RECREG, a safe RL framework capable of enforcing non-Markovian regular safety properties via recovery-based shielding. RECREG is a unified approach that supports different levels of a priori knowledge and safety guarantees. The paper primarily focuses on building the theoretical foundations for RECREG in the tabular setting, providing rigorous safety and convergence guarantees that are not present in related work. We provide an extensive set of empirical results using the MASA-Safe-RL library, and we outline an extension of RECREG to deep RL domains using SOTA model-based RL. Our empirical results demonstrate that RECREG achieves efficient learning and matches the theory in this paper.

1 Introduction

Safe Reinforcement Learning (RL) is an active area of research focusing on the training of agents with RL while maintaining some standard of safe behaviour at deployment and possibly during training as well [5]. There exist many competing paradigms in safe RL, the most common being Constrained Markov Decision Processes (CMDPs) [4], which frame safe RL as a constrained optimization problem, enforcing safety through cost functions and expected cumulative cost thresholds; although this approach is often inappropriate in highly safety-critical domains, as it only enforces safety in expectation and often lacks rigorous guarantees [53].

An alternative view comes from formal methods. Methods from this class often leverage some form of Linear Temporal Logic (LTL) [42] to express formal safety constraints and task objectives, enabling expressive and interpretable specifications [14, 25, 26, 40, 47, 53, 54]. Following this line of work, shielding has emerged as a powerful approach for enforcing LTL safety properties in RL [3]. Predicated on ideas like the Simplex Architecture [46], shielding works by monitoring the agent's actions and overriding them with a safe alternative if they propose an action that could lead to a safety violation. Classical approaches to shielding leverage reactive synthesis to build correct-by-construction monitors from formal safety specification and a formal model of the environment called the safety abstraction [3, 10]. The safety abstraction is designed to encode the minimum amount of environment dynamics required to guarantee safety. As such, it is often built from a pessimistic view of the environment derived from prior knowledge, thus classical shielding approaches can only reasonably be applied to known environments or simple safety specifications. This fundamentally departs from the usual RL framework (unknown environment), but does provide strong safety guarantees by construction.

More recent shielding approaches consider probabilistic safety constraints [24, 32]. While these are less pessimistic, they still require knowledge of the transition kernel, using probabilistic model

Preprint.

checking to verify actions. There has however been a shift to lift these assumptions, in particular, by leveraging model-based RL to estimate the unknown environment dynamics and verify actions via forward simulation in the latent space of a recurrent state space model [17, 18, 27, 57], with Gaussian Process dynamics models [19] or ensembles of probabilistic neural networks [20]. RECREG addresses this same question: how can we obtain meaningful safety guarantees when the environment dynamics are unknown?. We summarize our contributions hereafter.

Contributions. To bridge the gap between the strong empirical results achievable by data driven methods (e.g., CMDP, model-based RL) and formally guaranteed safety (classical shielding) we propose RECREG, a unified framework for enforcing regular safety properties that spans multiple levels of a priori knowledge. In a similar fashion to Recovery RL [49], RECREG learns a backup policy trained to maximize safety probability and action replacement (shielding) is implemented by identifying probabilistic safe sets (or “recovery zones”). A central contribution of this paper is in the development of explicit safety guarantees, convergence and optimality results which are missing in prior work [49]. In particular, we identify and formalize three complementary operation modes. In the EXACT mode, RECREG assumes full knowledge of the transition kernel and guarantees safety from the beginning of training. In the MODELBASED mode, RECREG estimates the transition kernel from observed data, then performs on-the-fly verification via finite-horizon reachability analysis, enabling principled shielding under partial model knowledge with statistical guarantees. In the MODELFREE mode, RECREG dispenses with explicit model learning altogether and instead directly estimates the safety critic, yielding a purely model-free shielding mechanism with convergence guarantees. We also use DREAMERV3 [23] to develop a deep RL variant of RECREG that uses latent rollout models and safety critics to provide safety guarantees under correct model calibration. In the tabular setting, we validate that RECREG matches the outlined theory and that comparable approaches cannot reliably enforce safety constraints while maximising task performance. In deep RL we also observe that RECREG is able to reliably reduce safety violations while achieving good returns compared to similar approaches based on the DREAMERV3 architecture. Together these results establish RECREG as a practical and theoretically-grounded approach to safe RL.

Related work. Existing methods for safe RL can roughly be dividing into two camps: (A) methods that incorporate safety into the learning objective, encouraging safe behaviour as an outcome of learning [2, 6, 13, 25, 38, 45, 47, 48, 60], and (B) methods that enforce safety via external mechanisms that directly modify the agent's actions [3, 9, 20, 32, 35, 36, 49]. Methods from camp (B) make up a large portion of “provably safe” RL algorithms [37]. They can also be further divided into hard constraints [3] and probabilistic constraints [9, 24, 32]. Methods based on CMDPs are from camp (A) – they use a cost function, that often represents safety violations, in the learning objective to reduce the probability of unsafe behaviour. CMDPs themselves can be solved via linear programming in the tabular setting [4]. For more complex environments, methods based on Lagrange relaxations and dual-gradient descent [6, 13, 38, 45, 48], and local policy search with gradient projections [2, 60] are popular approaches. While CMDPs provide a convenient framework for learning, they have several limitations. In particular, safety constraints are only enforced in expectation, which do not guarantee that unsafe events will never occur. Furthermore, the discounting accumulated costs also poses issues with constraining limiting behaviour [53].

In contrast, our approach RECREG fits neatly into camp (B), enforcing regular safety properties (more expressive than LTL safety properties) with high probability. LTL constraints have been considered in RL for both task specification [14, 25, 26] and constraint specification [47, 53, 54]. LTL constraints are PAC learnable under specific conditions [53, 59], but optimality under LTL constraints can only be achieved subject to optimal discount factors and Lagrange multipliers [47, 54]. Earlier theoretical work assumed access to a perfect generative model of the environment which can be queried from any state, breaking standard RL assumptions [53]. Recent work on Automata Constrained Q-learning uses reward shaping and penalties to ensure the optimal policy is also safe at convergence although does not provide explicit safety guarantees during learning unlike our approach [40]. For RL with LTL safety constraints, Shielding can be used to enforce constraint compliance [3]. In partially observable settings (e.g., deep RL) safety can be guaranteed if the underlying transition structure is known [12]. RECREG, by contrast, offers a unified framework for safety guarantees even when the transition dynamics or structure are truly unknown.

Another related line of research is Reward Machines [29, 30]; these are closely related to our work as simple reward machines can encode reward functions for learning regular safety properties. While the Reward Machines literature is primarily focused on task specification, there are many key insights such as counterfactual experiences and reward shaping [41] that are used to speed up learning over Reward Machines, which can applied in our framework too.

References (19)