A contextual bandit is a decision loop: at each round a context arrives (a user, a query, a weather forecast), the learner picks an action, and it observes a reward and, in constrained problems, a cost that must stay under a budget on average. The strongest recent algorithm for this constrained setting, Triple-Optimistic Learning for Stochastic Contextual Bandits with General Constraints, achieves regret and total constraint violation that both grow only as the square root of the horizon, without assuming the constraint can be met with slack. Its update to the constraint price, however, needs the true distribution of contexts, and the authors name removing that requirement as an open problem. The natural patch is to substitute the empirical distribution of contexts seen so far. That patch fails in a specific and costly way. When a high-cost context is rare, the empirical measure underweights it early on, the algorithm believes it is under budget, and it spends violations it cannot recover. The file's knapsack example makes the point concretely: a context that arrives 5% of the time must still be planned for (An efficient algorithm for contextual bandits with knapsacks).
We propose to replace the unknown expectation with a pessimistic one. Every past context is kept, and the current policy's predicted cost on all of them is re-evaluated at no interaction cost, because contexts are observed whatever action is taken. The expected violation is then taken as the worst case over distributions within a shrinking confidence ball around the empirical measure. The claim is that not knowing the context distribution costs only a lower-order term in regret and total violation. Pessimism in particular removes the early-violation penalty that plug-in estimation pays in proportion to how rare the costly contexts are. Put briefly, context samples are free and can be reused, but in constrained problems their estimation error is asymmetric, so it has to be absorbed on the conservative side.
Core Claim
Consider $K$ context types (or clusters) with unknown frequencies. Let $\hat P_t$ be the empirical context measure after $t$ rounds, $\hat c_t(x,\pi)$ the optimistic (lower-confidence) cost estimate of policy $\pi$ on context $x$, $\epsilon$ the per-round budget, $\eta$ a step size, and $\lambda_t$ the constraint price. We replace the known-distribution expectation in the dual step with
$$\lambda_{t+1} = \Big[\lambda_t + \eta\big(\max_{Q:\ \|Q-\hat P_t\|_1 \le \rho_t} \mathbb{E}_{x\sim Q}[\hat c_t(x,\pi_t)] - \epsilon\big)\Big]_+ ,$$
with radius $\rho_t \approx \sqrt{K\log(t/\delta)/t}$, which is the standard $L_1$ concentration rate of an empirical distribution over $K$ categories. The inner maximum has a closed form: move up to $\rho_t/2$ of probability mass onto the costliest context types. Its cost is therefore a sort over $K$ values, with no per-round linear program. This keeps the computational advantage that Optimistic³ has over LP-based methods.
We conjecture two things. First, keeping the remaining optimistic machinery of Optimistic³ unchanged (upper confidence bounds on reward, lower confidence bounds on cost, and KL-regularized mirror-descent policy updates) preserves $\tilde O(\sqrt{T})$ regret and violation. The extra error from the context distribution is $\tilde O(\sqrt{KT})$ in the worst case and does not depend on the action-exploration terms. Second, cumulative violation over the first $t_0$ rounds is bounded independently of the minimum frequency $p_{\min}$ of costly contexts. We conjecture that plug-in estimation instead incurs early violation that scales with $1/p_{\min}$ before those contexts are observed often enough. That second, instance-dependent separation is the new content. It is the claim the experiments are built to confirm or refute.
Relation to Prior Work
Three works supply the method. Optimistic³ provides the primal-dual template and the result that no strict-feasibility (Slater) condition is needed. We keep both and change only the dual expectation. Contexts can be Cheap shows that for unconstrained contextual linear bandits, an empirical context distribution built over expanding epochs costs nothing in rate, because the estimation error behaves as bounded misspecification. We borrow the idea that contexts are "free" samples, but we differ in two ways. We treat the estimation error one-sidedly, since in a constrained problem an underestimate of cost is a violation and not just noise. We also re-estimate every round instead of freezing the estimate per epoch. Stochastic Conservative Contextual Linear Bandits motivates the setting: its regret splits cleanly into a UCB term plus constant terms for conservatism and context uncertainty. But its learner observes the context distribution each round and relies on a baseline policy, and we assume neither.
The safe-exploration literature constrains what we can promise. Zero-violation methods such as Safe Exploration Incurs Nearly No Additional Sample Complexity for Reward-Free RL and Safe Exploration for Optimizing Contextual Bandits require a known safe policy or baseline logs. A Safe Exploration Approach to Constrained Markov Decision Processes shows that in-training feasibility pays a sample-complexity overhead ($\tilde O(\epsilon^{-6})$ versus $\tilde O(\epsilon^{-4})$). We therefore do not claim zero violations. Our target is sublinear total violation with a small early-phase constant and no baseline policy, which is an honest middle ground. Breaking Safety Paradox with Feasible Dual Policy Iteration warns that safe policies can starve the cost model of boundary data. Pessimism over contexts does not cause this problem: it reweights contexts, not actions, so cost-model data collection is still driven by the optimistic lower-confidence-bound cost estimates.
Research Program
The theoretical work has three parts. We first prove the rate conjecture for finite contexts and actions, the same scope as Optimistic³. We then prove an early-violation lower bound for plug-in estimation on a two-context instance with rare costly contexts, and a matching $p_{\min}$-free upper bound for the pessimistic update. Finally, we analyze a sliding-window version for piecewise-stationary context drift, with a radius that grows with the number of change points.
The algorithmic work extends the method to continuous contexts. Contexts are clustered into $K$ cells, which is exactly where the concern about discretizing in high dimensions noted by Hanna et al. applies. We will report how results change as $K$ varies, rather than assume a single choice.
Baselines
The naive reference point is a sample-based Lagrangian bandit. It updates the constraint price using only the realized cost of the current round, so it never needs the context distribution. This is the LagrangeCBwLC-style method that Optimistic³ reports beating on MSLR-WEB30k. A second weak reference is fixed-penalty reward shaping with a tuned penalty; (MetaDrive: Composing Diverse Driving Scenarios for Generalizable Reinforcement Learning; MetaDrive: Composing Diverse Driving Scenarios for Generalizable Reinforcement Learning) documents its reckless-or-paralyzed failure mode.
The strongest existing method is Optimistic³ itself, run in two forms. With oracle access to the true context distribution, it is an upper reference and is not beatable on fair terms. With empirical plug-in estimation, it is the real competitor, because it is exactly what a practitioner would do. We also include an epoch-frozen estimate in the style of Hanna et al. The file does not give a numerical score for Optimistic³ on MSLR-WEB30k; its reported result is qualitative ("higher cumulative rewards while maintaining significantly lower and more stable constraint violations" than LagrangeCBwLC and LOE2D). No reported result was found on Lacuna for exact MSLR numbers, so we will reproduce all baselines ourselves.
Fairness rules apply to every method. All methods see identical context streams across 20 seeds and use identical confidence-bound cost models. Each method gets the same grid of 20 settings for step size and regularization, selected on a held-out stream.
Two ablations isolate the key ingredient. Setting the radius $\rho_t=0$ recovers plug-in estimation. Removing context replay, so that only the current context is used, isolates the value of reusing free context samples.
To count as beating plug-in estimation, the method must meet two conditions at matched final regret, within the seed confidence interval. It must cut early-phase cumulative violation (the first 10% of rounds) by a statistically significant margin in the rare-context regime. And it must not do worse in the well-covered regime.
Why not just…?
Why not just plug in the empirical context distribution? This is the real threat. In a stationary world where every context type is common, plug-in estimation should match our method, since both errors shrink at the same $1/\sqrt{t}$ rate. We expect it to fail only when costly contexts are rare or drifting. The experiment therefore sweeps $p_{\min}$ from 0.5 down to 0.01. If plug-in estimation matches us across the whole sweep, the pessimism contribution collapses. What would remain is a theoretical result showing that plug-in estimation already closes the open problem left by Optimistic³, and we would report it that way.
Why not just update the constraint price with the realized cost, which never needs the distribution? Standard Lagrangian updates are known to oscillate and to accumulate thousands of violations early while the price climbs (Constrained Markov Decision Processes via Backward Value Functions; Safety Gymnasium). Optimistic³ was designed precisely to improve on this through predictive dual steps. Including it as a baseline tests whether the distribution-dependent prediction is worth estimating at all.
Why not just use the epoch-based reduction of Contexts can be Cheap? It freezes the estimate within an epoch and has no notion of cost. A rare costly context that first appears mid-epoch goes unaccounted for until the next epoch. The epoch baseline, compared under drift, measures what this staleness costs.
Why not just learn offline from logs with inverse propensity scoring? Offline learning cannot leave the support of the logging policy (Safe Exploration for Optimizing Contextual Bandits). Vanilla inverse propensity scoring also controlled constraint violations poorly in 27-domain dialogue routing, where meta-gradient tuning reached a 75.91% macro-averaged violation reduction (Constrained Policy Optimization for Controlled Contextual Bandit Exploration). It also assumes logs exist, which our setting does not.
Proposed Experiments
We use three testbeds. The first is a synthetic discrete-context knapsack instance with a controllable rare-context frequency $p_{\min}$ and a controllable number of drift points. The second is MSLR-WEB30k with synthetic budget and fairness constraints, following the Optimistic³ setup. The third uses G2F maize yield data (Stochastic Conservative Contextual Linear Bandits) with the forecast distributions hidden from the learner, which turns that paper's known-distribution setting into an unknown one.
We report four metrics: cumulative regret, total violation, early-phase violation, and the maximum running violation, the last as an analogue of the consecutive-cost measure (EMCC) from Revisiting Safe Exploration in Safe Reinforcement learning.
Four checks decide the outcome. The first is the $p_{\min}$ sweep: our early-violation curve should stay flat while the plug-in curve rises roughly as $1/p_{\min}$. The second is the gap to the oracle-distribution Optimistic³, which should shrink as $\sqrt{K/T}$. The third is a $K$-sweep on MSLR-WEB30k, which shows when clustering into more cells stops helping. The fourth is a drift test, in which the sliding-window version should keep violations bounded while the stationary estimators accumulate them.
References
- Triple-Optimistic Learning for Stochastic Contextual Bandits with General Constraints
- An efficient algorithm for contextual bandits with knapsacks, and an extension to concave objectives
- Contexts can be Cheap: Solving Stochastic Contextual Bandits with Linear Bandit Algorithms
- Stochastic Conservative Contextual Linear Bandits
- Safe Exploration Incurs Nearly No Additional Sample Complexity for Reward-Free RL
- Safe Exploration for Optimizing Contextual Bandits
- A Safe Exploration Approach to Constrained Markov Decision Processes
- Breaking Safety Paradox with Feasible Dual Policy Iteration
- MetaDrive: Composing Diverse Driving Scenarios for Generalizable Reinforcement Learning
- MetaDrive: Composing Diverse Driving Scenarios for Generalizable Reinforcement Learning
- Constrained Markov Decision Processes via Backward Value Functions
- Safety Gymnasium: A Unified Safe Reinforcement Learning Benchmark
- Constrained Policy Optimization for Controlled Contextual Bandit Exploration
- Revisiting Safe Exploration in Safe Reinforcement learning