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
use std::path::PathBuf;
use thiserror::Error;
use uuid::Uuid;
/// Errors that can occur during session operations.
#[derive(Debug, Error)]
pub enum SessionError {
/// An I/O error occurred (file read/write, directory creation, etc.).
#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),
/// Removing one artifact from a Session-owned artifact set failed.
#[error(
"failed to remove session artifact {path}: {source}; removed={removed:?}; remaining={remaining:?}; retryable=true"
)]
ArtifactCleanup {
/// Exact artifact path whose removal failed.
path: PathBuf,
/// Underlying filesystem failure.
#[source]
source: std::io::Error,
/// Paths already removed before the failure.
removed: Vec<PathBuf>,
/// Paths still present and safe to retry.
remaining: Vec<PathBuf>,
},
/// Session index cleanup failed while the transcript remained discoverable.
#[error("failed to remove Session {session_id} from the index: {message}")]
IndexCleanup {
/// Session whose supplementary index/fork rows could not be removed.
session_id: Uuid,
/// Content-free index diagnostic.
message: String,
},
/// Orphan-sidecar validation or SQLite ownership probing failed.
#[error("failed to reconcile orphan Session sidecar {path}: {message}")]
OrphanReconciliation {
/// Exact validated sidecar path.
path: PathBuf,
/// Content-free validation or SQLite diagnostic.
message: String,
},
/// A line in the JSONL file is not valid JSON.
#[error("invalid JSON in session file: {0}")]
InvalidJson(String),
/// The requested session was not found.
#[error("session not found: {0}")]
SessionNotFound(Uuid),
/// The requested entry ID was not found in the session.
#[error("entry not found: {0}")]
EntryNotFound(String),
/// The requested branch ID was not found.
#[error("branch not found: {0}")]
BranchNotFound(String),
/// Failed to parse a session file.
#[error("failed to parse session file: {0}")]
ParseError(String),
/// A per-session internal mutex was poisoned by a panicking thread.
#[error("session lock poisoned")]
LockPoisoned,
/// A host-provided external session identifier is invalid.
#[error("invalid external session identifier: {0}")]
InvalidExternalId(String),
/// A durable turn cannot be committed because its persisted state is inconsistent.
#[error("durable turn error: {0}")]
DurableTurn(String),
/// A turn was already finalized with a different outcome or payload.
#[error("durable turn conflict for {turn_id}: existing={existing}, requested={requested}")]
DurableTurnConflict {
/// Turn identity whose terminal record already exists.
turn_id: String,
/// Previously persisted terminal outcome or ambiguous state.
existing: String,
/// Requested terminal outcome.
requested: String,
},
}