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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Identifier newtypes and lifecycle enums.
//!
//! These ids are the keys that make recursion observable and correlatable: a
//! [`RunId`] names one run, and pairing it with the `root_run_id` /
//! `parent_run_id` recorded in [`crate::harness::events::HarnessRunStatus`] lets
//! a child run (a sub-agent or sub-graph invocation) be traced back up to the
//! top-level run that spawned it. A `From`/`Display`/`as_str` surface is
//! generated for each newtype by a single macro so the ids stay cheap to clone,
//! log, and serialize.
//!
//! See [`types`] for the type definitions. This module provides the shared
//! constructors, accessors, and conversions for every id newtype.
pub use *;
/// Implements the common surface (`new`, `as_str`, `Display`, `From`) for a
/// string-backed id newtype.
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
impl_string_id!;
use OnceLock;
use ;
use ;
/// Process-unique monotonic sequence source for deterministic, dependency-free
/// id generation.
///
/// Reused by the id constructors below instead of wall-clock time or randomness
/// so ids stay reproducible across platforms and easy to assert in tests.
static ID_SEQ: AtomicU64 = new;
/// Returns the next process-unique monotonic sequence number.
///
/// This is the single id-allocation primitive shared by the `new_*_id`
/// helpers; it never repeats within a process and requires no `rand`,
/// `SystemTime`, or `Date` dependency.
/// Returns a per-process nonce, stable for the lifetime of the process and
/// (in practice) distinct across restarts.
///
/// The bare monotonic [`next_seq`] restarts at `0` in every new process, so ids
/// built from it alone (`ckpt-0`, `ckpt-1`, …) *collide* across a restart — a
/// resumed thread would re-mint checkpoint ids it already used, corrupting the
/// parent-lineage map and time-travel resume. Mixing in this nonce makes ids
/// collision-free across restarts while [`next_seq`] keeps them ordered within
/// a process. Seeded once from the wall clock (nanoseconds since the epoch);
/// only ever used as an opaque uniqueness component, never parsed or compared
/// for time.
/// Returns the current wall-clock time in milliseconds since the Unix epoch,
/// or `0` if the clock is set before the epoch.
///
/// The single `now_ms` used across the crate for timestamping records,
/// checkpoints, goals, and observability events, so the epoch/`unwrap_or(0)`
/// convention lives in exactly one place instead of being re-hand-rolled in
/// every module that needs a millisecond timestamp.
/// Allocates a fresh [`RunId`] of the form `run-<nonce>-<n>`, collision-free
/// across process restarts (see [`process_nonce`]).
/// Allocates a fresh [`CheckpointId`] of the form `ckpt-<nonce>-<n>`,
/// collision-free across process restarts (see [`process_nonce`]).
///
/// Restart-safety is essential here: checkpoint ids are the keys of the
/// parent-lineage spine that `prune`, `get_state_history`, and
/// `ResumeTarget::Checkpoint` all walk, so a duplicate id across a restart can
/// delete a live record's ancestor or resume the wrong checkpoint.
/// Allocates a fresh, process-unique [`SessionId`] of the form `session-<n>`.
/// Allocates a fresh, process-unique [`CellId`] of the form `cell-<n>`.
/// Allocates a fresh, process-unique [`CallId`] of the form `call-<n>`.