xbp_analysis/application/rules/
unbounded_retry.rs1use super::{base_caps, concepts_of, finding_from_concept};
2use crate::domain::concepts::ConceptKind;
3use crate::domain::model::LanguageModel;
4use crate::domain::rule::{Rule, RuleMeta};
5use crate::domain::types::{Confidence, Finding, Severity};
6use std::sync::OnceLock;
7
8#[derive(Default)]
9pub struct UnboundedRetryRule;
10
11impl Rule for UnboundedRetryRule {
12 fn meta(&self) -> &RuleMeta {
13 static META: OnceLock<RuleMeta> = OnceLock::new();
14 META.get_or_init(|| RuleMeta {
15 id: "unbounded-retry".into(),
16 name: "Unbounded retry".into(),
17 description: "Retry loop without limit or backoff.".into(),
18 default_severity: Severity::High,
19 required_capabilities: base_caps(),
20 autofix_safe: false,
21 })
22 }
23
24 fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
25 concepts_of(model, ConceptKind::Retry)
26 .filter(|(_, c)| c.bounded == Some(false))
27 .map(|(lang, c)| {
28 finding_from_concept(
29 &self.meta().id,
30 lang,
31 c,
32 Severity::High,
33 Confidence::Medium,
34 "Retry loop has no explicit bound or backoff.",
35 "Hot-loop retries amplify outages and thrash dependencies.",
36 "Cap attempts, add exponential backoff with jitter, and fail after budget.",
37 )
38 })
39 .collect()
40 }
41}