use super::{async_caps, concepts_of, finding_from_concept};
use crate::domain::concepts::ConceptKind;
use crate::domain::model::LanguageModel;
use crate::domain::rule::{Rule, RuleMeta};
use crate::domain::types::{Confidence, Finding, Severity};
use std::sync::OnceLock;
#[derive(Default)]
pub struct UnobservedTaskFailureRule;
impl Rule for UnobservedTaskFailureRule {
fn meta(&self) -> &RuleMeta {
static META: OnceLock<RuleMeta> = OnceLock::new();
META.get_or_init(|| RuleMeta {
id: "unobserved-task-failure".into(),
name: "Unobserved task failure".into(),
description: "Background task detached without observing its error result.".into(),
default_severity: Severity::High,
required_capabilities: async_caps(),
autofix_safe: false,
})
}
fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
concepts_of(model, ConceptKind::UnobservedTask)
.map(|(lang, c)| {
finding_from_concept(
&self.meta().id,
lang,
c,
Severity::High,
Confidence::Medium,
"Background task is spawned without observing completion/errors.",
"Task panics or errors are lost; partial work continues unnoticed.",
"Join the handle, use a supervisor, or log JoinError in a dedicated task.",
)
})
.collect()
}
}