fair_machines 0.1.5-x86_64-linux → 0.6.1-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3c4faee52a632fb98e06653ec81b1c60b779479aeadc28bf6dde0fa8622762e
4
- data.tar.gz: cea172d1a0cb2679bbd9ef3db6defbc2d62983082c282c5c688a4bcefc3fca34
3
+ metadata.gz: 8b830afdcd96e74d19fcf9dfc2c7bd0b24a857d0d7d6a1c96178d494531f3351
4
+ data.tar.gz: ed7194ee41e98050ba6e0746bc694f2b962730f60d0c46f707944089600f8d92
5
5
  SHA512:
6
- metadata.gz: 58e781a081e6f3afe3a874cd07224a52cfd8be2ec1cb3cf8598c3d9910e7aa9581ca7c14dc0fc68ce019d2a4e3bc641b14933bcf9cf2944772620a1e2f4264e7
7
- data.tar.gz: 797826760ab020f80c912e2cdfebcc255de233dd5df05e8643811eb718568e3c8b15f8d15f9018683bd355944b622a1569da6d54d4ad5a537d7f6d6f34fd85ec
6
+ metadata.gz: 25f0bdc037d0f75085e8c49ebe0828423a8b6edfc7baf5a9f2cc947facf08f5eecffd69599caeb9f54ebe2784238cda2a1af4f357a3c1410cd0a33ef2c3519b4
7
+ data.tar.gz: 7f72de7e97b20841c6c08c73603051864b0fa8c9eec864b64492aa3f9c557b839b45029a6761181aae09806a42a0ed5d2d724cdcddce4b5e8f866658326aa2a6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.1](https://github.com/seuros/fair_machines/compare/fair_machines/v0.6.0...fair_machines/v0.6.1) (2026-11-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * fix wrapped classes at load so building a value runs no Ruby ([eb9ca70](https://github.com/seuros/fair_machines/commit/eb9ca70c43f9165eacdcfb00d54a482d303ee07b))
9
+
10
+ ## [0.6.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.5.1...fair_machines/v0.6.0) (2026-11-16)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * seal TenantFair and KeyedFair against subclassing
16
+
17
+ ### Features
18
+
19
+ * seal TenantFair and KeyedFair against subclassing ([74f1b9c](https://github.com/seuros/fair_machines/commit/74f1b9c6f3d283689441bfa7a8e469da16695f4f))
20
+
21
+ ## [0.5.1](https://github.com/seuros/fair_machines/compare/fair_machines/v0.5.0...fair_machines/v0.5.1) (2026-11-14)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **deps:** require matryona-machines >= 0.4 ([04666de](https://github.com/seuros/fair_machines/commit/04666de21538f824df21f6012e2cbbeca419bafe))
27
+
28
+ ## [0.5.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.4.0...fair_machines/v0.5.0) (2026-11-14)
29
+
30
+
31
+ ### ⚠ BREAKING CHANGES
32
+
33
+ * adopt matryona-machines 0.3 (optional_positive heads, integer_in lanes)
34
+
35
+ ### Features
36
+
37
+ * adopt matryona-machines 0.3 (optional_positive heads, integer_in lanes) ([fd6b0cf](https://github.com/seuros/fair_machines/commit/fd6b0cf9ff26bb52d4a8606a0bc4cc7bf27a5be6))
38
+
39
+ ## [0.4.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.3.0...fair_machines/v0.4.0) (2026-11-14)
40
+
41
+
42
+ ### ⚠ BREAKING CHANGES
43
+
44
+ * build the binding on matryona-machines 0.2; compiler-checked refusal symbols; read Lane fields from the struct; ship no test files
45
+
46
+ ### Features
47
+
48
+ * build the binding on matryona-machines 0.2; compiler-checked refusal symbols; read Lane fields from the struct; ship no test files ([9e05fa0](https://github.com/seuros/fair_machines/commit/9e05fa06ec652a0693d0d83f4fd5c5e63fc96f31))
49
+
50
+ ## [0.3.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.2.0...fair_machines/v0.3.0) (2026-11-14)
51
+
52
+
53
+ ### ⚠ BREAKING CHANGES
54
+
55
+ * validate Lane through the core, seal it, exact-class reads, clone-then-keep admit
56
+
57
+ ### Features
58
+
59
+ * validate Lane through the core, seal it, exact-class reads, clone-then-keep admit ([2f819ae](https://github.com/seuros/fair_machines/commit/2f819aeed1bfc76251be703b14e8dafd6d17ee45))
60
+
61
+ ## [0.2.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.1.5...fair_machines/v0.2.0) (2026-11-13)
62
+
63
+
64
+ ### ⚠ BREAKING CHANGES
65
+
66
+ * converted to the fleet conventions. One exhaustive Refusal per crate, Result from every operation that can refuse, a refusal changes nothing, provable idempotent repeats are honoured, Ruby mirrors the core. No compatibility aliases. Requires flow-machines >= 0.3 and priority-machines >= 0.4.
67
+
68
+ ### Features
69
+
70
+ * answer Result<_, Refusal>, refuse unadmitted heads in select, mirror the core positionally in Ruby ([5e73ef6](https://github.com/seuros/fair_machines/commit/5e73ef67f86a0326709e27eca46d8f97bccd8aba))
71
+
3
72
  ## [0.1.5](https://github.com/seuros/fair_machines/compare/fair_machines/v0.1.4...fair_machines/v0.1.5) (2026-11-07)
4
73
 
5
74
 
data/README.md CHANGED
@@ -12,11 +12,11 @@ gem 'fair_machines'
12
12
 
13
13
  ```ruby
14
14
  # Two tenants. Each may have 100 units of work queued; each gets 2 units per round.
15
- fair = FairMachines::TenantFair.new(capacities: [100, 100], quanta: [2, 2])
15
+ fair = FairMachines::TenantFair.new([100, 100], [2, 2]) # capacities, quanta
16
16
 
17
17
  # Enterprise tenant enqueues ten PDF exports at cost 5. Small tenant queues five emails at cost 1.
18
- 10.times { fair.admit(tenant: 0, cost: 5) }
19
- 5.times { fair.admit(tenant: 1, cost: 1) }
18
+ 10.times { fair.admit(0, 5) } # => :admitted (tenant, cost)
19
+ 5.times { fair.admit(1, 1) }
20
20
 
21
21
  # Each round, tell the scheduler the cost at the head of every tenant's queue.
22
22
  # It answers with the tenant whose head runs now. You pop that job and run it.
@@ -58,7 +58,7 @@ end
58
58
 
59
59
  ## The Flight Plan
60
60
 
61
- Each tenant is either idle or has cost queued. Admission moves cost in, dispatch and cancellation move it out, and a full budget turns new work away.
61
+ Each tenant is either idle or has cost queued. Admission moves cost in, dispatch and cancellation move it out, and a full budget turns new work away. A refusal moves nothing.
62
62
 
63
63
  ```mermaid
64
64
  stateDiagram-v2
@@ -82,9 +82,9 @@ sequenceDiagram
82
82
  participant W as Workers
83
83
 
84
84
  E->>F: admit cost 5, ten times
85
- F-->>E: true, true, true...
85
+ F-->>E: :admitted, :admitted...
86
86
  S->>F: admit cost 1
87
- F-->>S: true
87
+ F-->>S: :admitted
88
88
 
89
89
  W->>F: select([5, 1])
90
90
  F-->>W: tenant 1
@@ -104,44 +104,54 @@ sequenceDiagram
104
104
 
105
105
  ### Admit
106
106
 
107
- Before a job is enqueued, ask whether the tenant has room for its cost. The answer is a plain boolean, and `false` means the job doesn't go on the queue.
107
+ Before a job is enqueued, ask whether the tenant has room for its cost. `:admitted` means it does and the cost is now on the ledger. Anything else is a refusal, and the job doesn't go on the queue.
108
108
 
109
109
  ```ruby
110
- fair = FairMachines::TenantFair.new(capacities: [10, 5], quanta: [3, 1])
111
-
112
- fair.admit(tenant: 1, cost: 5) # => true budget 5, now full
113
- fair.admit(tenant: 1, cost: 1) # => false over budget
114
- fair.admit(tenant: 2, cost: 1) # => false no such tenant
115
- fair.tenant_count # => 2
110
+ fair = FairMachines::TenantFair.new([10, 5], [3, 1])
111
+
112
+ fair.admit(1, 5) # => :admitted budget 5, now full
113
+ fair.admit(1, 1) # => :insufficient over budget
114
+ fair.admit(2, 1) # => :unknown_tenant no such tenant
115
+ fair.in_flight(1) # => 5
116
+ fair.available(1) # => 0
117
+ fair.tenant_count # => 2
116
118
  ```
117
119
 
118
- Over-budget is a refusal, not an error. Decide what to do with the job: reject it, hold it, tell the tenant.
120
+ Over-budget is a refusal, not an error. Decide what to do with the job: reject it, hold it, tell the tenant. Every answer is a symbol and every symbol is truthy, so don't write `if fair.admit(...)`. Compare against `:admitted`.
119
121
 
120
122
  ### Select
121
123
 
122
124
  Each round, pass the head cost of every tenant's queue. You get back the tenant whose head runs now, or `nil` when nobody is eligible. The chosen tenant is charged that cost against its budget, so the room comes back as the work drains.
123
125
 
124
126
  ```ruby
125
- fair = FairMachines::TenantFair.new(capacities: [10, 5], quanta: [3, 1])
126
- fair.admit(tenant: 0, cost: 4)
127
- fair.admit(tenant: 1, cost: 1)
128
-
129
- fair.select([4, 1]) # => 1
130
- fair.select([4, nil]) # => 0
131
- fair.select([4, nil]) # => nil tenant 0 has nothing left queued
132
- fair.admit(tenant: 0, cost: 7) # => true the dispatched 4 freed its room
127
+ fair = FairMachines::TenantFair.new([10, 5], [3, 1])
128
+ fair.admit(0, 4)
129
+ fair.admit(1, 1)
130
+
131
+ fair.select([4, 1]) # => 1
132
+ fair.select([4, nil]) # => 0
133
+ fair.select([nil, nil]) # => nil both queues are empty
134
+ fair.admit(0, 7) # => :admitted the dispatched 4 freed its room
133
135
  ```
134
136
 
135
- Heads have to be truthful. A head that costs more than the tenant has admitted is not eligible and `select` returns `nil` for it.
137
+ `nil` means one thing: every head you passed was `nil`.
138
+
139
+ Heads have to be truthful. A head that costs more than its tenant has admitted was never admitted, so it can't be dispatched. `select` refuses the whole round with `:exceeds_in_flight` and changes nothing, rather than quietly skipping that tenant and leaving you to wonder why its jobs never run.
140
+
141
+ ```ruby
142
+ fair.select([8, nil]) # => :exceeds_in_flight tenant 0 only admitted 7
143
+ fair.select([7, 1]) # => :exceeds_in_flight tenant 1 admitted nothing
144
+ fair.select([7, nil]) # => 0
145
+ ```
136
146
 
137
147
  ### Share is by cost, not by count
138
148
 
139
149
  Quanta are how much cost each tenant may dispatch per round, with leftover carried to the next round. A tenant whose head is expensive waits until it has saved up. A tenant with cheap jobs runs one every round.
140
150
 
141
151
  ```ruby
142
- fair = FairMachines::TenantFair.new(capacities: [50, 50], quanta: [2, 2])
143
- fair.admit(tenant: 0, cost: 40) # heavy jobs at cost 4
144
- fair.admit(tenant: 1, cost: 10) # light jobs at cost 1
152
+ fair = FairMachines::TenantFair.new([50, 50], [2, 2])
153
+ fair.admit(0, 40) # heavy jobs at cost 4
154
+ fair.admit(1, 10) # light jobs at cost 1
145
155
 
146
156
  Array.new(10) { fair.select([4, 1]) }
147
157
  # => [1, 1, 0, 1, 1, 1, 1, 0, 1, 1]
@@ -152,9 +162,9 @@ Same quanta, same share of the pool, and the light tenant still dispatches four
152
162
  Give one tenant a bigger quantum and it gets a bigger share of the pool outright:
153
163
 
154
164
  ```ruby
155
- fair = FairMachines::TenantFair.new(capacities: [20, 20], quanta: [3, 1])
156
- fair.admit(tenant: 0, cost: 20)
157
- fair.admit(tenant: 1, cost: 20)
165
+ fair = FairMachines::TenantFair.new([20, 20], [3, 1])
166
+ fair.admit(0, 20)
167
+ fair.admit(1, 20)
158
168
 
159
169
  Array.new(8) { fair.select([1, 1]) }
160
170
  # => [0, 0, 0, 1, 0, 0, 0, 1]
@@ -165,38 +175,72 @@ Array.new(8) { fair.select([1, 1]) }
165
175
  A job that leaves the queue without being dispatched has to give its cost back, or the tenant's budget leaks until nothing is admitted.
166
176
 
167
177
  ```ruby
168
- fair = FairMachines::TenantFair.new(capacities: [10, 5], quanta: [3, 1])
169
- fair.admit(tenant: 0, cost: 4)
178
+ fair = FairMachines::TenantFair.new([10, 5], [3, 1])
179
+ fair.admit(0, 4)
170
180
 
171
- fair.cancel(tenant: 0, cost: 4) # => true
172
- fair.cancel(tenant: 0, cost: 1) # => false nothing left to cancel
173
- fair.select([4, nil]) # => nil the queue is empty, and so is the ledger
181
+ fair.cancel(0, 4) # => :cancelled
182
+ fair.cancel(0, 1) # => :exceeds_in_flight nothing left to cancel
183
+ fair.select([nil, nil]) # => nil the queue is empty, and so is the ledger
174
184
  ```
175
185
 
176
- Cancelling more than was admitted is refused, and the ledger is untouched.
186
+ Cancelling more than was admitted is refused, and the ledger is untouched. The ledger counts cost, not jobs: it can't tell a cancel you sent twice from two jobs of the same cost. Cancel each job once.
177
187
 
178
188
  ### Too many tenants to name: `KeyedFair`
179
189
 
180
- Sixteen tenant slots is a crew roster. Orgs, API keys and IP prefixes are a starfield. `KeyedFair` hashes each key onto a fixed set of lanes, every lane with its own budget and no queue. A loud org fills its lane and gets `nil`; the other lanes don't notice. Keys that hash to the same lane share its budget, so pick enough lanes that a collision is rare.
190
+ Sixteen tenant slots is a crew roster. Orgs, API keys and IP prefixes are a starfield. `KeyedFair` hashes each key onto a fixed set of lanes, every lane with its own budget and no queue. A loud org fills its lane and gets `:insufficient`; the other lanes don't notice. Keys that hash to the same lane share its budget, so pick enough lanes that a collision is rare.
181
191
 
182
192
  ```ruby
183
- fair = FairMachines::KeyedFair.new(lanes: 64, capacity: 8)
193
+ fair = FairMachines::KeyedFair.new(64, 8) # lanes, capacity per lane
184
194
 
185
- lane = fair.admit(hash: org_id.hash, cost: 1) # => 17, or nil when that lane is full
195
+ hash = org_id.hash & 0xFFFF_FFFF_FFFF_FFFF # hashes are unsigned 64-bit
196
+ lane = fair.admit(hash, 1) # => #<data FairMachines::Lane index=17>, or :insufficient
186
197
  # ... do the work ...
187
- fair.release(lane:, cost: 1) # => true
198
+ fair.release(lane, 1) # => :released
188
199
  ```
189
200
 
190
- `lanes:` is a power of two from 1 to 256. Any Integer works as `hash:`, negatives included, so `key.hash` goes straight in.
201
+ Any lane count from 1 to 256 works. `admit` hands back the `Lane` it charged so you don't hash twice. A lane is just a bucket number wrapped in a `Data`: the same hash lands in the same lane every time, in every `KeyedFair` with as many lanes, and you can ask for one without admitting anything.
202
+
203
+ ```ruby
204
+ FairMachines::KeyedFair.lane(64, hash) # => #<data FairMachines::Lane index=17>
205
+ FairMachines::KeyedFair.lane_at(64, 63) # => #<data FairMachines::Lane index=63>
206
+ FairMachines::KeyedFair.lane_at(64, 64) # => nil
207
+ fair.in_flight(lane) # => 0
208
+ fair.release(FairMachines::Lane.new(64), 1) # => :unknown_lane
209
+ ```
191
210
 
192
211
  ## The Rules of the Escort
193
212
 
194
- - **1 to 16 tenants**, set by the length of `capacities:`. `quanta:` must be the same length. Empty, longer, or mismatched arrays raise `ArgumentError`.
195
- - **Capacities, quanta, and costs are positive Integers** below `2**32`. Zero is `ArgumentError`, negative or too large is `RangeError`, floats and strings are `TypeError`. Nothing is rounded for you.
196
- - **Heads are exactly `tenant_count` entries**, each a positive Integer or `nil`. The wrong length or a zero raises `ArgumentError`, and a float raises `TypeError`, before anything changes.
197
- - **Bad tenant indices don't raise.** `admit` and `cancel` with an unknown tenant return `false`.
198
- - **Frozen means frozen.** `freeze` the scheduler and `admit`, `cancel`, and `select` raise `FrozenError`. `tenant_count` still answers.
199
- - **A tenant that drains to empty loses its saved-up share.** Leftover quantum doesn't accumulate for a tenant with nothing queued.
213
+ - **Ruby mirrors the Rust core.** Arguments are positional, in the core's order: `TenantFair.new(capacities, quanta)`, `admit(tenant, cost)`, `KeyedFair.new(lanes, capacity)`. `Lane` is a `Data` with an `index`. Where the core has a function on the type, `KeyedFair::<LANES>::lane(hash)`, Ruby has a class method that takes the lane count first: `KeyedFair.lane(lanes, hash)`.
214
+ - **Every answer, by method.**
215
+
216
+ | Method | Honoured | Refused |
217
+ | --- | --- | --- |
218
+ | `TenantFair#admit(tenant, cost)` | `:admitted` | `:unknown_tenant`, `:insufficient` |
219
+ | `TenantFair#cancel(tenant, cost)` | `:cancelled` | `:unknown_tenant`, `:exceeds_in_flight` |
220
+ | `TenantFair#select(heads)` | the tenant to dispatch (Integer), `nil` exactly when every head is `nil` | `:exceeds_in_flight` |
221
+ | `TenantFair#in_flight(tenant)`, `#available(tenant)` | Integer, `nil` for an index that is not a tenant | never refuse |
222
+ | `KeyedFair#admit(hash, cost)` | the `Lane` charged | `:insufficient` |
223
+ | `KeyedFair#release(lane, cost)` | `:released` | `:unknown_lane`, `:exceeds_in_flight` |
224
+ | `KeyedFair#in_flight(lane)`, `#available(lane)` | Integer, `nil` for a lane this instance does not have | never refuse |
225
+ | `KeyedFair.lane(lanes, hash)` | a `Lane` | never refuses |
226
+ | `KeyedFair.lane_at(lanes, index)` | a `Lane`, `nil` for an index of `lanes` or more | never refuses |
227
+ | `tenant_count`, `lane_count` | Integer | never refuse |
228
+
229
+ Every refusal has its own symbol; there is no catch-all. No method takes a time, so no answer records a clock.
230
+ - **A refusal never raises and changes nothing.** Not a budget, not a tenant's saved share, not whose turn it is.
231
+ - **1 to 16 tenants**, set by the length of `capacities`; `quanta` must be the same length. Empty, longer, or mismatched arrays raise `RangeError`. The tenant count is the core's const generic `N`, and the core has no ceiling of its own: `TenantFair::MAX_TENANTS`, 16, is the largest `N` compiled into the binding.
232
+ - **1 to 256 lanes**, any count, not only powers of two. Outside that is `RangeError`. The lane count is the core's const generic `LANES`; `KeyedFair::MAX_LANES`, 256, is the largest compiled into the binding.
233
+ - **Wrong type is `TypeError`, wrong value is `RangeError`,** and the message names the argument (`tenant must be an Integer`, `cost must be in 1..=4294967295`). `ArgumentError` is Ruby's own, for the wrong number of arguments.
234
+ - **Capacities, quanta, and costs are positive Integers** below `2**32`. Zero, negative or too large is `RangeError`; floats and strings are `TypeError`. Nothing is rounded for you.
235
+ - **Hashes are Integers** in `0...2**64`; **tenant indices** are Integers a `usize` holds (`0...2**64` on a 64-bit platform, `0...2**32` on a 32-bit one). Negative or too large is `RangeError`. Ruby's `#hash` can be negative: mask it, as above. A tenant index past the last tenant doesn't raise; it's `:unknown_tenant`.
236
+ - **Heads are exactly `tenant_count` entries**, each a positive Integer or `nil`. The wrong length or a zero raises `RangeError`, a float `TypeError`, before anything changes.
237
+ - **`release`, `in_flight` and `available` on a `KeyedFair` take a `Lane`**, not a bare Integer. Anything else is `TypeError`.
238
+ - **A `Lane` is valid or does not exist.** `Lane.new(index)` is the core's `Lane::new(index)`: an Integer a `usize` holds, `TypeError` for anything else, `RangeError` outside the range. One you build by hand is held to the same rule as one `admit` returned. `Lane` is sealed: subclassing it raises `TypeError` and `allocate` is gone. That stops accidents, not reflection, so the binding checks too: a lane it reads must be an instance of exactly `Lane` (`TypeError` otherwise) and its index is re-checked (`RangeError`), so a lane forged with `Data#initialize` or `Marshal` never reaches the core. `TenantFair` and `KeyedFair` are sealed too: they wrap native state, and subclassing either raises `TypeError`.
239
+ - **The binding never loses work.** Everything that can raise happens before the core is called. `admit` charges a copy, builds the `Lane` it answers, and keeps the copy only if the `KeyedFair` is still unfrozen and unchanged: if building the lane raises, freezes it (`FrozenError`) or calls back into it (`RuntimeError`), nothing is charged.
240
+ - **A `Lane` is a bucket, not a ticket.** Nobody issued it and it proves nothing: anyone can build one, and two `KeyedFair`s with the same lane count agree on every lane. That's the point of hashing. Keep separate things in separate `KeyedFair`s and don't mix their lanes up.
241
+ - **Repeats aren't recognised.** `cancel` and `release` count cost, so a second one is honoured while cost remains and `:exceeds_in_flight` after. There are no ids, so nothing survives a restart either: a new ledger starts empty.
242
+ - **Frozen means frozen.** `freeze` either object and `admit`, `cancel`, `select`, and `release` raise `FrozenError`. Readers still answer.
243
+ - **A tenant that drains to empty loses its saved-up share.** Leftover quantum doesn't accumulate for a tenant with nothing queued, and a tenant you present as `nil` to `select` is treated the same.
200
244
 
201
245
  ## What You Think You're Doing vs Reality
202
246
 
@@ -207,7 +251,7 @@ Taking turns by job count hands the pool to whoever submits the heaviest jobs. F
207
251
 
208
252
  ## What's Yours
209
253
 
210
- The scheduler is a ledger, not a queue. You keep a queue per tenant, call `admit` before you push, hand `select` the cost at the head of each queue, and pop the job from the tenant it names. Your cost estimates have to be honest, because the ledger believes them. And when a job dies on the floor without running, call `cancel`, or the tenant pays for it forever.
254
+ The scheduler is a ledger, not a queue. You keep a queue per tenant, call `admit` before you push and push only on `:admitted`, hand `select` the cost at the head of each queue, and pop the job from the tenant it names. Your cost estimates have to be honest, because the ledger believes them. And when a job dies on the floor without running, call `cancel`, or the tenant pays for it forever.
211
255
 
212
256
  ## License
213
257
 
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.0](https://github.com/seuros/fair_machines/compare/fair-machines-v0.6.0...fair-machines-v0.7.0) (2026-11-16)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * seal TenantFair and KeyedFair against subclassing
9
+
10
+ ### Features
11
+
12
+ * seal TenantFair and KeyedFair against subclassing ([74f1b9c](https://github.com/seuros/fair_machines/commit/74f1b9c6f3d283689441bfa7a8e469da16695f4f))
13
+
14
+ ## [0.6.0](https://github.com/seuros/fair_machines/compare/fair-machines-v0.5.0...fair-machines-v0.6.0) (2026-11-14)
15
+
16
+
17
+ ### ⚠ BREAKING CHANGES
18
+
19
+ * build the binding on matryona-machines 0.2; compiler-checked refusal symbols; read Lane fields from the struct; ship no test files
20
+
21
+ ### Features
22
+
23
+ * build the binding on matryona-machines 0.2; compiler-checked refusal symbols; read Lane fields from the struct; ship no test files ([9e05fa0](https://github.com/seuros/fair_machines/commit/9e05fa06ec652a0693d0d83f4fd5c5e63fc96f31))
24
+
25
+ ## [0.5.0](https://github.com/seuros/fair_machines/compare/fair-machines-v0.4.0...fair-machines-v0.5.0) (2026-11-14)
26
+
27
+
28
+ ### ⚠ BREAKING CHANGES
29
+
30
+ * validate Lane through the core, seal it, exact-class reads, clone-then-keep admit
31
+
32
+ ### Features
33
+
34
+ * validate Lane through the core, seal it, exact-class reads, clone-then-keep admit ([2f819ae](https://github.com/seuros/fair_machines/commit/2f819aeed1bfc76251be703b14e8dafd6d17ee45))
35
+
36
+ ## [0.4.0](https://github.com/seuros/fair_machines/compare/fair-machines-v0.3.0...fair-machines-v0.4.0) (2026-11-13)
37
+
38
+
39
+ ### ⚠ BREAKING CHANGES
40
+
41
+ * converted to the fleet conventions. One exhaustive Refusal per crate, Result from every operation that can refuse, a refusal changes nothing, provable idempotent repeats are honoured, Ruby mirrors the core. No compatibility aliases. Requires flow-machines >= 0.3 and priority-machines >= 0.4.
42
+
43
+ ### Features
44
+
45
+ * answer Result&lt;_, Refusal&gt;, refuse unadmitted heads in select, mirror the core positionally in Ruby ([5e73ef6](https://github.com/seuros/fair_machines/commit/5e73ef67f86a0326709e27eca46d8f97bccd8aba))
46
+
3
47
  ## [0.3.0](https://github.com/seuros/fair_machines/compare/fair-machines-v0.2.2...fair-machines-v0.3.0) (2026-11-07)
4
48
 
5
49
 
@@ -19,3 +19,64 @@ its budget.
19
19
 
20
20
  Tenant hierarchies, per-flow WFQ, runtime preemption, and strict latency/starvation
21
21
  bounds are not implemented.
22
+
23
+ ## Contract
24
+
25
+ - **Answers.** Every operation that can refuse returns `Result<T, Refusal>`,
26
+ and `T` describes only honoured outcomes.
27
+
28
+ | Call | Honoured | Refused |
29
+ | --- | --- | --- |
30
+ | `TenantFair::admit(tenant, cost)` | `()` | `UnknownTenant`, `Insufficient` |
31
+ | `TenantFair::cancel(tenant, cost)` | `()` | `UnknownTenant`, `ExceedsInFlight` |
32
+ | `TenantFair::select(heads)` | `Some(tenant)`, or `None` exactly when every head is `None` | `ExceedsInFlight` |
33
+ | `KeyedFair::admit(hash, cost)` | the `Lane` charged | `Insufficient` |
34
+ | `KeyedFair::release(lane, cost)` | `()` | `UnknownLane`, `ExceedsInFlight` |
35
+ | `in_flight`, `available` | `Some(cost)`, `None` for a tenant or lane the instance does not have | queries, never refuse |
36
+ | `KeyedFair::lane(hash)`, `lane_at(index)`, `Lane::new(index)` | a `Lane`; `lane_at` is `None` past the last lane | pure functions |
37
+
38
+ - **Refusals change nothing.** Every `Err` leaves the value equal to a clone
39
+ taken before the call: no budget, no DRR credit, no cursor.
40
+ - **`Refusal`.** `UnknownTenant`: the index is `N` or more. `UnknownLane`: the
41
+ lane was built for a `KeyedFair` with more lanes. `Insufficient`: the
42
+ admission asks for more cost than the budget has available; there is no
43
+ partial admission. `ExceedsInFlight`: more cost is being returned than the
44
+ budget has admitted; there is no partial return.
45
+ - **`select` and an unadmitted head.** `select` is a drain: `Ok(None)` means
46
+ every head was `None`, and nothing else. A head that costs more than its
47
+ tenant has admitted is not "nothing to dispatch": selecting it would return
48
+ cost that was never admitted, the same fault as an over-sized `cancel`. It
49
+ is refused as `ExceedsInFlight` and the whole call changes nothing, rather
50
+ than treating that tenant as empty, which would silently drop its saved
51
+ credit and hide the caller's accounting error. An honoured `select` records
52
+ what the round observed, as DRR does: a tenant presented as `None` loses the
53
+ credit it had saved.
54
+ - **Repeats cannot be honoured as repeats.** Budgets count cost, not jobs, so
55
+ the core cannot tell a repeated `cancel` or `release` from a second job of
56
+ the same cost. Either is honoured while that much cost is in flight and
57
+ refused as `ExceedsInFlight` once it is not. Return every admitted cost
58
+ exactly once.
59
+ - **`Lane` is not an issued id.** It is the bucket a hash maps to, a pure
60
+ function of the hash and `LANES`. Nothing is counted or issued: `admit`
61
+ answers it only to save the caller a second hash, `lane`, `lane_at` and
62
+ `Lane::new` build one without admitting anything, and the same hash names the same lane
63
+ in every instance with as many lanes. That aliasing is the design, so a lane
64
+ carries no scope, proves no admission, and there is no sequence to resume. A
65
+ lane built for more lanes than an instance has is `UnknownLane`.
66
+ - **No issued ids, no restarts to manage.** Neither type hands out a handle.
67
+ A rebuilt instance starts with empty budgets; cost admitted before the
68
+ restart is the caller's to re-admit or forget.
69
+ - **No clock.** Nothing here takes time, so no answer records one.
70
+ - **No panics.** The one `assert!` is evaluated at compile time:
71
+ `KeyedFair<0>` does not build, so no runtime path can meet a lane-less
72
+ instance. There is no `debug_assert!` arm: `select` settles every head
73
+ against its tenant's budget before the scheduler runs (an unadmitted head
74
+ refuses the whole call there), and presents each head to the DRR with
75
+ whether it drains its tenant, so the DRR deactivates a drained tenant
76
+ inside the selection and nothing after its answer can be refused. `cancel`
77
+ checks the tenant against the budgets; the scheduler's unknown-lane refusal
78
+ for the same index is carried as `UnknownTenant`, and both commit last.
79
+ - **Sibling seams.** The `flow-machines` credit windows and the
80
+ `priority-machines` DRR are private: no sibling type appears in this API,
81
+ so none is re-exported. Their refusals are mapped onto `Refusal` variant by
82
+ variant.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FairMachines
4
- VERSION = '0.1.5'
4
+ VERSION = '0.6.1'
5
5
  end
data/lib/fair_machines.rb CHANGED
@@ -1,4 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'fair_machines/version'
4
+
5
+ module FairMachines
6
+ # The core's `Lane`: the bucket a hash maps to, at position `index`.
7
+ # A bucket position, not an issued id: `KeyedFair.lane`, `KeyedFair.lane_at`
8
+ # and `Lane.new` build one without admitting anything, and holding one
9
+ # proves nothing. Like `Lane::new`, it holds only a position: an Integer a
10
+ # `usize` holds, TypeError for anything else, RangeError outside the range.
11
+ Lane = Data.define(:index) do
12
+ def initialize(index:)
13
+ super(index: FairMachines.__send__(:__lane, index))
14
+ end
15
+ end
16
+ end
17
+
18
+ # Native is required: there is no pure-Ruby fallback. It validates and builds
19
+ # Lane values, so the Data class above must exist first.
4
20
  require 'fair_machines_native/fair_machines_native'
21
+
22
+ module FairMachines
23
+ private_class_method :__lane
24
+
25
+ # Lane is final. `initialize` is where it validates, and a subclass could
26
+ # override it, or `allocate` build an instance that never ran it:
27
+ # subclassing raises TypeError and `allocate` is gone. This stops accidents,
28
+ # not reflection, so the binding also checks every Lane it reads.
29
+ Lane.singleton_class.undef_method(:allocate)
30
+ Lane.define_singleton_method(:inherited) { |_| raise TypeError, "#{Lane} cannot be subclassed" }
31
+
32
+ # The schedulers wrap native state and have no allocator: a subclass's
33
+ # `new` would build the base class anyway, so subclassing raises too.
34
+ [TenantFair, KeyedFair].each do |scheduler|
35
+ scheduler.define_singleton_method(:inherited) { |_| raise TypeError, "#{scheduler} cannot be subclassed" }
36
+ end
37
+ end
@@ -1,18 +1,119 @@
1
+ # Capacities, quanta and costs are Integers in 1..2**32-1: TypeError for
2
+ # anything else, RangeError outside the range, zero included. Hashes are
3
+ # Integers in 0..2**64-1; tenant and lane positions and lane counts are
4
+ # Integers a `usize` holds (0..2**64-1 on a 64-bit platform, 0..2**32-1 on a
5
+ # 32-bit one): TypeError for anything else, RangeError outside the range.
6
+ # Every message names the offending argument. Arguments are positional, in
7
+ # the core's order. Nothing here takes time, so no answer records a clock. A
8
+ # frozen object raises FrozenError on every mutating call. Refusals are
9
+ # symbols, one per core `Refusal` variant; they never raise, and a refused
10
+ # call changes nothing.
1
11
  module FairMachines
2
12
  VERSION: String
13
+
14
+ # The core's `Refusal`.
15
+ # :unknown_tenant, the tenant index is not one of the scheduler's tenants.
16
+ # :unknown_lane, the lane is not one of this instance's lanes.
17
+ # :insufficient, more cost asked for than the budget has available.
18
+ # :exceeds_in_flight, more cost returned than the budget has admitted.
19
+ type refusal = :unknown_tenant | :unknown_lane | :insufficient | :exceeds_in_flight
20
+
21
+ # The core's `Lane`: the bucket a hash maps to. A position, not an issued
22
+ # id: it can be built freely and proves nothing. Like the core's
23
+ # `Lane::new(index)`, it holds only a position: `index` is an Integer a
24
+ # `usize` holds, TypeError for anything else, RangeError outside the range.
25
+ # Sealed: subclassing raises TypeError and `allocate` is undefined. Every
26
+ # Lane the binding reads must be an instance of exactly this class
27
+ # (TypeError otherwise) and its index is re-checked (RangeError), so a
28
+ # value forged by reflection or Marshal never reaches the core.
29
+ class Lane < Data
30
+ attr_reader index: Integer
31
+ def self.new: (Integer index) -> Lane
32
+ | (index: Integer) -> Lane
33
+ end
34
+
35
+ # The core's `TenantFair<N>`; `N` is the length of the arrays.
36
+ # Sealed: subclassing raises TypeError, and there is no allocator.
3
37
  class TenantFair
4
- def self.new: (capacities: Array[Integer], quanta: Array[Integer]) -> instance
5
- def admit: (tenant: Integer, cost: Integer) -> bool
6
- def cancel: (tenant: Integer, cost: Integer) -> bool
7
- def select: (Array[Integer?] heads) -> Integer?
38
+ # The largest `N` compiled into this binding: `TenantFair<1>` to
39
+ # `TenantFair<16>`. The core takes any `N`; it has no ceiling of its own.
40
+ MAX_TENANTS: Integer
41
+
42
+ # The core's `TenantFair::new(capacities, quanta)`. `N` is the arrays'
43
+ # length: raises RangeError unless both have the same length, in
44
+ # 1..MAX_TENANTS, and TypeError unless both are Arrays.
45
+ def self.new: (Array[Integer] capacities, Array[Integer] quanta) -> TenantFair
46
+
47
+ # Honoured: :admitted. Refused: :unknown_tenant, :insufficient.
48
+ def admit: (Integer tenant, Integer cost) -> (:admitted | :unknown_tenant | :insufficient)
49
+
50
+ # Honoured: :cancelled. Refused: :unknown_tenant, :exceeds_in_flight.
51
+ # A repeat cannot be recognised: it is honoured while that much cost is
52
+ # still admitted and refused once it is not.
53
+ def cancel: (Integer tenant, Integer cost) -> (:cancelled | :unknown_tenant | :exceeds_in_flight)
54
+
55
+ # `heads` has one entry per tenant: the cost at the head of its queue,
56
+ # nil when it has nothing waiting. Honoured: the tenant to dispatch, or
57
+ # nil exactly when every head is nil. Refused: :exceeds_in_flight, some
58
+ # head costs more than its tenant has admitted. Raises RangeError
59
+ # unless `heads` has tenant_count entries.
60
+ def select: (Array[Integer?] heads) -> (Integer | nil | :exceeds_in_flight)
61
+
8
62
  def tenant_count: () -> Integer
63
+
64
+ # Cost admitted and not yet dispatched or cancelled; nil for an index
65
+ # that is not a tenant. A query.
66
+ def in_flight: (Integer tenant) -> Integer?
67
+
68
+ # Cost the tenant may still admit; nil for an index that is not a tenant.
69
+ def available: (Integer tenant) -> Integer?
9
70
  end
71
+
72
+ # The core's `KeyedFair<LANES>`. `LANES` is a const generic in the core;
73
+ # here it is the first argument wherever the core names the type.
74
+ # Sealed like TenantFair.
10
75
  class KeyedFair
11
- def self.new: (lanes: Integer, capacity: Integer) -> instance
12
- def admit: (hash: Integer, cost: Integer) -> Integer?
13
- def release: (lane: Integer, cost: Integer) -> bool
14
- def in_flight: (Integer lane) -> Integer
15
- def lane: (Integer hash) -> Integer
76
+ # The largest `LANES` compiled into this binding: `KeyedFair<1>` to
77
+ # `KeyedFair<256>`. The core takes any `LANES > 0`; it has no ceiling of
78
+ # its own.
79
+ MAX_LANES: Integer
80
+
81
+ # The core's `KeyedFair::<LANES>::new(capacity)`. Raises RangeError
82
+ # unless `lanes` is in 1..MAX_LANES.
83
+ def self.new: (Integer lanes, Integer capacity) -> KeyedFair
84
+
85
+ # The core's associated `KeyedFair::<LANES>::lane(hash)`: the lane a hash
86
+ # maps to. A pure function. Raises RangeError unless `lanes` is in
87
+ # 1..MAX_LANES.
88
+ def self.lane: (Integer lanes, Integer hash) -> Lane
89
+
90
+ # The core's associated `KeyedFair::<LANES>::lane_at(index)`: nil for an
91
+ # index of `lanes` or more. Raises RangeError unless `lanes` is in
92
+ # 1..MAX_LANES.
93
+ def self.lane_at: (Integer lanes, Integer index) -> Lane?
94
+
95
+ # Honoured: the Lane that was charged. Refused: :insufficient. The Lane
96
+ # is built through `Lane.new` before the admission is kept: if that
97
+ # raises, freezes this KeyedFair (FrozenError) or changes it
98
+ # (RuntimeError), nothing is admitted.
99
+ def admit: (Integer hash, Integer cost) -> (Lane | :insufficient)
100
+
101
+ # Honoured: :released. Refused: :unknown_lane, :exceeds_in_flight. A
102
+ # repeat cannot be recognised: it is honoured while that much cost is
103
+ # still in flight and refused once it is not. Raises TypeError unless
104
+ # given a Lane.
105
+ def release: (Lane lane, Integer cost) -> (:released | :unknown_lane | :exceeds_in_flight)
106
+
16
107
  def lane_count: () -> Integer
108
+
109
+ # Cost admitted to the lane and not yet released; nil for a lane this
110
+ # instance does not have. Raises TypeError unless given a Lane.
111
+ def in_flight: (Lane lane) -> Integer?
112
+
113
+ # Cost the lane may still admit; nil for a lane this instance does not have.
114
+ def available: (Lane lane) -> Integer?
17
115
  end
116
+
117
+ # Private native hook `Lane#initialize` validates its index through.
118
+ private def self.__lane: (Integer index) -> Integer
18
119
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fair_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.6.1
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-07 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Initial unstable Ruby adapter to the no_std fair-machines Rust core.
14
- Local source builds require unpublished path-only flow and priority siblings.
13
+ description: 'Ruby adapter to the no_std fair-machines Rust core: per-tenant cost
14
+ budgets with deficit round robin dispatch, and hashed lanes for an open tenant set.'
15
15
  email:
16
16
  - oss@seuros.com
17
17
  executables: []