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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
//! Shared worker registration admission against durable package contracts.
//!
//! Admission holds a registering worker against the deployed `.v4` contracts
//! its queue can still dispatch under — the REACHABLE ones, chosen by
//! [`aion::Engine::worker_contracts_for_admission`]. Retained-but-unreachable
//! versions are named in a refusal but never held against the worker: demanding
//! them made one stale deploy enough to kill a whole task queue.
use BTreeSet;
use ;
use ActivityDescriptor;
use ;
use render_mismatch;
/// What a registering worker announced about itself, in the TWO independent
/// forms it announces it in.
///
/// These are different sets and they are used for different things, which is
/// precisely why they must travel together. `activity_types` is the NAME set the
/// dispatcher selects on; `contracts` is the typed-descriptor set admission
/// compares against the deployed `.v4` contracts. A worker can advertise a name
/// with no contract behind it — it is then selectable but not admissible.
///
/// Before this pair existed, admission received only `contracts` while the
/// refusal log printed only `activity_types`, and on 2026-07-30 that produced a
/// refusal record which listed action `assistant` as advertised in the same line
/// that reported it `<missing>`. Both facts were true of different sets and the
/// record said which of neither. Carrying both through the gate makes the
/// refusal state the gap instead of contradicting itself.
/// Typed refusal from worker contract admission.
/// Validates a worker against every REACHABLE `.v4` contract for its queue.
///
/// `node` is the connection's advertised locality, `None` when it carries none.
/// Callers holding a raw proto3 string normalize with
/// [`super::registry::optional_node`] — the SAME normalization the registry then
/// routes by, never a restatement of it, because admission decides which actions
/// a connection owes from exactly the locality the dispatcher will filter on.
///
/// Two independent narrowings apply, and both exist because a worker that is
/// doing its whole job must not be refused:
///
/// 1. Only REACHABLE package versions are held against the connection. Under
/// content-hash namespacing a queue retains every deployed version; one
/// that no longer routes and carries no live run can never produce a
/// dispatch, so demanding it protects nothing and costs the queue.
/// 2. Within a reachable version, only the actions whose dispatch can reach
/// this connection's node are demanded of it, because the server routes by
/// (namespace × `task_queue` × node) and a worker serving several nodes
/// therefore opens one connection PER NODE, each advertising only that
/// node's actions.
///
/// **Every refusal this gate returns, it also SAYS** — at WARN, on the server,
/// naming the queue, the node, the worker build and the reason, through
/// [`name_refusal`]. A caller may add transport detail of its own but must not
/// restate the refusal: the naming is the gate's, so no transport can be added
/// that forgets to do it.
///
/// # Errors
///
/// Returns [`ContractAdmissionError::Catalog`] when the deployed contracts or
/// the liveness they are judged against cannot be read — an unreadable answer
/// refuses rather than admits — and [`ContractAdmissionError::Mismatch`] with
/// the field-level diagnosis before the worker becomes dispatch-visible.
/// Which refusal site this connection belongs to, derived from the CATALOG.
///
/// A node names a site of its own only when some action demanded of this
/// connection is pinned to it. Otherwise the node cannot have changed the
/// verdict — [`aion_package::contract_diffs`] demands every unpinned action of
/// every locality — so all such connections are one site.
///
/// **This is the bound.** `task_queue` and `node` both arrive on the wire, so
/// keying on them directly lets a refused worker allocate a map entry per dial
/// by varying either. The first cut of #147 moved `identity` out of the key and
/// left `node` in it, which defeated half the trap it had itself named. Here
/// the queue is bounded because a queue with no reachable contract demands
/// nothing and is ADMITTED rather than remembered, and the node is bounded
/// because it must match a pin the catalog carries.
/// The ONE place a contract refusal is spoken, for every transport.
///
/// It lives at the gate rather than in a caller because that is the whole
/// finding behind #147: this exact defect was found, fixed and pinned on
/// 2026-07-29 — but in the liminal CALLER — and the gRPC caller re-manifested it
/// verbatim within a week, refusing every dial in silence while a `Rejected` ack
/// carried the reason nobody printed. One rule maintained in two places had
/// already drifted. A second copy of the log would have been the same mistake a
/// third time, so the naming moved INTO the gate and the liminal caller stopped
/// restating it.
///
/// Repeats are silent, and that is a transition rule rather than a rate limit:
/// see [`AdmissionAudit`] for why an identical redial carries no information and
/// why nothing here is a configurable cap.
///
/// `site` decides whether to SPEAK and is server-derived ([`refusal_site`]);
/// `task_queue` and `node` are what the connection actually advertised and are
/// only ever PRINTED. They diverge when the refusal is node-independent, or
/// when the catalog could not be read at all, and the line reports the real
/// ones because they are true facts about the dial being refused — the operator
/// needs to know which dial produced this, even when the fault is not its own.
/// One field-level disagreement, carrying why its version was demanded.