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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! # Authoritative task registry
//!
//! The registry owns active task identities, names, actor handles, and final cleanup.
//! A task remains registered until its actor is joined and both indexes are released.
//!
//! ## Internal Layout
//!
//! - `protocol`: management commands and direct replies.
//! - `completion`: watched outcomes and terminal cleanup signals.
//! - `state`: the two synchronized indexes, entry state, and pending joins.
//! - `admission`: actor creation and atomic single or batch registration.
//! - `removal`: removal claims, actor joins, outcomes, and cleanup.
//! - `listener`: command and completion dispatch.
//!
//! ## Data Flow
//!
//! Management decisions use two separate transports:
//!
//! | Direction | Transport |
//! |---------------------------------------|----------------------------------|
//! | `SupervisorCore` -> registry listener | Bounded management command queue |
//! | Registry listener -> calling method | Direct one-shot reply |
//!
//! Actor joins have one owner:
//!
//! | Cleanup trigger | Actor-handle owner |
//! |------------------------------------------------|-----------------------------------------|
//! | Winning actor-completion claim in the listener | Detached join reporter |
//! | Winning `Remove` or `Cancel` claim | Detached join reporter |
//! | Claim made by `cancel_all_within` | Task currently running shutdown cleanup |
//!
//! Every owner uses the same terminal commit.
//! It removes the [`TaskId`] and name from both indexes, resolves an optional watched [`TaskOutcome`](super::outcome::TaskOutcome),
//! completes cancellation waiters, and publishes the final `TaskRemoved` event.
//!
//! The registry listener serializes management admission and removal-claim decisions.
//! Shutdown can claim remaining handles directly; the shared state lock arbitrates that work with the listener.
//! Actor joins run concurrently outside the listener.
//! Final index removal uses the same state lock.
//!
//! Backpressure applies only to the bounded management queue.
//! Actor completion signals and shutdown fences use separate internal unbounded channels.
//!
//! Management commands, reliable completion signals, and shutdown drive registry state.
//! Events only describe that work; losing an event cannot block cleanup or keep a controller slot occupied.
//!
//! ## Invariants
//!
//! - Both identity indexes change under one write lock.
//! - A name stays reserved while its entry is registered or being removed.
//! - One removal claim owns the actor join handle. Later cancellation calls can wait on the same completion signal.
//! - An accepted registration releases task bodies only after indexing and its `TaskAdded` publication and direct reply send are attempted.
//! - An accepted static batch completes those steps for every entry before releasing any task body.
//! - Only terminal join cleanup removes membership. Best-effort events cannot do it.
//! - Before graceful task drain starts, every management command committed before admission closes reaches its direct registry decision.
use ;
use ;
use CancellationToken;
use crate::;
pub use ;
// Keep the pre-decomposition `core::registry` protocol surface intact.
pub use ;
use ListenerState;
use ;
use ;
use ;
/// Owns registered tasks and their membership state.
///
/// It accepts management commands, receives actor completion signals, joins actors, resolves watched outcomes, and publishes registry lifecycle events.
///
/// # Also
///
/// - [`TaskActor`](super::actor::TaskActor) - per-task actor spawned by the registry
/// - [`SupervisorCore`](super::runtime::SupervisorCore) - sends registry commands
/// - [`TaskOutcome`](super::outcome::TaskOutcome) - final result for watched tasks
pub