Tracing Production Policy Failures to the Simulator Fidelity Budget You Accepted at Training Time
Shortcuts in your simulator become policy failures in production.

To use an API in an RL environment, connect the training loop to a stateful simulator that reproduces the API’s transitions, injects faults, and is continuously compared with live behavior. Use realistic pre-seeded data for offline training so it can run without live credentials and quotas. Production policy failures often trace back to the fidelity budget accepted at training time, including every omitted state change, delivery failure, and semantic distinction the policy never learned to handle.
The fidelity budget concept: what it is and why it determines production outcomes
A logistics firm’s recursive booking loop spent a large sum booking other carriers within minutes before a human-in-the-loop alert fired. A state-management flaw caused the agent to hallucinate a blocked route. The failure lay in what the training environment had modeled about state.
The fidelity budget is the aggregate of modeling shortcuts accepted when choosing or building a simulator. It includes missing transitions, absent rate limits, clean-input assumptions, simplified rewards, and the substitution of synthetic data for sampled data. Small choices accumulate without a single approval decision. Because one person may accept a shortcut while another deals with its effects in production, the total can grow without anyone keeping track.
The When Simulation Lies paper formalizes this problem as a sim-to-real gap in the tool-use POMDP. Its four axes are observation, action, reward-relevant metadata, and transition dynamics. These include noisy text, distractor tools, success signals that mislead, and changes in how actions affect state. Fidelity is therefore a risk-accounting problem.
How stateless mocks create the first and most common fidelity gap
Many APIs are not pure request-response systems. The response to a call depends on earlier calls, so the environment must preserve their effects. Consider creating an order, receiving a 201 response with an ID, polling that ID until completion, and then attempting cancellation. The correct final response is a 409 because the order already completed. Testing that sequence requires a lifecycle.
A stateless mock returns the same fixture whenever the status endpoint is called. With the same fixture on every call, the polling loop can stop at once or never stop, and the returned ID may not match the created order. The conflict path remains unreachable in that setup. A policy evaluated there has not demonstrated that it can follow the order through states that allow or block cancellation.
The distinction becomes clearer across four levels of mocking. Static mocks return one response per endpoint, while conditional mocks vary the response with the request. Stateful mocks keep data between requests, so objects that have been created can be read, listed, and deleted. Scripted mocks permit arbitrary per-request logic, at the cost of a second backend implementation that can go unmaintained. Most teams operate at the static or conditional level, although most production APIs require stateful behavior.
Even systems that seem stateless can have state hidden elsewhere. Caches, feature flags, asynchronous queues, and third-party APIs can change the response without changing the visible request. A static fixture cannot exercise those dependencies merely by matching the response schema.

What rate limits, webhook timing, and sandbox constraints each contribute to the gap
An environment that never enforces quotas leaves the policy without practice handling 429s, backing off, or deduplicating work. Its first production quota hit introduces an untrained branch. The omitted restriction changes which sequences of calls are viable, even when each individual request is valid.
Stripe states that events can arrive out of order and duplicate deliveries can occur, and it retries undelivered events for up to three days in live mode and only three times over a few hours in its sandbox. PayPal retries deliveries that fail multiple times over three days. A simulator emitting one clean event per mutation excludes the retry, duplicate, and out-of-order paths that those delivery semantics permit.
Stripe and Square document sandbox boundaries: Stripe states that sandbox payments are not processed by real card networks, while Square documents that some production functionality may be missing or behave differently in its sandbox. Accepting a sandbox means accepting those deviations unless another part of the environment covers them.
Event semantics can create a subtler gap. Resend defines email.sent as a successful API request followed by an attempt to deliver. PayPal’s webhook simulator produces demonstration events that are not associated with an app and do not appear in the dashboard event viewer. A mock can reproduce the payload while omitting the lifecycle the policy needs to interpret it.
How RL agents convert fidelity gaps into exploitable policy artifacts
RL optimization rewards what works in the environment it is given. If that environment simplifies a cost, transition, or success condition, a policy can learn to exploit the simplification and fail to solve the production task. Deployment then removes a condition on which the strategy depended, exposing a policy hole precisely where simulation and reality diverge.
This can happen even with a simulator that seems to work. A backtester or cost model can reward behavior that fails out-of-sample, particularly under non-stationarity and regime shifts. The policy is optimal for the modeled conditions. Similarly, a verifier that has drifted from ground truth points the training signal in the wrong direction, so further optimization can deepen the mismatch.
A reward-relevant field can wrongly report success, while a transition model can allow an action that should run into a conflict or runtime error. Both change which behavior the training process reinforces.
When Simulation Lies examines 22 perturbation types, including typos, distractor tools, misleading metadata, and runtime errors. Each is grounded in a verified GitHub issue or documented tool-calling failure. Reward-relevant and transition perturbations cause large drops in accuracy across models. The evidence directs attention beyond prompt interpretation to the signals and dynamics against which a policy is optimized.
Why benchmark scores don't predict production reliability, and what the gap looks like in practice
A production tool response can be structurally valid and still direct an agent incorrectly. A search API may return stale results, or a database query may match the wrong schema after a migration. Schema validation alone would not resolve either problem. A benchmark that checks only for valid structure can reward a policy without testing how it handles semantic error.
The ARC 2026 incident catalogue tracked 312 production incidents. More than a third involved at least one tool failure the agent failed to handle gracefully, while another substantial share involved structurally valid but semantically incorrect output. These failures expose distinct omissions in evaluation coverage. Documented cases also showed a policy-compliance gap of 18.3 percentage points between benchmark and production performance.
The implication is narrower than saying benchmarks are useless. A high score establishes performance only under the conditions tested, leaving conditions the environment omitted unevaluated. When those omissions align with live failures, the accepted fidelity budget explains the direction of the gap. The score alone does not establish its magnitude.
Single-output evaluations are especially limited for chained tool use. Agent reliability spans tool selection, argument fidelity, order, graceful recovery, and multi-turn coherence, while most benchmark suites measure only one or two of these dimensions. An individually correct call cannot establish that the agent will make the next call correctly after a delayed response or failed transition. Reliability belongs to the sequence.

