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
//! Worker identity and concurrency helpers.
//!
//! These helpers keep startup defaults small and deterministic while the main
//! worker loop focuses on task execution.
//!
//! # Examples
//!
//! ```ignore
//! let worker_id = generate_worker_id();
//! assert!(worker_id.starts_with("wrk_"));
//! ```
/// Generates a fresh worker identifier for registration and heartbeats.
///
/// The identifier embeds a timestamp and random suffix so concurrent workers do
/// not collide even when they start at nearly the same time.
///
/// # Examples
///
/// ```ignore
/// let worker_id = generate_worker_id();
/// assert!(worker_id.starts_with("wrk_"));
/// ```
/// Resolves the effective worker identifier from environment or fallback.
///
/// `CODETETHER_WORKER_ID` takes precedence, followed by `A2A_WORKER_ID`, then
/// a generated identifier when neither variable is set.
///
/// # Examples
///
/// ```ignore
/// let worker_id = resolve_worker_id();
/// assert!(!worker_id.trim().is_empty());
/// ```
pub
/// Clamps worker concurrency to at least one active task.
///
/// This prevents misconfiguration from disabling task processing entirely.
///
/// # Examples
///
/// ```ignore
/// assert_eq!(normalize_max_concurrent_tasks(0), 1);
/// ```
pub