When Online Adaptation of Resilience Policies Hurts: Safe Exploration and Measurement Pitfalls in Resilience4j
Authors: Rajat M. Barot, Arjun S. Borkhatariya
Organizations: Department of Computer Science, State University of New York, Binghamton, Binghamton, NY, USA · Department of Software Engineering, Arizona State University, Tempe, AZ, USA
Circuit breaker, retry, and bulkhead settings in Java microservices are tuned once and frozen, although the best setting depends on the fault a dependency is currently showing. We study whether an online learner can pick these settings at runtime. AdaptR4j swaps Resilience4j policies atomically in Spring Boot 3 and lets a contextual bandit choose among complete CircuitBreaker/Retry/Bulkhead configurations from Prometheus signals. Our first, naive design scored worse than keeping the default policy in three of four winnable fault scenarios under the reward it optimised: exploring a menu that contained aggressive circuit breakers rejected most traffic while the learner was still learning. Two safeguards fix this: a safe policy menu (no breaker stricter than the latency SLO) and safe exploration with a bounded reward. With them, AdaptR4j beats the production default in every winnable scenario (p < 0.001, three runs each, run-to-run SD <= 0.03), beats the best fixed policy when the fault changes over time, and cuts user-visible failures up to 3.7x compared with the naive design. A context-free bandit on the same safe menu performs statistically indistinguishably, so the safeguards - not the learner - carry most of the benefit. We also report how an earlier version of our harness produced convincing but wrong results: a unit mismatch made every circuit breaker 100x too strict and rejected calls were invisible to the metrics, so 94% of user requests failed while latency and error metrics looked excellent.
Figures & tables
Harness
Scen.
p99 seen
errors seen
users failed
original
S1
138 ms
0.10 %
94.5 %
original
S2
106 ms
0.06 %
97.4 %
fixed
S1
280 ms
0.12 %
0.1 %
fixed
S2
854 ms
3.64 %
6.0 %
TABLE I: What the controller saw vs. what users experienced (AdaptR4j; per-window p99 and error rate averaged over the run; users failed = Locust, whole run).
AdaptR4j (safe design)
Default p01
Best fixed policy
UCB1, safe menu
Naive design
Scen.
reward
late
fail%
reward
fail%
reward
fail%
reward
fail%
reward
fail%
S1
+0.257±0.002
+0.518
0.1
−2.000†
0.1
+0.518
0.0
+0.050
0.8
+0.441
0.3
S2
−1.821±0.021
−1.759
5.8
−2.000†
1.0
−1.438†
9.4
−1.823
4.0
−1.862
9.4
S3
−2.000 (1 run)
−2.000
0.8
−2.000
0.0
−2.000
0.0
–
–
−2.000
10.6
S4
−0.315±0.010
−0.035
9.4
−2.000†
32.5
+0.249†
2.6
−0.526
14.0
−0.848
31.4
S5
−0.451±0.026
−0.409
2.3
−0.842†
0.0
−0.763†
0.0
−0.603
0.4
−0.764
8.5
TABLE II: Mean reward (higher is better; −2 = SLO missed every window) and user-visible failure rate (Locust: HTTP 5xx or response >1 s). AdaptR4j: three runs, mean ± SD; “late” = windows 40–80. † : block-bootstrap p<0.05 vs. AdaptR4j run 1.
Java applications reach large language models (LLMs) through an integration framework, and rely on it to handle a failing provider: to retry what can be retried and nothing else, to wait as long as the provider asks, never to present a truncated answer as complete, and to record each failure in the application's metrics. We state these expectations as a six-clause reliability contract and measure Spring AI 2.0.1 and LangChain4j 1.21.0 against it with a scripted OpenAI-compatible provider: fifteen failure scenarios, synchronous and streaming, three repetitions. LangChain4j meets it in 47 of 77 applicable cases with its defaults and in 51 of 83 when configured explicitly, Spring AI in 72 of 77 and 76 of 83; both deliver a stream that ended without its terminator as a complete answer. We then place one implementation of the contract beneath both frameworks, at the HTTP boundary - an OkHttp interceptor for Spring AI, an HttpClient for LangChain4j, and a java.net.http transport for code without a framework - sharing a 725-line core that depends only on the JDK and the Micrometer Observation API. With it, all three clients behave identically and meet the contract in 90 of 91 cases; the remaining case is a policy trade-off between retrying a hung provider and waiting for a slow first token. Against a local model server the layer rejected none of 700 calls, and it adds a median of 32-217 microseconds to a call.
Tool-using LLM agents are typically developed and post-trained in controlled environments with reliable tools, but deployment exposes them to tool failures, API and schema drift, and third-party services outside the developer's control. We introduce Bench2Robust, a framework for scenario-controlled solvability that augments existing benchmarks with episodes requiring retrying the original path, switching to a fallback-equivalent tool, or recognizing that no viable path remains. By controlling recoverability, Bench2Robust separates recovery-policy quality from randomness in whether failures persist or resolve. Across 7 models from 4 families and 10 task/domain slices spanning customer-service and function-calling benchmarks, 69 of 70 model-subset pairs degrade under tool failures, by up to 46.7 percentage points. We propose Bayesian Tool Memory (BTM) for structured runtime recovery context and use reinforcement learning (RL) for learned recovery behavior. On held-out Retail tasks using the benchmark's original tool set, BTM improves robustness by 16.8 percentage points without retraining, while RL retains a 6.3-point gain without inference-time BTM. Combining RL with BTM yields a 20.7-point improvement over the base model while preserving clean performance. These results show that robust tool use benefits from combining structured runtime recovery context with learned recovery behavior.
Residual policy adaptation provides a lightweight way to modify a strong reference policy, but a shared scale and a fixed subgroup partition can hide heterogeneous degradation and become fragile when the deployment mixture of information states changes. We introduce RSD-Poker, a structure-adaptive and shift-robust certification framework that freezes a bank of residual families and scales, learns a policy-visible partition on an independent structure split, and freezes that partition before calibration labels are joined. Each candidate-group pair receives a weighted simultaneous upper certificate for anchor-relative risk and a lower certificate for weak-response utility. A robust group-to-candidate map is then selected over a predeclared uncertainty set of deployment group proportions. Under independent calibration units drawn from each frozen group's law, a candidate bank and partition fixed before calibration, and invariant within-group conditionals, the selected map satisfies its declared mixture-robust risk budget and utility certificate with probability at least 1−ζrisk−ζutil. The information contract supports both a teacher-backed transform and a teacher-free observation-only student. The retained deterministic 24-state audit remains an exact replay diagnostic: empirical-zero selects α=0.08, raising the weak-response proxy from 4.2082 to 4.2889 with 0/12 held-out threshold crossings. On stratified held-out states, the learned-partition dual selector raises weak utility from 4.4074 under global dual certification to 4.4936 and lowers held-out violation from 0.0215 to 0.0078; its mixture-robust variant reaches violation 0.0059. Across five observation-only checkpoints, risk-calibrated residuals attain weak utility 4.3659±0.0177 and violation rate 0.0178±0.0057.
Miaobo Hu, Shuhao Hu, Xiaobo Guo +4
School of Artificial Intelligence, University of Chinese Academy of Sciences, Beijing, China · Institute of Information Engineering, Chinese Academy of Sciences, Beijing, China