Skip to content

The least spend that keeps a bad run's downtime under a limit - #505

Merged
derrynknife merged 1 commit into
devfrom
build/downtime-risk
Nov 21, 2026
Merged

derrynknife merged 1 commit into
devfrom
build/downtime-risk

Conversation

@derrynknife

Copy link
Copy Markdown
Owner

Summary

Answers "I want to be 95% sure I don't lose more than x on downtime over the horizon: what is the least I need to pay?". Use case UC-68 was written in the maintenance README first.

The method. RepairableRBD.least_spend_for_downtime(horizon, limit, ...), plus UnitPlan.least_spend_for_downtime, which goes through the plan's one-node diagram.

The target is downtime only.

  • Measured in hours, or as cost with measure="cost" (the downtime_cost_rate, plus any value_rate lost).
  • All system downtime counts by default; downtime="unplanned" counts failures only.
  • Spend is unbounded unless budget= is given.

When a design counts as safe. A design meets the limit only when an upper confidence bound on the downtime's risk measure is under it, so simulation noise cannot make a design look safe:

  • objective="var": the quantile at level, with an exact order-statistic bound (binomial method);
  • objective="cvar": the tail mean, with a normal bound that is stated as approximate.

The risk measures live in the money module, repyability.value._risk. results._order_statistic now calls its quantile, so there is one definition.

Levers, each at its own price:

  • redundancy={node: price}: copies in parallel, drawn as allocate_redundancy draws a train of one node;
  • intervals={node: [...]}: a preventive interval's candidates, priced at the change in expected preventive cost.

The search is the allocations' marginal analysis on common random numbers (one seed for every design). An interval move may jump to any later candidate, because a quantile can stay flat over a single step.

What the result reports:

  • frontier: the non-dominated designs, so more spend never raises the downtime along it;
  • for every design, both planned and unplanned downtime: mean and bad run, in hours and in cost;
  • when the limit is not met, floor and stopped name what stopped the levers: the budget, the levers' caps, or planned task downtime at or over the limit on its own.

Per-run unplanned downtime. AvailabilityResult.unplanned_downtimes gives each run's unplanned downtime. Both engines already computed it and only summed it, so the tally now keeps the per-run values too. The engines are untouched and no number changes.

Registration. The new method has a route in analysis_routes, a call in REPAIRABLE_CALLS, a row in the capability matrix (README regenerated), a guide section in docs/guide/costs.md, and API entries for DowntimeRiskResult and DowntimeDesign.

Type of change

  • New feature

Checklist

test_downtime_risk.py (12 tests) covers:

  • a single exponential unit's 95th percentile against the exact downtime distribution of an alternating renewal process, within four of the quantile's standard errors. The exact distribution comes from uniformisation: given n jumps, the spacings are Dirichlet, so k down-spacings sum to T·Beta(k, n+1−k). The test also checks that distribution's two ends against closed forms;
  • the quantile bound against the binomial definition;
  • level 0.5 on a symmetric loss giving its median;
  • redundancy meeting limits of 200, 50, 10 and 1 h at a rising spend;
  • the frontier never rising with spend;
  • planned downtime rising along the unplanned-downtime frontier;
  • the planned floor and the budget floor being named;
  • seeded repeats, and cost equal to hours × rate;
  • a plan alone equal to its diagram;
  • refusals.

Other checks:

  • black, isort, flake8 and mypy on the changed files
  • CHANGELOG.md updated
  • Monte-Carlo tests are seeded, with seeds fixed before each test's run

Notes for reviewers

Tests run (one process each):

  • test_downtime_risk + test_planned_split: 28 passed, 2 skipped (numba).
  • test_analysis_routes -k "least_spend or covers_every or readme", which includes the new method on every catalogue diagram, plus test_readme_capabilities: 8 passed.
  • test_help, test_result_objects, test_plan_alone, test_unit_plan, the costs guide's examples, test_every_analysis_is_called, the saving guide's table, and the doctests of _risk.py, _downtime_risk.py and the new method: 255 passed, 1 skipped.

The new tests passed on their first run, and none was changed after a failure.

Pre-existing failures. In test_api_docstrings, the UnitPlan task classes (AgePolicy … Upgrade) are undocumented on the API pages and lack parameter docs. That already fails on dev and this PR doesn't change it.

Study to run at consolidation. scripts/downtime_bound_coverage.py checks the bound's coverage at its stated rate: 1,000 seeded repeats of 500 runs, passing if the coverage's 99% binomial interval reaches 0.95. It is committed unrun, as the testing rule asks.


Generated by Claude Code

RepairableRBD.least_spend_for_downtime (and UnitPlan's, through its
one-node diagram) searches redundancy and interval levers on common
random numbers for the cheapest design whose downtime quantile (or tail
mean) has an upper bound under the limit, in hours or cost, all downtime
or unplanned only. Each design reports planned and unplanned downtime,
the frontier keeps the non-dominated designs, and a limit not met names
the floor that stopped the levers. Risk measures go in
repyability.value._risk; each run's unplanned downtime, which both
engines already worked out, is kept per run. Use case UC-68. The bound's
coverage study is committed unrun, for consolidation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
@derrynknife
derrynknife merged commit 6ae1a77 into dev Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants