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
//! §Fase 114.a — **the budget gate, in ONE place, on EVERY tool path.**
//!
//! # The live bug this closes
//!
//! `budget { rate: 100 per minute on Tool(Search) }` parses, type-checks
//! (`axon-T830`–`T834`), and its kernel is **real**: a refilling token bucket, a
//! tumbling window, fail-closed, with `on_exhausted ∈ {block, defer, shed}`
//! honoured.
//!
//! Until §114.a it was wired to **exactly one** dispatch site —
//! `pure_shape::run_step_streaming_tool` — which you reach only if **all three**
//! hold:
//!
//! 1. the tool declares `effects: stream:*` (`derive_is_streaming`), **and**
//! 2. the call happens inside a `daemon`, **and**
//! 3. you are on the enterprise supervisor (OSS's `run_daemon` has zero callers).
//!
//! **The canonical `use Tool(…)` path had zero budget references.** `ctx.budget`
//! appeared in one file in the entire crate.
//!
//! And the sharpest part of it:
//!
//! > `advertised.rs` certifies `tool` as **Real**, citing as its proof
//! > *`lambda_tools::dispatch_use_tool_real`* — **the very function where its
//! > budget did not run.**
//!
//! So an adopter wrote a budget over their vendor, the compiler accepted it, and
//! **in an ordinary flow it did nothing.** That is not a design gap; it is a live
//! governance hole on the primitive the product's safety story rests on.
//!
//! # Why this is a module and not a copy-paste
//!
//! The obvious fix is to paste the gate into `lambda_tools` too. That would make
//! **two copies of one law** — and §113 established what that costs: the key-shape
//! check for `axon-T850` had been inlined at three sites, and *three copies of a
//! law is how the islands happened*. The copies drift, and the one nobody looks at
//! quietly stops meaning anything.
//!
//! There is now **one** charge point. Every tool path calls it.
//!
//! # Why the gate must precede the emission
//!
//! A budget charged *after* the call has already been made bounds nothing — the
//! vendor was already hit, the money was already spent. Over-emission has to be
//! **impossible by construction**, not merely reported. So [`charge`] runs before
//! any request is issued, and a denial means **the call is never made.**
use crate;
use crateGateDecision;
/// What the budget decided about one tool emission.
/// Charge one tool emission against the program's `budget`.
///
/// Called **before** the request is issued, on every tool path. `Err` ⇒ the call
/// must not happen.
///
/// - `block` (the default) ⇒ [`DispatchError::EffectQuotaExhausted`] — fail-closed.
/// - `defer` ⇒ [`DispatchError::EffectDeferred`] — a *distinct* error,
/// so a supervisor reschedules instead of failing.
/// - `shed` ⇒ [`BudgetGrant::Shed`] — skip the call, continue the flow.