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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
//! Tap event identifiers for the core observability surface.
//!
//! These constants define the tap event IDs used throughout the observability
//! infrastructure. Keep them in sync with the documentation in `observe::core`.
//!
//! # Dual-Ring Event ID Allocation
//!
//! Events are routed to separate ring buffers based on ID range:
//!
//! - **User Ring** (`0x0000..0x00FF`): Application/EPF events (TAP_OUT, custom events)
//! - **Infra Ring** (`0x0100..0xFFFF`): System events (ENDPOINT_SEND, LANE_ACQUIRE, etc.)
//!
//! This separation prevents Observer Effect feedback loops where streaming
//! infrastructure events flood the ring and trigger continuous wake cycles.
// ────────────── Event ID Range Boundaries ──────────────
/// Upper bound (exclusive) for User Ring events.
/// Events with `id < USER_EVENT_RANGE_END` are routed to the User Ring.
pub const USER_EVENT_RANGE_END: u16 = 0x0100;
// ────────────── Endpoint boundary (0x0200-0x020F) ──────────────
/// Control abort initiated.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Lane / reason payload (u32)
pub const ABORT_BEGIN: u16 = 0x0200;
/// Control abort acknowledged.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Lane that observed the acknowledgement (u32)
pub const ABORT_ACK: u16 = 0x0201;
/// Endpoint send operation observed at the tap boundary.
///
/// - `arg0`: Packed role/lane/label/flags (u32)
/// - `arg1`: Session identifier (u32)
pub const ENDPOINT_SEND: u16 = 0x0202;
/// Endpoint receive operation observed at the tap boundary.
///
/// - `arg0`: Packed role/lane/label/flags (u32)
/// - `arg1`: Session identifier (u32)
pub const ENDPOINT_RECV: u16 = 0x0203;
/// Endpoint control-plane event (state snapshot, state restore, abort, ...).
///
/// - `arg0`: Packed role/lane/label/flags (u32)
///
pub const ENDPOINT_CONTROL: u16 = 0x0204;
/// Topology handshake initiated.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Generation / causal context (u32)
pub const TOPOLOGY_BEGIN: u16 = 0x0208;
/// Topology handshake acknowledged.
///
/// - `arg0`: from_lane (u8) | to_lane (u8) << 8 | generation (u16) << 16
/// - `arg1`: Session identifier (u32)
pub const TOPOLOGY_ACK: u16 = 0x0209;
/// Topology handshake committed.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Generation acknowledged (u32)
pub const TOPOLOGY_COMMIT: u16 = 0x020A;
// ───────────── Lane lifecycle (0x0210-0x021F) ─────────────
/// Lane acquired via LaneLease (RAII lifecycle start).
///
/// - `arg0`: Rendezvous identifier (u32)
/// - `arg1`: Packed session/lane (u32)
///
/// # Observable Properties
/// - Every LANE_ACQUIRE must eventually have a matching LANE_RELEASE
/// - Multiple LANE_ACQUIRE for the same lane without RELEASE indicates violation
pub const LANE_ACQUIRE: u16 = 0x0210;
/// Lane released via LaneLease::Drop (RAII lifecycle end).
///
/// - `arg0`: Rendezvous identifier (u32)
/// - `arg1`: Packed session/lane (u32)
///
/// # Observable Properties
/// - Must follow LANE_ACQUIRE for the same lane
/// - Enables streaming verification of lane lifecycle correctness
pub const LANE_RELEASE: u16 = 0x0211;
// ───────────── Route / Loop control (0x0220-0x022F) ─────────────
/// Loop decision recorded (continue/break).
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: lane<<16 | idx<<8 | disposition (1 = continue, 0 = break)
pub const LOOP_DECISION: u16 = 0x0220;
/// Route arm selection resolved via dynamic policy.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: scope_id<<16 | arm (u32)
/// - `causal`: lane marker with decision encoded in the sequence field (0 = skip, 1 = send)
pub const ROUTE_DECISION: u16 = 0x0221;
// ───────────── Capability lifecycle (0x0240-0x024F) ─────────────
///
/// Base identifier for capability mint events. Actual tap IDs are computed as
/// `CAP_MINT_BASE + ResourceKind::TAG as u16` to yield `CAP_MINT::<K>`.
///
/// Emitted when a new capability token is created via:
/// - `Rendezvous::mint_cap`
/// - endpoint local control send paths such as `flow().send()`
///
/// # Event Encoding
/// - `arg0`: Session ID (u32) or packed lane/role/kind/shot
/// - `arg1`: Capability identifier (u32) or 0 for nonce-based tokens
///
/// # Observable Properties
/// - Every CAP_MINT must eventually have a matching CAP_CLAIM
/// - One-shot: CAP_MINT → CAP_CLAIM → CAP_EXHAUST
/// - Many-shot: CAP_MINT → CAP_CLAIM (no EXHAUST)
pub const CAP_MINT_BASE: u16 = 0x0240;
/// Capability token claimed (validation succeeded).
///
/// Base identifier for capability claim events. Actual tap IDs are computed as
/// `CAP_CLAIM_BASE + ResourceKind::TAG as u16` to yield `CAP_CLAIM::<K>`.
///
/// Emitted when a capability token is successfully validated via:
/// - `Rendezvous::claim_cap`
///
/// # Event Encoding
/// - `arg0`: Session ID (u32) or packed lane/role/kind/shot
/// - `arg1`: Capability identifier (u32) or 0 for nonce-based tokens
///
/// # Observable Properties
/// - Must follow CAP_MINT for the same session
/// - One-shot: first claim succeeds, subsequent claims return Exhausted
/// - Many-shot: multiple claims succeed
pub const CAP_CLAIM_BASE: u16 = 0x0241;
/// One-shot capability exhausted (lifecycle complete).
pub const CAP_EXHAUST_BASE: u16 = 0x0242;
/// Session effect initialisation completed.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Number of control effects/materialised resources (u32)
pub const EFFECT_INIT: u16 = 0x0500;
/// State snapshot request issued by the state-restore subsystem.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Generation marker (u32)
pub const STATE_SNAPSHOT_REQ: u16 = 0x0130;
/// State restore requested.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Target generation (u32)
pub const STATE_RESTORE_REQ: u16 = 0x0131;
/// State restore completed successfully.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Generation restored (u32)
pub const STATE_RESTORE_OK: u16 = 0x0132;
/// Policy transaction abort requested.
///
/// - `arg0`: Session identifier (u32)
/// - `arg1`: Snapshot generation restored (u32)
pub const POLICY_TX_ABORT: u16 = 0x0411;
/// Transport-level telemetry event (ACK / Loss notification).
///
/// - `arg0`: Lower 32 bits of the packet number
/// - `arg1`: Packed payload length / retransmission counters
pub const TRANSPORT_EVENT: u16 = 0x0212;
/// Transport-level congestion metrics snapshot.
///
/// - `arg0`: `[ algo | queue_depth | srtt_scaled ]`
/// - `arg1`: `[ congestion_window_kib | in_flight_kib ]`
pub const TRANSPORT_METRICS: u16 = 0x0213;
/// Transport-level congestion metrics extension payload.
///
/// - `arg0`: `[ retransmissions | congestion_marks ]`
/// - `arg1`: Pacing interval in microseconds (0 indicates absent)
pub const TRANSPORT_METRICS_EXT: u16 = 0x0214;
/// Delegation begins (tracks shot discipline and in-flight count).
///
/// - `arg0`: Service identifier (high 32 bits of 64-bit id)
/// - `arg1`: Low 32 bits | shot flag << 31 | in-flight count
pub const DELEG_BEGIN: u16 = 0x0230;
/// Routing policy selected a target shard/node.
///
/// - `arg0`: Policy identifier
/// - `arg1`: Shard or node identifier (u32)
///
/// # Observable Properties
/// - Occurs after `DELEG_BEGIN` and before topology acknowledgement
/// - Enables auditing of routing decisions
pub const ROUTE_PICK: u16 = 0x0231;
/// Policy VM requested a session abort (mapped to abort_begin/ack).
///
/// - `arg0`: Abort reason (u16 promoted to u32)
/// - `arg1`: Session identifier when known, otherwise 0
pub const POLICY_ABORT: u16 = 0x0400;
/// Policy VM emitted an annotation via ACT_ANNOT.
///
/// - `arg0`: Annotation key (u16 promoted to u32)
/// - `arg1`: Annotation value (u32)
pub const POLICY_ANNOT: u16 = 0x0401;
/// Policy VM trapped (fuel exhausted, illegal opcode/syscall, verify failure).
///
/// - `arg0`: Trap kind discriminant
/// - `arg1`: Session identifier when known, otherwise 0
pub const POLICY_TRAP: u16 = 0x0402;
/// Policy VM dispatched a control-plane effect.
///
/// - `arg0`: ControlOp discriminant (u16 promoted to u32)
/// - `arg1`: Effect operand when present, otherwise 0
pub const POLICY_EFFECT: u16 = 0x0403;
/// Policy-requested control-plane effect completed successfully.
///
/// - `arg0`: ControlOp discriminant (u16 promoted to u32)
/// - `arg1`: Session identifier when known, otherwise 0
pub const POLICY_RA_OK: u16 = 0x0404;
/// Policy VM slot activation scheduled after Load→Commit.
///
/// - `arg0`: Slot identifier (0=Forward,1=EndpointRx,2=EndpointTx,3=Rendezvous)
/// - `arg1`: Activated version identifier
pub const POLICY_COMMIT: u16 = 0x0405;
/// Policy VM slot restored to a previous version.
///
/// - `arg0`: Slot identifier (0=Forward,1=EndpointRx,2=EndpointTx,3=Rendezvous)
/// - `arg1`: Version identifier restored
pub const POLICY_STATE_RESTORE: u16 = 0x0406;
/// Policy audit core digest tuple.
///
/// - `arg0`: policy_digest
/// - `arg1`: event_hash
/// - `arg2`: signals_input_hash
pub const POLICY_AUDIT: u16 = 0x0407;
/// Policy audit extension digest tuple.
///
/// - `arg0`: signals_attrs_hash
/// - `arg1`: transport_snapshot_hash
/// - `arg2`: slot/mode metadata
pub const POLICY_AUDIT_EXT: u16 = 0x0408;
/// Policy audit verdict tuple.
///
/// - `arg0`: verdict metadata (`tag<<24 | arm<<16`)
/// - `arg1`: reject reason (0 unless `Reject`)
/// - `arg2`: fuel_used
pub const POLICY_AUDIT_RESULT: u16 = 0x0409;
/// Policy replay event tuple.
///
/// - `arg0`: triggering event id (u16 promoted to u32)
/// - `arg1`: triggering event arg0
/// - `arg2`: triggering event arg1
pub const POLICY_REPLAY_EVENT: u16 = 0x040A;
/// Policy replay input tuple (first three input words).
///
/// - `arg0`: policy_input[0]
/// - `arg1`: policy_input[1]
/// - `arg2`: policy_input[2]
pub const POLICY_REPLAY_INPUT0: u16 = 0x040B;
/// Policy replay input tuple (last input word).
///
/// - `arg0`: policy_input[3]
/// - `arg1`: reserved (0)
/// - `arg2`: reserved (0)
pub const POLICY_REPLAY_INPUT1: u16 = 0x040C;
/// Policy replay transport tuple (latency/queue/congestion).
///
/// - `arg0`: latency_us (saturated to u32, 0 when unavailable)
/// - `arg1`: queue_depth
/// - `arg2`: congestion_marks
pub const POLICY_REPLAY_TRANSPORT0: u16 = 0x040D;
/// Policy replay transport tuple (retry count).
///
/// - `arg0`: retransmissions
/// - `arg1`: presence bitmask (bit0 latency, bit1 queue, bit2 congestion, bit3 retry)
/// - `arg2`: reserved (0)
pub const POLICY_REPLAY_TRANSPORT1: u16 = 0x040E;
/// Policy replay event extension tuple.
///
/// - `arg0`: triggering event arg1
/// - `arg1`: triggering event arg2
/// - `arg2`: triggering event causal key (u16 promoted to u32)
pub const POLICY_REPLAY_EVENT_EXT: u16 = 0x040F;
/// Policy liveness/defer audit tuple.
///
/// - `arg0`: `defer_source<<24 | retry_hint<<16 | remaining_budget`
/// (`defer_source` is not a `RouteDecisionSource` tap sequence)
/// - `arg1`: `scope_slot<<16 | selected_arm<<8 | ready_arm_mask`
/// (`scope_slot=0xFFFF` means non-route frontier, `selected_arm=0xFF` means unknown)
/// - `arg2`: `defer_reason<<16 | hint<<8 | frontier<<4 | binding_ready<<1 | exhausted_flag`
pub const POLICY_AUDIT_DEFER: u16 = 0x0410;