causa_runtime/executor/error.rs
1use causa_kernel::{
2 BatchError, BlockId, ControlError, ProcessorError, SourceError, ToolResultPayload,
3};
4
5/// Failure to construct or change a tool registry.
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7#[non_exhaustive]
8pub enum ToolRegistryError {
9 /// Static tool definitions must have distinct names.
10 #[error("duplicate static tool: {name}")]
11 DuplicateTool {
12 /// Conflicting advertised name.
13 name: String,
14 },
15 /// A source with this identity is already registered.
16 #[error("dynamic source already registered: {source_id}")]
17 DuplicateSource {
18 /// Conflicting source identity.
19 source_id: String,
20 },
21 /// A requested source is not registered.
22 #[error("no dynamic source registered: {source_id}")]
23 UnknownSource {
24 /// Requested source identity.
25 source_id: String,
26 },
27}
28
29/// Failure to bind a complete, unambiguous invocation catalog.
30#[derive(Debug, thiserror::Error)]
31#[non_exhaustive]
32pub enum ToolCatalogError {
33 /// The parent invocation control stopped catalog acquisition.
34 #[error(transparent)]
35 Control(ControlError),
36 /// A catalog could not be listed; its original error is retained.
37 #[error("source {source_id} failed: {error}")]
38 Source {
39 /// Identity of the failed source registration.
40 source_id: String,
41 /// Original listing failure.
42 error: SourceError,
43 },
44 /// A name occurred more than once in the assembled catalog.
45 #[error("duplicate advertised tool: {name}")]
46 DuplicateTool {
47 /// Conflicting advertised name.
48 name: String,
49 },
50 /// A static tool changed the name registered at construction.
51 #[error("static tool name changed from {registered} to {actual}")]
52 StaticNameChanged {
53 /// Name registered at construction.
54 registered: String,
55 /// Name returned during this binding.
56 actual: String,
57 },
58}
59
60/// Position of a processor in the executor's fixed processing flow.
61///
62/// Exhaustive on purpose: the flow has these two positions.
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum ToolProcessorPhase {
65 /// Before dispatch; pending inputs may be changed or completed.
66 Before,
67 /// After dispatch; completed output may be edited or reordered.
68 After,
69}
70
71/// Why controlled processing returned the caller's current batch early.
72// The confirmed API retains the actual rejected payload without indirection.
73#[allow(clippy::large_enum_variant)]
74#[derive(Debug, thiserror::Error)]
75#[non_exhaustive]
76pub enum ToolProcessingError {
77 /// The binding's parent cancellation or deadline stopped processing.
78 #[error(transparent)]
79 Control(ControlError),
80 /// The input or internally produced batch is structurally invalid.
81 #[error("invalid tool batch: {0}")]
82 InvalidBatch(BatchError),
83 /// This entry point only accepts new, entirely pending declarations.
84 #[error("tool batch already contains {completed} completed calls")]
85 NotFreshBatch {
86 /// Number of completed calls at entry.
87 completed: usize,
88 },
89 /// A processor returned its own error.
90 #[error("{phase:?} processor {index} failed: {error}")]
91 Processor {
92 /// Processing phase.
93 phase: ToolProcessorPhase,
94 /// Zero-based index within that phase's configured processors.
95 index: usize,
96 /// Original processor error.
97 error: ProcessorError,
98 },
99 /// A processor returned a structurally invalid batch.
100 #[error("{phase:?} processor {index} returned an invalid batch: {error}")]
101 InvalidProcessorBatch {
102 /// Processing phase.
103 phase: ToolProcessorPhase,
104 /// Zero-based processor index.
105 index: usize,
106 /// Original batch validation error.
107 error: BatchError,
108 },
109 /// A processor violated fixed membership or immutable completed facts.
110 #[error("{phase:?} processor {index} violated its handoff: {message}")]
111 Handoff {
112 /// Processing phase.
113 phase: ToolProcessorPhase,
114 /// Zero-based processor index.
115 index: usize,
116 /// Specific violated handoff constraint.
117 message: String,
118 },
119 /// An actual tool result could not be associated with its declaration.
120 #[error("tool result rejected for declaration {call_block_id:?}: {error}")]
121 ResultRejected {
122 /// Declaration actually dispatched.
123 call_block_id: BlockId,
124 /// Original association or installation error.
125 error: BatchError,
126 /// Actual rejected payload, preserved for diagnosis.
127 result: ToolResultPayload,
128 },
129}