Skip to main content

engine.solvers.recovery

engine.solvers.recovery

Failure-recovery solvers: what the runtime does once an effect has failed (added 2026-10-20).

Domain implementations behind mlsysim.solvers. Each model is arithmetic on stated inputs: one bounded repair priced against unwinding and rebuilding to the same endpoint, the expected irreversible loss of a plan whose checks run before or after its pivot, an append-only loop run to its turn ceiling or stopped early, retries multiplied through nested layers, a capped dependency under one burst of blocking calls, and a retry cohort synchronized or jittered. None models a particular framework, provider, or queueing burst beyond what it states.

Classes

Name Description
BulkheadAdmissionModel One burst of blocking calls to a stalled dependency, before any completes.
IrreversibleLossModel Expected irreversible loss of a plan with its check after, or before, the pivot.
RepairBreakEvenModel One bounded repair attempt against compensating and rebuilding to the same endpoint.
RetryAmplificationModel Attempts one failing logical operation sends when each layer retries on its own allowance.
RetryJitterModel A cohort of retries released together: all inside a burst window, or jittered.
UndetectedLoopModel An append-only loop run to its turn ceiling, or stopped after an earlier turn.

BulkheadAdmissionModel

engine.solvers.recovery.BulkheadAdmissionModel()

One burst of blocking calls to a stalled dependency, before any completes.

Uncapped, every call takes a worker until the pool is full. Capped, at most worker_cap occupy workers and queue_cap wait without one; the rest are rejected at admission, and the cap protects the remaining workers however long the stall lasts. Worker slots only: not CPU, storage, or remote jobs that outlive a timeout.

Methods

Name Description
solve Partition a burst among occupied, queued, and rejected calls.
solve
engine.solvers.recovery.BulkheadAdmissionModel.solve(
    arrivals,
    workers,
    worker_cap,
    queue_cap,
)

Partition a burst among occupied, queued, and rejected calls.

Parameters
Name Type Description Default
arrivals int Nonnegative burst arrival count. required
workers int Positive total worker count. required
worker_cap int Dependency worker cap between zero and workers. required
queue_cap int Nonnegative waiting-queue capacity. required
Returns
Name Type Description
BulkheadAdmissionResult Occupied, queued, rejected, and protected-worker counts for the burst, together with the uncapped occupancy comparison.
Notes

Equation: occupied=min(arrivals,cap); queued=min(arrivals-occupied,queue_cap).

Assumptions: All arrivals precede completion and queued calls hold no worker.

Excludes: CPU load, remote jobs surviving timeouts, and service-time distributions.

References

Derivation: assign burst calls first to dependency worker slots, then to waiting slots, then reject the remainder. Subtract occupied workers from the whole pool to count protected workers. The comparison repeats this partition with the entire pool available and no waiting queue.

Examples
>>> from mlsysim.core.units import Q_
>>> r = BulkheadAdmissionModel().solve(10, 8, 3, 2)
>>> r.occupied + r.queued + r.rejected == 10
True

IrreversibleLossModel

engine.solvers.recovery.IrreversibleLossModel()

Expected irreversible loss of a plan with its check after, or before, the pivot.

Without a check ahead of the pivot nothing recovers: L = P(bad) I. A check that catches a fraction v and reverts with fidelity rho leaves P(bad) v I (1 - rho) from caught changes and P(bad) (1 - v) I from missed ones, which sum to P(bad) I (1 - v rho). Raising v by one step dv removes P(bad) I rho dv.

Methods

Name Description
solve Split expected loss into caught and missed defects.
solve
engine.solvers.recovery.IrreversibleLossModel.solve(
    defect_probability,
    consequence,
    catch_rate,
    revert_fidelity,
    attempt_cost,
    catch_step,
)

Split expected loss into caught and missed defects.

Parameters
Name Type Description Default
defect_probability float Defect probability in [0, 1]. required
consequence Quantity Positive consequence per defect, USD. required
catch_rate float Check catch probability in [0, 1]. required
revert_fidelity float Fraction recovered after a caught defect, in [0, 1]. required
attempt_cost Quantity Positive per-attempt cost, USD. required
catch_step float Nonnegative catch-rate increment; catch_rate + catch_step <= 1. required
Returns
Name Type Description
IrreversibleLossResult Caught and missed expected losses in USD, recovery benefit ratios, and marginal loss reduction for the supplied catch-rate increment.
Notes

