1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Runtime error types.
use thiserror::Error;
use super::run::RunId;
/// Errors that can occur during runtime execution.
#[derive(Debug, Error)]
pub enum RuntimeError {
/// Provider not found in registry.
#[error("provider not found: {0}")]
ProviderNotFound(String),
/// Session not found.
#[error("session not found: {0}")]
SessionNotFound(uuid::Uuid),
/// Run not found.
#[error("run not found: {0}")]
RunNotFound(RunId),
/// Run is in invalid state for operation.
#[error("invalid run state: expected {expected}, got {actual}")]
InvalidRunState {
/// Expected state.
expected: String,
/// Actual state.
actual: String,
},
/// Maximum iteration limit exceeded.
#[error("iteration limit exceeded: {0}")]
IterationLimitExceeded(usize),
/// Token budget exceeded.
#[error("token budget exceeded: {used} > {limit}")]
TokenBudgetExceeded {
/// Tokens used.
used: usize,
/// Token limit.
limit: usize,
},
/// Context length exceeded the model's maximum.
#[error("context length exceeded: model context {context}, estimated {estimated}")]
ContextOverflow {
/// Model context window size.
context: u32,
/// Estimated token usage.
estimated: usize,
},
/// Session is already being processed by another run.
#[error("session busy: {0}")]
SessionBusy(uuid::Uuid),
/// Tool execution timeout.
#[error("tool execution timeout: {tool}")]
ToolTimeout {
/// Tool name.
tool: String,
},
/// Provider error.
#[error(transparent)]
Provider(#[from] crate::error::ProviderError),
/// Context error.
#[error(transparent)]
Context(#[from] crate::error::ContextError),
/// Storage error.
#[error(transparent)]
Storage(#[from] crate::error::StorageError),
/// Tool error.
#[error(transparent)]
Tool(#[from] crate::error::ToolError),
/// Snapshot or recovery failed.
#[error("recovery error: {0}")]
RecoveryFailed(String),
/// Doom loop detected — agent is stuck in repetitive tool call pattern.
#[error("doom loop detected: {description}")]
DoomLoopDetected {
/// Human-readable description of the detected pattern.
description: String,
},
/// Input was rejected by the admission pipeline.
#[error("input rejected: {input_id} — {reason}")]
InputRejected {
/// Input identifier.
input_id: crate::runtime::input::InputId,
/// Rejection reason.
reason: String,
},
/// Input admission internal error.
#[error("input admission error: {0}")]
InputAdmissionFailed(String),
}
/// Result type for runtime operations.
pub type RuntimeResult<T> = Result<T, RuntimeError>;