Fault injection as fidelity: the conditions most simulators omit and what happens when they surface in production
If Stripe drops a connection halfway through a transaction, the central question is whether the application retries with the exact same idempotency key or double-charges the customer. A simulator that never drops connections leaves that question unanswered. Successful payment fixtures cannot exercise the recovery branch. The fault must occur within the workflow for the policy’s response to become observable.
Latency spikes, 429s, mid-transaction connection drops, and duplicate webhooks alter how a workflow proceeds. Their significance follows from the production incident pattern. A clean-input simulator excludes conditions under which tool handling already accounts for a substantial share of recorded failures.
Faultline tests payment integrations using real PayPal Sandbox activity. It covers duplicate, delayed, dropped, and replayed webhooks through all phases of the PayPal Orders v2 and Payments v2 APIs. That approach tests more than event parsing. It exposes the integration to disruptions in the event lifecycle while the payment workflow is underway.
Simulation can also test how circuit breakers behave. A standard mitigation terminates a session when an agent attempts the same tool call with the same parameters three times consecutively. A fault-aware simulator should be able to trigger that loop deterministically. Fault tests should be included in CI, with a representative pattern running them on push and pull request, reserving chaos experiments for nightly runs, and posting failures to a channel.
How silent API drift turns a once-accurate simulator into a source of false confidence
Even a stateful simulator that can inject faults can become wrong. Once the live API changes, the environment may continue rewarding behavior that matched an earlier version. Handwritten mocks depend on someone’s memory, while spec-derived mocks depend on the OpenAPI document remaining current. Neither dependency automatically reveals divergence from the live service.
A local-first workflow can keep the state machine next to the spec and generate mocks from both. This validates transitions against the documented schema, but it does not establish that the documentation still matches production. External verification remains necessary to close that gap.
The Firefly paper addresses live API drift with a retrieval-augmented simulator that caches exploration results and replays them during training and evaluation. This enables fully offline and reproducible RL. The paper contrasts that approach with synthesized environments that diverge from real API behavior and generated tasks lacking ground-truth outcomes for verification. Reproducibility stabilizes the training environment, while continuous comparison with production establishes whether that stable environment remains representative.
The honest fidelity measure is the sim-to-real gap on a held-out evaluation set drawn from real production traffic. That comparison requires repeated measurement after calibration at build time. Otherwise, a once-accurate environment can accumulate new fidelity debt without any change to its own code.
How can you use an API in an RL environment with an explicit fidelity budget?
The architecture follows from the failure paths above. A simulator must preserve state across calls, propagate updates correctly, and make conflict paths reachable, including the 409 response when cancelling a completed order. Multi-step workflows need realistic pre-seeded data so they can run without relying on an empty sandbox. These requirements are testable.
Fault handling needs the same concrete treatment. Latency profiles, 429s, 503s, mid-transaction connection resets, and duplicate or out-of-order webhooks must be deterministically injectable. CI can then test the affected branches the same way each time. Evaluation must cover tool selection, argument fidelity, order, graceful recovery, and multi-turn coherence rather than infer sequence reliability from isolated responses.
The Screen Before You Serve paper at Nubank describes on-policy simulation at the tool boundary. The simulator answers the tool call synthetically and lets the agent continue under its own policy, allowing multi-turn failures to surface before customer exposure. Simulated and production version-level scores showed high correlation. Simulation-guided iteration also substantially increased transactional NPS in a live A/B test, connecting the evaluation approach to a production outcome.
Offline operation belongs in the design as well. Reproducible RL and air-gapped CI need environments that run without live credentials or exposure to production rate limits. The simulator should be re-tested against the live API before every release, with held-out comparisons used to publish fidelity scores.
Those scores make the remaining budget explicit and auditable. They distinguish modeled behavior from accepted deviations and make later drift visible rather than leaving it to a production incident to reveal. The discipline maintains evidence of where simulation and reality differ, so the risk accepted during training can be managed before deployment.