Equation: L=p I(1-v rho); delta_L=p I rho delta_v.

Assumptions: Consequence and recovery fidelity are fixed conditional on a defect.

Excludes: Estimated detection accuracy, correlated harms, and risk certification.

References

Derivation: partition defective attempts into caught and missed events. Caught defects retain fraction 1 - revert_fidelity of their consequence; missed defects retain all of it. Summing the two mutually exclusive contributions gives defect_probability * consequence (1 - catch_rate revert_fidelity).

Examples
>>> from mlsysim.core.units import Q_
>>> r = IrreversibleLossModel().solve(0.1, Q_(100,"USD"), 0.5, 0.5, Q_(1,"USD"), 0.1)
>>> r.loss_with_check < r.loss_without_check
True

RepairBreakEvenModel

engine.solvers.recovery.RepairBreakEvenModel()

One bounded repair attempt against compensating and rebuilding to the same endpoint.

The fallback costs the compensation and rebuild times and the rebuild’s model tokens; one repair costs its pre-output startup, its output at the decode rate, local validation, and its whole isolated request. If a failed attempt leaves the fallback unchanged, E[C] = C_repair + (1 - p) C_fallback and repair first pays when p > p* = C_repair / C_fallback, per axis.

Methods

Name Description
solve Price one repair attempt against rebuilding.
solve
engine.solvers.recovery.RepairBreakEvenModel.solve(
    unwind_time,
    rebuild_time,
    rebuild_input,
    rebuild_output,
    repair_input,
    repair_output,
    startup_time,
    output_rate,
    validation_time,
    input_price,
    output_price,
    assumed_success,
)

Price one repair attempt against rebuilding.

Parameters
Name Type Description Default
unwind_time Quantity Nonnegative compensation time. required
rebuild_time Quantity Positive rebuild time. required
rebuild_input int Nonnegative rebuild input-token count. required
rebuild_output int Nonnegative rebuild output-token count. required
repair_input int Nonnegative repair input-token count. required
repair_output int Nonnegative repair output-token count. required
startup_time Quantity Nonnegative startup time. required
output_rate Quantity Positive output-token generation rate, tokens per second. required
validation_time Quantity Nonnegative local-validation time. required
input_price Quantity Positive input price, USD per token. required
output_price Quantity Positive output price, USD per token. required
assumed_success float Assumed repair success probability in [0, 1]. required
Returns
Name Type Description
RepairBreakEvenResult Repair and fallback costs in USD and seconds, break-even success probabilities per axis, expected costs, and fractional savings.
Notes

Equation: E[C]=C_repair+(1-p)C_fallback; p_star=C_repair/C_fallback.

Assumptions: A failed repair leaves the same fallback available; costs are additive.

Excludes: Success-rate estimation, retries after repair, and correlated failures.

References

Derivation: a repair charge is paid on every trial, whereas fallback is paid only on the failure branch with probability 1 - assumed_success. Comparing this expected charge with unconditional fallback yields the repair-to-fallback cost ratio as the success threshold, independently for time and money.

Examples
>>> from mlsysim.core.units import Q_
>>> r = RepairBreakEvenModel().solve(Q_(1,"s"), Q_(10,"s"), 100, 10, 10, 2, Q_(1,"s"), Q_(2,"token/s"), Q_(1,"s"), Q_(1,"USD/token"), Q_(1,"USD/token"), 0.9)
>>> r.repair_time < r.fallback_time
True

RetryAmplificationModel

engine.solvers.recovery.RetryAmplificationModel()

Attempts one failing logical operation sends when each layer retries on its own allowance.

Every attempt of a layer drives a full set of attempts in the layer below, so a attempts per layer over L layers reach the dependency a^L times; one retry owner with the same allowance sends a (Brooker 2019).

Methods

Name Description
solve Count attempts amplified through nested retry layers.
solve
engine.solvers.recovery.RetryAmplificationModel.solve(
    attempts_per_layer,
    layers,
)

Count attempts amplified through nested retry layers.

Parameters
Name Type Description Default
attempts_per_layer int Positive integer attempt allowance per layer. required
layers int Nonnegative number of nested layers. required
Returns
Name Type Description
RetryAmplificationResult Attempt counts by depth, total layered attempts, and coordinated attempts; these are counts rather than latency predictions.
Notes

Equation: A_layered=a**L; A_coordinated=a.

Assumptions: Every attempt fails and consumes the full downstream allowance.

