a2a_protocol_server/store/
mod.rs1pub mod applied;
9pub mod claim;
10pub(crate) mod database;
11#[cfg(any(feature = "sqlite", feature = "postgres"))]
12mod delegation_journal;
13#[cfg(feature = "encryption")]
14pub mod encrypted;
15pub mod halt;
16pub mod holds;
17pub mod lease;
18#[cfg(feature = "postgres")]
19mod log_notify;
20pub(crate) mod log_wake;
21pub mod retention;
22pub mod task_store;
23pub mod tenant;
24pub mod terminal;
25#[cfg(test)]
26pub(crate) mod tests;
27#[cfg(feature = "tracing")]
28pub(crate) mod traced;
29
30#[cfg(any(feature = "sqlite", feature = "postgres"))]
32pub(crate) mod cursor;
33
34pub(crate) mod pagination;
36
37pub mod caller_keys;
38#[cfg(feature = "sqlite")]
39pub mod migration;
40#[cfg(feature = "sqlite")]
41pub mod sqlite_store;
42#[cfg(feature = "sqlite")]
43pub mod tenant_sqlite_store;
44
45#[cfg(feature = "postgres")]
48pub const DEFAULT_POOL_SIZE: u32 = 10;
49
50#[cfg(feature = "postgres")]
51pub mod pg_migration;
52#[cfg(feature = "postgres")]
53pub(crate) mod pg_retry;
54#[cfg(feature = "postgres")]
55pub(crate) mod pg_schema;
56#[cfg(feature = "postgres")]
57pub mod postgres_store;
58#[cfg(feature = "postgres")]
59pub mod tenant_postgres_store;
60
61#[cfg(any(feature = "sqlite", feature = "postgres"))]
63mod tenant_idempotency;
64
65#[cfg(any(feature = "sqlite", feature = "postgres"))]
67mod event_log_sql;
68#[cfg(any(feature = "sqlite", feature = "postgres"))]
69mod tenant_event_log;
70
71pub use applied::AppliedPosition;
72pub use claim::{
73 ClaimLost, Handed, HeldClaim, InMemoryTurnClaims, PendingSteering, TurnClaimStore,
74};
75pub use database::StoreDatabase;
76pub use halt::{HaltSignal, HaltStore, InMemoryHaltStore, StoredHalt};
77pub use holds::{DEFAULT_MAX_HELD_EVENTS_FACTOR, EventHold, EventHolds};
78pub use lease::{InMemoryLeaseStore, LeaseStore};
79#[cfg(feature = "postgres")]
80pub use log_notify::{CHANNEL as LOG_NOTIFY_CHANNEL, LogListen};
81pub use log_wake::{LogWake, LogWatch};
82pub use retention::{PurgeReport, RetentionPolicy, terminal_states};
83pub use task_store::{
89 ArtifactDelta, DEFAULT_IDEMPOTENCY_KEY_TTL, DEFAULT_MAX_EVENTS_PER_TASK,
90 DEFAULT_MAX_IDEMPOTENCY_KEYS, DEFAULT_MAX_PAGE_SIZE, HistoryLimit, IdempotencyClaim,
91 IdempotencyHolder, InMemoryTaskStore, RecordedEvent, TaskStore, TaskStoreConfig,
92};
93pub use tenant::{TenantAwareInMemoryTaskStore, TenantContext, TenantStoreConfig};
94pub use terminal::{TERMINAL_STATE_CONFLICT_MARKER, TerminalStateConflict, refuses_write};
95
96#[cfg(feature = "sqlite")]
112pub(crate) fn status_timestamp_sqlite(ts: Option<&str>) -> Option<String> {
113 let millis = status_millis(ts)?;
114 let iso = a2a_protocol_types::unix_millis_to_iso8601(millis);
115 Some(format!("{} {}", &iso[..10], &iso[11..23]))
117}
118
119#[cfg(any(feature = "sqlite", feature = "postgres"))]
125const FIRST_POSTGRES_MILLIS: i64 = -62_135_596_800_000;
126
127#[cfg(any(feature = "sqlite", feature = "postgres"))]
133fn status_millis(ts: Option<&str>) -> Option<i64> {
134 Some(
135 ts.and_then(a2a_protocol_types::parse_iso8601_to_unix_millis)?
136 .max(FIRST_POSTGRES_MILLIS),
137 )
138}
139
140#[cfg(feature = "postgres")]
147pub(crate) fn status_timestamp_rfc3339(ts: Option<&str>) -> Option<String> {
148 Some(a2a_protocol_types::unix_millis_to_iso8601(status_millis(
149 ts,
150 )?))
151}
152
153#[cfg(feature = "sqlite")]
154pub use delegation_journal::SqliteDelegationJournal;
155#[cfg(feature = "sqlite")]
156pub use halt::SqliteHaltStore;
157#[cfg(feature = "sqlite")]
158pub use migration::{Migration, MigrationRunner};
159#[cfg(feature = "sqlite")]
160pub use sqlite_store::SqliteTaskStore;
161#[cfg(feature = "sqlite")]
162pub use tenant_sqlite_store::TenantAwareSqliteTaskStore;
163
164#[cfg(feature = "postgres")]
165pub use delegation_journal::PostgresDelegationJournal;
166#[cfg(feature = "postgres")]
167pub use halt::PostgresHaltStore;
168#[cfg(feature = "postgres")]
169pub use lease::PostgresLeaseStore;
170#[cfg(feature = "postgres")]
171pub use pg_migration::{BUILTIN_PG_MIGRATIONS, PgMigration, PgMigrationRunner};
172#[cfg(feature = "postgres")]
173pub use postgres_store::PostgresTaskStore;
174#[cfg(feature = "postgres")]
175pub use tenant_postgres_store::TenantAwarePostgresTaskStore;
176
177#[cfg(test)]
178mod status_timestamp_tests {
179 #[cfg(feature = "sqlite")]
186 #[test]
187 fn sqlite_shape_is_the_column_format() {
188 assert_eq!(
189 super::status_timestamp_sqlite(Some("2026-03-15T12:00:00.123Z")).as_deref(),
190 Some("2026-03-15 12:00:00.123"),
191 );
192 assert_eq!(
195 super::status_timestamp_sqlite(Some("2026-03-15T12:00:00Z")).as_deref(),
196 Some("2026-03-15 12:00:00.000"),
197 );
198 }
199
200 #[cfg(feature = "sqlite")]
201 #[test]
202 fn sqlite_returns_none_for_missing_or_unparseable() {
203 assert_eq!(super::status_timestamp_sqlite(None), None);
204 assert_eq!(super::status_timestamp_sqlite(Some("")), None);
205 assert_eq!(
206 super::status_timestamp_sqlite(Some("not a timestamp")),
207 None
208 );
209 assert_eq!(super::status_timestamp_sqlite(Some("2026-03-15")), None);
210 }
211
212 #[cfg(feature = "sqlite")]
213 #[test]
214 fn sqlite_slicing_survives_out_of_range_years() {
215 for input in [
220 "99999-01-01T00:00:00Z",
221 "999999-12-31T23:59:59.999Z",
222 "1969-12-31T23:59:59Z",
223 "0001-01-01T00:00:00Z",
224 "+010000-01-01T00:00:00Z",
225 ] {
226 let out = super::status_timestamp_sqlite(Some(input));
227 if let Some(s) = out {
228 assert!(
229 s.is_char_boundary(0) && s.len() >= 23,
230 "{input} produced a malformed value: {s:?}"
231 );
232 }
233 }
234 }
235
236 #[cfg(feature = "postgres")]
237 #[test]
238 fn rfc3339_normalizes_to_canonical_utc() {
239 assert_eq!(
240 super::status_timestamp_rfc3339(Some("2026-03-15T12:00:00.123Z")).as_deref(),
241 Some("2026-03-15T12:00:00.123Z"),
242 );
243 assert_eq!(
247 super::status_timestamp_rfc3339(Some("2026-03-15T14:00:00+02:00")).as_deref(),
248 Some("2026-03-15T12:00:00.000Z"),
249 );
250 assert_eq!(super::status_timestamp_rfc3339(None), None);
251 assert_eq!(super::status_timestamp_rfc3339(Some("nope")), None);
252 }
253
254 #[cfg(feature = "postgres")]
262 #[test]
263 fn rfc3339_holds_a_year_postgres_timestamptz_cannot_hold_at_year_one() {
264 for (input, why) in [
265 ("0000-01-01T00:00:00Z", "the exact boundary"),
266 ("0000-12-31T23:59:59.999Z", "the last instant of year 0000"),
267 (
268 "0001-01-01T00:00:00+01:00",
269 "a positive offset moves it into 0000",
270 ),
271 ] {
272 assert_eq!(
273 super::status_timestamp_rfc3339(Some(input)).as_deref(),
274 Some("0001-01-01T00:00:00.000Z"),
275 "{input} ({why})"
276 );
277 }
278 for kept in ["0001-01-01T00:00:00Z", "0001-01-01T00:00:00.001Z"] {
281 assert_eq!(
282 super::status_timestamp_rfc3339(Some(kept)).as_deref(),
283 Some(a2a_protocol_types::unix_millis_to_iso8601(
284 a2a_protocol_types::parse_iso8601_to_unix_millis(kept).unwrap()
285 ))
286 .as_deref(),
287 "{kept}"
288 );
289 }
290 }
291
292 #[cfg(feature = "sqlite")]
295 #[test]
296 fn sqlite_holds_a_year_zero_instant_at_year_one() {
297 for input in ["0000-01-01T00:00:00Z", "0000-12-31T23:59:59.999Z"] {
298 assert_eq!(
299 super::status_timestamp_sqlite(Some(input)).as_deref(),
300 Some("0001-01-01 00:00:00.000"),
301 "{input}"
302 );
303 }
304 assert_eq!(
305 super::status_timestamp_sqlite(Some("0001-01-01T00:00:00.001Z")).as_deref(),
306 Some("0001-01-01 00:00:00.001")
307 );
308 }
309
310 #[cfg(any(feature = "sqlite", feature = "postgres"))]
312 #[test]
313 fn the_first_instant_postgres_holds_is_year_one() {
314 assert_eq!(super::FIRST_POSTGRES_MILLIS, -719_162 * 86_400 * 1000);
315 assert_eq!(
316 a2a_protocol_types::unix_millis_to_iso8601(super::FIRST_POSTGRES_MILLIS),
317 "0001-01-01T00:00:00.000Z"
318 );
319 }
320}