Skip to main content

aios_agent/backends/
fallback.rs

1//! FallbackNoOpBackend — circuit breaker 熔断后的最终安全后端。
2//!
3//! 返回单个 Idle/NoOp 意图。`confidence` 取 1.0:
4//! "做什么也不做" 是确定性的安全选择,不应被 policy 的置信度门槛
5//! (policy_engine 默认 0.3) 拦截。后端层面的失败信号由
6//! `DecisionBackendResult::error` 单独承载,与意图置信度解耦,
7//! 这样 fallback 路径产生的 NoOp 仍能流向 executor 形成完整审计链。
8
9use std::time::Instant;
10
11use aios_spec::{
12    ActionType, ActionUrgency, DecisionBackendResult, DecisionRoute, Intent, IntentBatch,
13    IntentType, RiskLevel, StructuredContext, SuggestedAction,
14};
15
16use crate::{new_id, DecisionBackend};
17
18pub struct FallbackNoOpBackend;
19
20impl DecisionBackend for FallbackNoOpBackend {
21    fn evaluate(&self, context: &StructuredContext) -> DecisionBackendResult {
22        let start = Instant::now();
23        let intent_batch = IntentBatch {
24            window_id: context.window_id.clone(),
25            intents: vec![Intent {
26                intent_id: new_id(),
27                intent_type: IntentType::Idle,
28                confidence: 1.0,
29                risk_level: RiskLevel::Low,
30                suggested_actions: vec![SuggestedAction {
31                    action_type: ActionType::NoOp,
32                    target: None,
33                    urgency: ActionUrgency::IdleTime,
34                }],
35                rationale_tags: vec!["fallback_noop".into()],
36            }],
37            generated_at_ms: context.window_end_ms,
38            model: "fallback-noop-v0.1".to_string(),
39        };
40
41        DecisionBackendResult {
42            route: DecisionRoute::FallbackNoOp,
43            intent_batch,
44            rationale_tags: vec!["fallback_noop".into()],
45            latency_us: start.elapsed().as_micros() as u64,
46            error: Some("circuit breaker engaged — falling back to no-op".into()),
47        }
48    }
49}