Excludes: Early success, backoff timing, and overlapping requests.

References

Derivation: every parent attempt invokes attempts_per_layer child attempts. Repeating this branching for layers levels multiplies the allowance once per level. A single retry owner invokes the dependency directly and therefore spends only one allowance.

Examples
>>> from mlsysim.core.units import Q_
>>> r = RetryAmplificationModel().solve(2, 3)
>>> r.layered > r.coordinated
True

RetryJitterModel

engine.solvers.recovery.RetryJitterModel()

A cohort of retries released together: all inside a burst window, or jittered.

Synchronized, the window average is N / w; each drawing its arrival uniformly over the span J, the expected rate is N / J and a window of length w expects N w / J arrivals. Expectations only: one window can still receive every retry, so only an admission rate limiter bounds the peak.

Methods

Name Description
solve Compare synchronized and uniformly jittered retry rates.
solve
engine.solvers.recovery.RetryJitterModel.solve(
    retries,
    burst_window,
    jitter_span,
)

Compare synchronized and uniformly jittered retry rates.

Parameters
Name Type Description Default
retries int Nonnegative retry count. required
burst_window Quantity Positive observation-window duration. required
jitter_span Quantity Positive uniform-jitter span, at least the window duration. required
Returns
Name Type Description
RetryJitterResult Synchronized and jittered mean rates in inverse seconds, their ratio, and the expected count in the observation window.
Notes

Equation: rate_sync=N/w; rate_jitter=N/J; E[arrivals_in_window]=N w/J.

Assumptions: Each retry chooses an independent uniform arrival within the jitter span.

Excludes: A deterministic peak-rate guarantee or admission rate limiting.

References

Derivation: a uniform arrival has probability burst_window / jitter_span of falling in the observation window. Linearity of expectation multiplies that probability by retries. Dividing the cohort by its release interval gives each mean rate; this calculation does not bound a realized burst.

Examples
>>> from mlsysim.core.units import Q_
>>> r = RetryJitterModel().solve(10, Q_(1,"s"), Q_(10,"s"))
>>> r.jittered_mean_rate < r.synchronized_rate
True

UndetectedLoopModel

engine.solvers.recovery.UndetectedLoopModel()

An append-only loop run to its turn ceiling, or stopped after an earlier turn.

Each turn appends its output and an observation and resends the whole history, so h turns send h s0 + delta h (h - 1) / 2 input tokens (calc_append_only_context) and h k_out output tokens; every turn takes the same time. The avoided charge is gross: detector cost, false alarms, and cleanup are not debited.

Methods

Name Description
solve Account for an append-only loop stopped early.
solve
engine.solvers.recovery.UndetectedLoopModel.solve(
    first_input,
    output_per_turn,
    observation_per_turn,
    turn_time,
    ceiling,
    stop_after,
    context_window,
    input_price,
    output_price,
)

Account for an append-only loop stopped early.

Parameters
Name Type Description Default
first_input int Positive initial prompt-token count. required
output_per_turn int Nonnegative output tokens per turn. required
observation_per_turn int Nonnegative observation tokens per turn. required
turn_time Quantity Positive fixed duration per turn. required
ceiling int Turn ceiling, integer at least two. required
stop_after int Positive stop turn no larger than the ceiling. required
context_window int Positive context capacity in tokens. required
input_price Quantity Positive input price, USD per token. required
output_price Quantity Positive output price, USD per token. required
Returns
Name Type Description
UndetectedLoopResult Input/output token accounting, costs in USD, durations in seconds, context-fit flag, and avoided gross spend from early stopping.
Notes

Equation: I(h)=h s0+delta h(h-1)/2; C(h)=I(h)p_in+h k_out p_out.

Assumptions: Each turn appends the same token counts and resends all history.

Excludes: Detector overhead, false alarms, cleanup, and prefix-cache discounts.

References

Derivation: prompt lengths form an arithmetic progression beginning with first_input and increasing by output_per_turn + observation_per_turn. Summing that progression prices all resent input; multiplying the fixed output count and fixed duration by turns gives output spend and elapsed time. The stopped trajectory truncates the same progression.

Examples
>>> from mlsysim.core.units import Q_
>>> r = UndetectedLoopModel().solve(10, 2, 3, Q_(1,"s"), 4, 2, 100, Q_(1,"USD/token"), Q_(1,"USD/token"))
>>> r.stop_cost < r.ceiling_cost
True
Back to top