async-bulkhead-llm 3.17.1 → 3.18.0
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.
- package/CHANGELOG.md +128 -0
- package/README.md +46 -0
- package/dist/cjs/bulkhead.cjs +27 -5
- package/dist/cjs/bulkhead.cjs.map +1 -1
- package/dist/cjs/engine/admission-counts.cjs +19 -0
- package/dist/cjs/engine/admission-counts.cjs.map +1 -1
- package/dist/cjs/engine/admitted-run.cjs +61 -18
- package/dist/cjs/engine/admitted-run.cjs.map +1 -1
- package/dist/cjs/engine/admitted-token.cjs +94 -3
- package/dist/cjs/engine/admitted-token.cjs.map +1 -1
- package/dist/cjs/engine/events.cjs +1 -0
- package/dist/cjs/engine/events.cjs.map +1 -1
- package/dist/cjs/engine/limit-fit.cjs +108 -0
- package/dist/cjs/engine/limit-fit.cjs.map +1 -0
- package/dist/cjs/engine/limits.cjs +22 -1
- package/dist/cjs/engine/limits.cjs.map +1 -1
- package/dist/cjs/engine/run.cjs +1 -1
- package/dist/cjs/engine/run.cjs.map +1 -1
- package/dist/cjs/engine/running-calls.cjs +79 -0
- package/dist/cjs/engine/running-calls.cjs.map +1 -0
- package/dist/cjs/engine/shared.cjs +7 -1
- package/dist/cjs/engine/shared.cjs.map +1 -1
- package/dist/cjs/engine/shutdown.cjs +20 -2
- package/dist/cjs/engine/shutdown.cjs.map +1 -1
- package/dist/cjs/engine/stats.cjs +2 -0
- package/dist/cjs/engine/stats.cjs.map +1 -1
- package/dist/cjs/engine/stop-policy.cjs +40 -0
- package/dist/cjs/engine/stop-policy.cjs.map +1 -0
- package/dist/cjs/engine/stop.cjs +91 -0
- package/dist/cjs/engine/stop.cjs.map +1 -0
- package/dist/cjs/engine/usage-report.cjs +1 -0
- package/dist/cjs/engine/usage-report.cjs.map +1 -1
- package/dist/cjs/errors.cjs +25 -1
- package/dist/cjs/errors.cjs.map +1 -1
- package/dist/cjs/index.cjs +7 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/profiles 2.cjs +16 -0
- package/dist/cjs/types 2.cjs +3 -0
- package/dist/cjs/types.cjs 2.map +1 -0
- package/dist/cjs/validation.cjs 2.map +1 -0
- package/dist/esm/bulkhead.js +27 -5
- package/dist/esm/bulkhead.js.map +1 -1
- package/dist/esm/engine/admission-counts.js +19 -0
- package/dist/esm/engine/admission-counts.js.map +1 -1
- package/dist/esm/engine/admitted-run.js +62 -19
- package/dist/esm/engine/admitted-run.js.map +1 -1
- package/dist/esm/engine/admitted-token.js +95 -4
- package/dist/esm/engine/admitted-token.js.map +1 -1
- package/dist/esm/engine/events.js +1 -0
- package/dist/esm/engine/events.js.map +1 -1
- package/dist/esm/engine/limit-fit.js +105 -0
- package/dist/esm/engine/limit-fit.js.map +1 -0
- package/dist/esm/engine/limits.js +22 -1
- package/dist/esm/engine/limits.js.map +1 -1
- package/dist/esm/engine/run.js +1 -1
- package/dist/esm/engine/run.js.map +1 -1
- package/dist/esm/engine/running-calls.js +76 -0
- package/dist/esm/engine/running-calls.js.map +1 -0
- package/dist/esm/engine/shared.js +6 -0
- package/dist/esm/engine/shared.js.map +1 -1
- package/dist/esm/engine/shutdown.js +20 -2
- package/dist/esm/engine/shutdown.js.map +1 -1
- package/dist/esm/engine/stats.js +2 -0
- package/dist/esm/engine/stats.js.map +1 -1
- package/dist/esm/engine/stop-policy.js +37 -0
- package/dist/esm/engine/stop-policy.js.map +1 -0
- package/dist/esm/engine/stop.js +88 -0
- package/dist/esm/engine/stop.js.map +1 -0
- package/dist/esm/engine/usage-report.js +1 -0
- package/dist/esm/engine/usage-report.js.map +1 -1
- package/dist/esm/errors.js +23 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/types/bulkhead.d.ts +9 -4
- package/dist/types/bulkhead.d.ts.map +1 -1
- package/dist/types/engine/admission-counts.d.ts +7 -3
- package/dist/types/engine/admission-counts.d.ts.map +1 -1
- package/dist/types/engine/admitted-run.d.ts +10 -4
- package/dist/types/engine/admitted-run.d.ts.map +1 -1
- package/dist/types/engine/admitted-token.d.ts +12 -5
- package/dist/types/engine/admitted-token.d.ts.map +1 -1
- package/dist/types/engine/events.d.ts.map +1 -1
- package/dist/types/engine/limit-fit.d.ts +30 -0
- package/dist/types/engine/limit-fit.d.ts.map +1 -0
- package/dist/types/engine/limits.d.ts +5 -3
- package/dist/types/engine/limits.d.ts.map +1 -1
- package/dist/types/engine/run.d.ts.map +1 -1
- package/dist/types/engine/running-calls.d.ts +55 -0
- package/dist/types/engine/running-calls.d.ts.map +1 -0
- package/dist/types/engine/shared.d.ts +13 -0
- package/dist/types/engine/shared.d.ts.map +1 -1
- package/dist/types/engine/shutdown.d.ts +6 -3
- package/dist/types/engine/shutdown.d.ts.map +1 -1
- package/dist/types/engine/stats.d.ts.map +1 -1
- package/dist/types/engine/stop-policy.d.ts +15 -0
- package/dist/types/engine/stop-policy.d.ts.map +1 -0
- package/dist/types/engine/stop.d.ts +44 -0
- package/dist/types/engine/stop.d.ts.map +1 -0
- package/dist/types/engine/usage-report.d.ts +2 -0
- package/dist/types/engine/usage-report.d.ts.map +1 -1
- package/dist/types/errors.d.ts +21 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +103 -2
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,134 @@ and adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [3.18.0] - 2026-11-23
|
|
11
|
+
|
|
12
|
+
Adds an opt-in way to stop work the bulkhead already admitted. Nothing is
|
|
13
|
+
stopped unless a limits snapshot carries a `stop` policy or a drain passes
|
|
14
|
+
`stopOnTimeout`; without them this release behaves as 3.17.1.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
* **`LLMAdmissionStoppedError` and one meaning of "stop".** Whatever the
|
|
19
|
+
trigger, stopping a call aborts the signal passed to its `run()` callback,
|
|
20
|
+
rejects the caller with `LLMAdmissionStoppedError` (`admissionId`, `cause`,
|
|
21
|
+
`resources`, `admissionClass`), and returns the concurrency slot at once.
|
|
22
|
+
The token hold stays charged until the callback settles, because a local
|
|
23
|
+
abort does not prove the provider stopped work; the borrowed-slot deadline
|
|
24
|
+
already followed this rule. `cause` is `"overrun"`, `"drain_deadline"`, or
|
|
25
|
+
`"limits"`.
|
|
26
|
+
|
|
27
|
+
* **Stop policy in the limits snapshot.** `LLMAdmissionLimits` gains optional
|
|
28
|
+
`stop: { overrunAllowanceTokens?, takeBackGraceMs? }`. It is validated with
|
|
29
|
+
the rest of the snapshot and returned by `limits()`, `stats().limits`, and
|
|
30
|
+
the `reconfigure` event while it is applied. Like every other limit it is
|
|
31
|
+
not inherited: a snapshot without `stop` has no policy. `setBudget()`
|
|
32
|
+
carries the applied policy into its new revision.
|
|
33
|
+
|
|
34
|
+
* **Overrun trigger.** `stop.overrunAllowanceTokens` lets a call's hold grow
|
|
35
|
+
that many tokens above its reservation; one more token stops it with cause
|
|
36
|
+
`"overrun"`. With the allowance set, a usage report that raises a hold and
|
|
37
|
+
leaves a class above `maxInFlightTokens`, or the pool above its budget,
|
|
38
|
+
also stops calls until the holds of the calls still running fit. A class
|
|
39
|
+
above its own ceiling gives up only its own calls. If a snapshot had
|
|
40
|
+
already lowered a ceiling below what is running, a report undoes only its
|
|
41
|
+
own growth. Requires a token budget.
|
|
42
|
+
|
|
43
|
+
* **Drain trigger.** `drain({ timeoutMs, stopOnTimeout: true })` stops every
|
|
44
|
+
call still running at the deadline with cause `"drain_deadline"`. Its
|
|
45
|
+
result gains `stopped`, the number of calls it stopped. Stopped calls stay
|
|
46
|
+
in `inFlight` until their callbacks settle.
|
|
47
|
+
|
|
48
|
+
* **Take-back trigger.** `stop.takeBackGraceMs` bounds how long running work
|
|
49
|
+
may stay above the limits of a new snapshot: a lower `maxConcurrent` or
|
|
50
|
+
token budget, lower class ceilings, or a restored class floor. Nothing is
|
|
51
|
+
stopped during the grace period and calls that finish inside it are left
|
|
52
|
+
alone; then enough calls are stopped to fit, with cause `"limits"`. Any
|
|
53
|
+
later applied snapshot replaces a take-back that is still waiting and, if
|
|
54
|
+
it still leaves work above the limits, starts its own grace period.
|
|
55
|
+
|
|
56
|
+
* **A fixed stop order.** Whenever the engine picks, calls admitted on
|
|
57
|
+
borrowed capacity go first, then normal priority before high, and on a tie
|
|
58
|
+
the call admitted last. A stopped call is never counted or picked again.
|
|
59
|
+
Deduplication followers receive their leader's error and are never picked;
|
|
60
|
+
observe-mode bypasses and queue waiters are never stopped.
|
|
61
|
+
|
|
62
|
+
* **`stop` event and counters.** A `stop` event fires once per stopped call
|
|
63
|
+
with `cause`, `resources`, and `heldTokens`. `stats().llm` gains `stopped`
|
|
64
|
+
and `stoppedByCause`, and each admission class gains `stopped`. All three
|
|
65
|
+
are absent until the first stop.
|
|
66
|
+
|
|
67
|
+
* **`stopped: true` on usage reports.** An `acquire()` token has no signal.
|
|
68
|
+
It learns of a stop from the event and from `stopped: true` on its usage
|
|
69
|
+
reports, starting with the report that caused the stop. Its tokens stay
|
|
70
|
+
charged until `release()`.
|
|
71
|
+
|
|
72
|
+
* **Tests.** Five new files cover each trigger, the stop order, what is never
|
|
73
|
+
stopped, and the default of never stopping: `test/stop_overrun.test.ts`,
|
|
74
|
+
`test/stop_drain.test.ts`, `test/stop_take_back.test.ts`,
|
|
75
|
+
`test/stop_order.test.ts`, and `test/stop_default.test.ts`.
|
|
76
|
+
|
|
77
|
+
* **Guide.** [Stopping admitted work](guides/stopping-admitted-work.md), with
|
|
78
|
+
matching sections in the README and the runtime-limits, streaming,
|
|
79
|
+
admission-classes, gateway-integration, telemetry, concepts, and migration
|
|
80
|
+
guides.
|
|
81
|
+
|
|
82
|
+
### Contract
|
|
83
|
+
|
|
84
|
+
* A stop is a local decision. It returns the local slot and asks the callback
|
|
85
|
+
to end. It does not prove that a provider account, model queue, or
|
|
86
|
+
accelerator stopped work, and a callback that ignores its signal keeps its
|
|
87
|
+
tokens charged for as long as it runs.
|
|
88
|
+
|
|
89
|
+
* `run()` gives the callback a signal the engine can abort only when a stop
|
|
90
|
+
policy was applied at the moment the call was admitted (`stop: {}` is
|
|
91
|
+
enough). A call admitted without a policy can still be stopped later, by a
|
|
92
|
+
drain or by a policy that arrives afterward: its caller is rejected and its
|
|
93
|
+
slot returns, but its callback is not aborted.
|
|
94
|
+
|
|
95
|
+
* The grace period of a take-back starts again with every newer snapshot that
|
|
96
|
+
still leaves work above the limits. Revisions that arrive faster than the
|
|
97
|
+
grace period keep postponing it.
|
|
98
|
+
|
|
99
|
+
### Internal
|
|
100
|
+
|
|
101
|
+
* Four new engine modules. `src/engine/running-calls.ts` owns the set of
|
|
102
|
+
admitted calls still running and the stop order; the set is a linked
|
|
103
|
+
list threaded through the calls, so registering one costs a few pointer
|
|
104
|
+
writes. `src/engine/stop.ts`
|
|
105
|
+
holds the three triggers and the timer of a waiting take-back.
|
|
106
|
+
`src/engine/limit-fit.ts` answers whether running work fits the applied
|
|
107
|
+
limits and which call to stop next. `src/engine/stop-policy.ts` validates
|
|
108
|
+
the `stop` part of a snapshot. The admitted token registers its call at
|
|
109
|
+
admission and removes it at stop or final release, and the stop policy
|
|
110
|
+
itself lives with the other limits in `limits.ts`.
|
|
111
|
+
|
|
112
|
+
* The promise `run()` returns for an admitted call is now built by hand
|
|
113
|
+
instead of by an `async` function, so that a stop can reject it early. It
|
|
114
|
+
settles on the same microtask as before.
|
|
115
|
+
|
|
116
|
+
* Every admission now registers its call as running. The median
|
|
117
|
+
`decisionDurationNs` measured on `admit` events stayed within one clock
|
|
118
|
+
tick (42 ns) of 3.17.1.
|
|
119
|
+
|
|
120
|
+
### Compatibility
|
|
121
|
+
|
|
122
|
+
* Existing exports, methods, and event names are unchanged, and every new
|
|
123
|
+
field is optional. The 13 existing test files pass unedited.
|
|
124
|
+
* Without a stop policy, a `run()` callback still receives exactly the signal
|
|
125
|
+
its caller passed: the same object, or `undefined`. Under a policy it
|
|
126
|
+
receives an engine-owned signal that the caller's abort is forwarded to.
|
|
127
|
+
* Behavior without a stop policy was checked against 3.17.1 by driving both
|
|
128
|
+
builds with the same 1,000 seeded random scenarios, covering classes,
|
|
129
|
+
token budgets, queues, deduplication, observe mode, limit changes, and
|
|
130
|
+
listeners, and comparing every result, error, event, and stats snapshot,
|
|
131
|
+
and the microtask on which each `run()` settled.
|
|
132
|
+
* Code that switches exhaustively on `LLMEventType`, or maps every error
|
|
133
|
+
other than `LLMBulkheadRejectedError` to an upstream failure, should
|
|
134
|
+
account for the `stop` event and `LLMAdmissionStoppedError` before opting
|
|
135
|
+
in.
|
|
136
|
+
* The runtime dependency remains `async-bulkhead-ts@^1.0.1`.
|
|
137
|
+
|
|
10
138
|
## [3.17.1] - 2026-11-22
|
|
11
139
|
|
|
12
140
|
Internal restructuring release. No public API, runtime behavior, or
|
package/README.md
CHANGED
|
@@ -10,6 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
## The problem
|
|
14
|
+
|
|
15
|
+
LLM calls are slow and uneven. One finishes in two seconds on 500 tokens; the
|
|
16
|
+
next runs for a minute on 100,000. A service that forwards every request it
|
|
17
|
+
receives has no defense when traffic bursts: all of them reach the provider
|
|
18
|
+
at once, the provider starts answering 429 or slowing down, retries add to
|
|
19
|
+
the pile, and every caller waits a long time to fail.
|
|
20
|
+
|
|
21
|
+
Counting requests is not enough to prevent it, because the load is the work
|
|
22
|
+
in flight, and a request's size is part of that work.
|
|
23
|
+
|
|
13
24
|
## What it does
|
|
14
25
|
|
|
15
26
|
You wrap your LLM calls in a bulkhead. Before each call runs, the bulkhead
|
|
@@ -181,6 +192,32 @@ capacity that client cancellation cannot authoritatively release.
|
|
|
181
192
|
|
|
182
193
|
→ [Stats and events](guides/telemetry.md)
|
|
183
194
|
|
|
195
|
+
## Stopping admitted work
|
|
196
|
+
|
|
197
|
+
By default an admitted call is never touched: a stream that overruns its
|
|
198
|
+
reservation only widens its hold, and a lowered limit waits for running calls
|
|
199
|
+
to finish. A limits snapshot can opt in to stopping them instead:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
bulkhead.applyLimits({
|
|
203
|
+
...bulkhead.limits(),
|
|
204
|
+
revision: bulkhead.limits().revision + 1,
|
|
205
|
+
stop: {
|
|
206
|
+
overrunAllowanceTokens: 500, // a hold may grow this far past its reservation
|
|
207
|
+
takeBackGraceMs: 2_000, // then work above lowered limits is stopped
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
A stopped call has its callback signal aborted, its caller rejected with
|
|
213
|
+
`LLMAdmissionStoppedError` (`cause` is `"overrun"`, `"drain_deadline"`, or
|
|
214
|
+
`"limits"`), and its concurrency slot returned at once. Its tokens stay
|
|
215
|
+
charged until the callback settles, because a local abort does not prove the
|
|
216
|
+
provider stopped. Calls on borrowed capacity are stopped first, then normal
|
|
217
|
+
priority before high, newest first.
|
|
218
|
+
|
|
219
|
+
→ [Stopping admitted work](guides/stopping-admitted-work.md)
|
|
220
|
+
|
|
184
221
|
## Shutting down cleanly
|
|
185
222
|
|
|
186
223
|
```ts
|
|
@@ -193,6 +230,14 @@ await bulkhead.drain({ timeoutMs: 10_000 }); // wait, but not forever
|
|
|
193
230
|
it does not abandon or release that work. One stuck upstream stream therefore
|
|
194
231
|
cannot hold the shutdown decision open indefinitely.
|
|
195
232
|
|
|
233
|
+
Add `stopOnTimeout: true` to stop whatever is still running at the deadline.
|
|
234
|
+
The result then also reports `stopped`, the number of calls it stopped:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
bulkhead.close();
|
|
238
|
+
const result = await bulkhead.drain({ timeoutMs: 10_000, stopOnTimeout: true });
|
|
239
|
+
```
|
|
240
|
+
|
|
196
241
|
Without `timeoutMs`, `drain()` waits for final token settlement as well as base
|
|
197
242
|
concurrency. In particular, returning a borrowed slot with
|
|
198
243
|
`abandonBorrowedConcurrency()` does not complete the admission: a manual
|
|
@@ -211,6 +256,7 @@ settling the resource accounting for the work behind it.
|
|
|
211
256
|
| [Streaming and reconciliation](guides/streaming.md) | `reportUsage()`, progressive holds, ordered usage events |
|
|
212
257
|
| [Admission classes](guides/admission-classes.md) | Per-class floors and ceilings, shared capacity, borrowing |
|
|
213
258
|
| [Runtime limits and reconfiguration](guides/runtime-limits.md) | `applyLimits()`, revisions, fail-closed startup, kill switch |
|
|
259
|
+
| [Stopping admitted work](guides/stopping-admitted-work.md) | Opt-in stops on overrun, at a drain deadline, and after a limit change |
|
|
214
260
|
| [Observe mode](guides/observe-mode.md) | Measure a policy before you enforce it |
|
|
215
261
|
| [Deduplication](guides/deduplication.md) | In-flight dedup, tenant scoping, streaming results |
|
|
216
262
|
| [Gateway integration](guides/gateway-integration.md) | `wouldAdmit()`, admission IDs, external leases, control planes |
|
package/dist/cjs/bulkhead.cjs
CHANGED
|
@@ -17,9 +17,11 @@ const options_js_1 = require("./engine/options.cjs");
|
|
|
17
17
|
const reject_detail_js_1 = require("./engine/reject-detail.cjs");
|
|
18
18
|
const reservation_js_1 = require("./engine/reservation.cjs");
|
|
19
19
|
const run_js_1 = require("./engine/run.cjs");
|
|
20
|
+
const running_calls_js_1 = require("./engine/running-calls.cjs");
|
|
20
21
|
const shared_usage_js_1 = require("./engine/shared-usage.cjs");
|
|
21
22
|
const shutdown_js_1 = require("./engine/shutdown.cjs");
|
|
22
23
|
const stats_js_1 = require("./engine/stats.cjs");
|
|
24
|
+
const stop_js_1 = require("./engine/stop.cjs");
|
|
23
25
|
const token_ledger_js_1 = require("./engine/token-ledger.cjs");
|
|
24
26
|
const would_admit_js_1 = require("./engine/would-admit.cjs");
|
|
25
27
|
// ────────────────────────────────────────────
|
|
@@ -50,6 +52,7 @@ function createLLMBulkhead(opts) {
|
|
|
50
52
|
slots: (0, class_slots_js_1.createClassSlots)(classIds),
|
|
51
53
|
counts: (0, admission_counts_js_1.createAdmissionCounts)(classIds),
|
|
52
54
|
observeStats: (0, observe_stats_js_1.createObserveStats)(),
|
|
55
|
+
running: (0, running_calls_js_1.createRunningCalls)(),
|
|
53
56
|
};
|
|
54
57
|
const dedup = (0, dedup_flow_js_1.createDedup)({ ...owners, options: opts.deduplication });
|
|
55
58
|
// ---- Capacity decisions: they read the owners and keep no state ----
|
|
@@ -62,10 +65,17 @@ function createLLMBulkhead(opts) {
|
|
|
62
65
|
capacity,
|
|
63
66
|
buildRejectDetail,
|
|
64
67
|
});
|
|
65
|
-
// ---- Admission, execution, stats and shutdown ----
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
// ---- Admission, execution, stopping, stats and shutdown ----
|
|
69
|
+
// The stopper decides which calls to stop; the token wrapper, built
|
|
70
|
+
// just below, is what stops one.
|
|
71
|
+
const stopper = (0, stop_js_1.createStopper)({
|
|
68
72
|
...owners,
|
|
73
|
+
stop: (call, cause) => tokens.stop(call, cause),
|
|
74
|
+
});
|
|
75
|
+
const shutdown = (0, shutdown_js_1.createShutdown)(concurrency, owners.counts, stopper.stopForDrain);
|
|
76
|
+
const tokens = (0, admitted_token_js_1.createTokenWrapper)({
|
|
77
|
+
...owners,
|
|
78
|
+
holdGrew: stopper.holdGrew,
|
|
69
79
|
settleDrainWaiters: shutdown.settleDrainWaiters,
|
|
70
80
|
});
|
|
71
81
|
const admit = (0, acquire_js_1.createAcquire)({
|
|
@@ -73,7 +83,7 @@ function createLLMBulkhead(opts) {
|
|
|
73
83
|
capacity,
|
|
74
84
|
buildRejectDetail,
|
|
75
85
|
resolveAdmission,
|
|
76
|
-
wrapToken,
|
|
86
|
+
wrapToken: tokens.wrap,
|
|
77
87
|
timeoutMs: config.timeoutMs,
|
|
78
88
|
});
|
|
79
89
|
const runBypassed = (0, bypass_js_1.createBypass)({ ...owners, buildRejectDetail });
|
|
@@ -175,9 +185,19 @@ function createLLMBulkhead(opts) {
|
|
|
175
185
|
* queue, or token ceilings use shrink-by-attrition: in-flight work and
|
|
176
186
|
* already accepted waiters are not canceled. Raising concurrency pumps
|
|
177
187
|
* accepted waiters immediately after the complete snapshot is installed.
|
|
188
|
+
*
|
|
189
|
+
* v3.18: a snapshot may carry an opt-in `stop` policy. With
|
|
190
|
+
* `stop.takeBackGraceMs`, running work the snapshot leaves above the new
|
|
191
|
+
* limits is stopped once the grace period ends, instead of being waited
|
|
192
|
+
* out. Accepted waiters are still never canceled. A snapshot without
|
|
193
|
+
* `stop` has no policy, whatever the previous revision said, and any
|
|
194
|
+
* applied snapshot replaces a take-back that is still waiting.
|
|
178
195
|
*/
|
|
179
196
|
function applyLimits(next) {
|
|
180
|
-
|
|
197
|
+
const result = admissionLimits.apply(next);
|
|
198
|
+
if (result.applied)
|
|
199
|
+
stopper.limitsApplied();
|
|
200
|
+
return result;
|
|
181
201
|
}
|
|
182
202
|
/**
|
|
183
203
|
* Backward-compatible budget-only setter.
|
|
@@ -185,9 +205,11 @@ function createLLMBulkhead(opts) {
|
|
|
185
205
|
* This is implemented as a complete local reconfiguration at
|
|
186
206
|
* `currentRevision + 1`. Externally managed deployments should use
|
|
187
207
|
* `applyLimits()` exclusively so one authority owns the revision stream.
|
|
208
|
+
* The applied stop policy, if any, is carried into the new revision.
|
|
188
209
|
*/
|
|
189
210
|
function setBudget(tokens) {
|
|
190
211
|
admissionLimits.setBudget(tokens);
|
|
212
|
+
stopper.limitsApplied();
|
|
191
213
|
}
|
|
192
214
|
/**
|
|
193
215
|
* Stop admission permanently. All pending waiters in the underlying
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkhead.cjs","sourceRoot":"","sources":["../../src/bulkhead.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"bulkhead.cjs","sourceRoot":"","sources":["../../src/bulkhead.ts"],"names":[],"mappings":";;AAqFA,8CA+SC;AA5UD,6EAA4E;AAC5E,oDAAoD;AACpD,sEAAqE;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,IAAwB;QAC3C,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,CAAC,aAAa,EAAE,CAAC;QAC5C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,SAAS,CAAC,MAAc;QAC/B,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,CAAC,aAAa,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,SAAS,KAAK;QACZ,QAAQ,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IA0CD,SAAS,KAAK,CAAC,IAGd;QACC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,SAAS,EAAE,CACT,KAAQ,EACR,QAAqB;QAErB,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,QAAQ;QACR,OAAO;QACP,GAAG;QACH,UAAU;QACV,KAAK;QACL,MAAM;QACN,WAAW;QACX,SAAS;QACT,KAAK;QACL,KAAK;QACL,EAAE;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -8,6 +8,8 @@ function createAdmissionCounts(classIds) {
|
|
|
8
8
|
const llmBorrowedConcurrencyAbandonedByCause = {};
|
|
9
9
|
let llmRejected = 0;
|
|
10
10
|
const llmRejectedByReason = {};
|
|
11
|
+
let llmStopped = 0;
|
|
12
|
+
const llmStoppedByCause = {};
|
|
11
13
|
const perClass = new Map();
|
|
12
14
|
for (const id of classIds) {
|
|
13
15
|
perClass.set(id, {
|
|
@@ -16,6 +18,7 @@ function createAdmissionCounts(classIds) {
|
|
|
16
18
|
borrowedConcurrencyAbandoned: 0,
|
|
17
19
|
rejected: 0,
|
|
18
20
|
rejectedByReason: {},
|
|
21
|
+
stopped: 0,
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
24
|
function countsOf(classId) {
|
|
@@ -56,6 +59,14 @@ function createAdmissionCounts(classIds) {
|
|
|
56
59
|
if (cls !== undefined)
|
|
57
60
|
cls.borrowedConcurrencyAbandoned++;
|
|
58
61
|
}
|
|
62
|
+
/** The engine stopped an admitted call. */
|
|
63
|
+
function noteStop(classId, cause) {
|
|
64
|
+
const cls = countsOf(classId);
|
|
65
|
+
llmStopped++;
|
|
66
|
+
llmStoppedByCause[cause] = (llmStoppedByCause[cause] ?? 0) + 1;
|
|
67
|
+
if (cls !== undefined)
|
|
68
|
+
cls.stopped++;
|
|
69
|
+
}
|
|
59
70
|
/** Admitted calls that have not reached final settlement. */
|
|
60
71
|
function unsettled() {
|
|
61
72
|
return Math.max(0, llmAdmitted - llmReleased);
|
|
@@ -72,6 +83,11 @@ function createAdmissionCounts(classIds) {
|
|
|
72
83
|
},
|
|
73
84
|
rejected: llmRejected,
|
|
74
85
|
rejectedByReason: { ...llmRejectedByReason },
|
|
86
|
+
// Absent until the first stop: a bulkhead that never stops anything
|
|
87
|
+
// keeps reporting the shape it always had.
|
|
88
|
+
...(llmStopped > 0
|
|
89
|
+
? { stopped: llmStopped, stoppedByCause: { ...llmStoppedByCause } }
|
|
90
|
+
: {}),
|
|
75
91
|
};
|
|
76
92
|
}
|
|
77
93
|
/** Detached copy of one class's counts. */
|
|
@@ -84,6 +100,9 @@ function createAdmissionCounts(classIds) {
|
|
|
84
100
|
noteRelease,
|
|
85
101
|
noteReject,
|
|
86
102
|
noteAbandon,
|
|
103
|
+
noteStop,
|
|
104
|
+
/** Has any call been stopped yet? */
|
|
105
|
+
anyStopped: () => llmStopped > 0,
|
|
87
106
|
unsettled,
|
|
88
107
|
totals,
|
|
89
108
|
classTotals,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admission-counts.cjs","sourceRoot":"","sources":["../../../src/engine/admission-counts.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"adm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C7D,SAAS,SAAS;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC;IAChD,CAAC;IAED,6EAA6E;IAC7E,SAAS,MAAM;QACb,OAAO;YACL,QAAQ,EAAE,SAAS,EAAE;YACrB,QAAQ,EAAE,WAAW;YACrB,QAAQ,EAAE,WAAW;YACrB,4BAA4B,EAAE,+BAA+B;YAC7D,mCAAmC,EAAE;gBACnC,GAAG,sCAAsC;aAC1C;YACD,QAAQ,EAAE,WAAW;YACrB,gBAAgB,EAAE,EAAE,GAAG,mBAAmB,EAAE;YAC5C,oEAAoE;YACpE,2CAA2C;YAC3C,GAAG,CAAC,UAAU,GAAG,CAAC;gBAChB,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,GAAG,iBAAiB,EAAE,EAAE;gBACnE,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC;IAED,2CAA2C;IAC3C,SAAS,WAAW,CAAC,OAAe;QAClC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;QACnC,OAAO,EAAE,GAAG,GAAG,EAAE,gBAAgB,EAAE,EAAE,GAAG,GAAG,CAAC,gBAAgB,EAAE,EAAE,CAAC;IACnE,CAAC;IAED,OAAO;QACL,SAAS;QACT,WAAW;QACX,UAAU;QACV,WAAW;QACX,QAAQ;QACR,qCAAqC;QACrC,UAAU,EAAE,GAAY,EAAE,CAAC,UAAU,GAAG,CAAC;QACzC,SAAS;QACT,MAAM;QACN,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -37,8 +37,13 @@ function withBorrowedDeadline(work, r, deadlineMs, callbackAbort, cleanup) {
|
|
|
37
37
|
* Start the callback of an admitted call and return the promise the
|
|
38
38
|
* caller should see. Not `async` on purpose: the callback starts
|
|
39
39
|
* synchronously, exactly where `run()` asks for it.
|
|
40
|
+
*
|
|
41
|
+
* `stoppable` is true when a stop policy was active at admission. Only
|
|
42
|
+
* then, or under a borrowed-slot deadline, does the callback get a signal
|
|
43
|
+
* the engine can abort. Otherwise it gets exactly what the caller passed,
|
|
44
|
+
* the same object or nothing, and a stop can only reject the caller.
|
|
40
45
|
*/
|
|
41
|
-
function runAdmitted(r, fn, ao, getUsage, borrowedConcurrencyDeadlineMs) {
|
|
46
|
+
function runAdmitted(r, fn, ao, getUsage, borrowedConcurrencyDeadlineMs, stoppable) {
|
|
42
47
|
const ctx = {
|
|
43
48
|
admissionId: r.admissionId,
|
|
44
49
|
limitRevision: r.limitRevision,
|
|
@@ -56,7 +61,7 @@ function runAdmitted(r, fn, ao, getUsage, borrowedConcurrencyDeadlineMs) {
|
|
|
56
61
|
r.resources.borrowedConcurrency
|
|
57
62
|
? borrowedConcurrencyDeadlineMs
|
|
58
63
|
: undefined;
|
|
59
|
-
const callbackAbort = deadlineMs !== undefined ? new AbortController() : undefined;
|
|
64
|
+
const callbackAbort = deadlineMs !== undefined || stoppable ? new AbortController() : undefined;
|
|
60
65
|
const sourceSignal = ao.signal;
|
|
61
66
|
let removeSourceAbortListener;
|
|
62
67
|
if (callbackAbort !== undefined && sourceSignal !== undefined) {
|
|
@@ -69,30 +74,68 @@ function runAdmitted(r, fn, ao, getUsage, borrowedConcurrencyDeadlineMs) {
|
|
|
69
74
|
removeSourceAbortListener = () => sourceSignal.removeEventListener("abort", forwardAbort);
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
// `work` settles on the same microtask as an `async` function around
|
|
78
|
+
// the callback would. It is built by hand so that a stop can reject it
|
|
79
|
+
// early; the callback's own settlement still releases the token later.
|
|
80
|
+
const work = new Promise((resolve, reject) => {
|
|
81
|
+
const stoppedBeforeStart = r.token[shared_js_1.ON_STOP]((error) => {
|
|
82
|
+
callbackAbort?.abort(error);
|
|
83
|
+
reject(error);
|
|
84
|
+
});
|
|
85
|
+
if (stoppedBeforeStart !== undefined) {
|
|
86
|
+
// Stopped between admission and this point: nothing was started,
|
|
87
|
+
// so nothing is left to hold tokens for.
|
|
88
|
+
removeSourceAbortListener?.();
|
|
89
|
+
r.token.release();
|
|
90
|
+
reject(stoppedBeforeStart);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let started;
|
|
74
94
|
try {
|
|
75
|
-
|
|
95
|
+
started = fn(callbackAbort?.signal ?? ao.signal, ctx);
|
|
76
96
|
}
|
|
77
97
|
catch (err) {
|
|
98
|
+
removeSourceAbortListener?.();
|
|
78
99
|
r.token.release(); // no usage on error
|
|
79
|
-
|
|
100
|
+
reject(err);
|
|
101
|
+
return;
|
|
80
102
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
void Promise.resolve(started).then((result) => {
|
|
104
|
+
removeSourceAbortListener?.();
|
|
105
|
+
// Extract usage for refund.
|
|
106
|
+
let usage;
|
|
107
|
+
if (getUsage) {
|
|
108
|
+
try {
|
|
109
|
+
const extracted = getUsage(result);
|
|
110
|
+
usage =
|
|
111
|
+
extracted === undefined
|
|
112
|
+
? undefined
|
|
113
|
+
: (0, validation_js_1.validateTokenUsage)(extracted);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// bad getUsage must not break release
|
|
117
|
+
}
|
|
118
|
+
}
|
|
84
119
|
try {
|
|
85
|
-
|
|
86
|
-
usage =
|
|
87
|
-
extracted === undefined ? undefined : (0, validation_js_1.validateTokenUsage)(extracted);
|
|
120
|
+
r.token.release(usage);
|
|
88
121
|
}
|
|
89
|
-
catch {
|
|
90
|
-
|
|
122
|
+
catch (err) {
|
|
123
|
+
reject(err);
|
|
124
|
+
return;
|
|
91
125
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
resolve(result);
|
|
127
|
+
}, (err) => {
|
|
128
|
+
removeSourceAbortListener?.();
|
|
129
|
+
try {
|
|
130
|
+
r.token.release(); // no usage on error
|
|
131
|
+
}
|
|
132
|
+
catch (releaseError) {
|
|
133
|
+
reject(releaseError);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
reject(err);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
96
139
|
if (deadlineMs === undefined || callbackAbort === undefined)
|
|
97
140
|
return work;
|
|
98
141
|
return withBorrowedDeadline(work, r, deadlineMs, callbackAbort, () => removeSourceAbortListener?.());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admitted-run.cjs","sourceRoot":"","sources":["../../../src/engine/admitted-run.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"admitted-run.cjs","sourceRoot":"","sources":["../../../src/engine/admitted-run.ts"],"names":[],"mappings":";;AAwEA,kCAiHC;AAjLD,4CAAmE;AACnE,oDAAsD;AACtD,2CAKqB;AAIrB;;;;;;GAMG;AACH,SAAS,oBAAoB,CAC3B,IAAgB,EAChB,CAAW,EACX,UAAkB,EAClB,aAA8B,EAC9B,OAAmB;IAEnB,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,IAAI,aAAa,GAAG,KAAK,CAAC;QAC1B,MAAM,MAAM,GAAG,CAAC,EAAc,EAAQ,EAAE;YACtC,IAAI,aAAa;gBAAE,OAAO;YAC1B,aAAa,GAAG,IAAI,CAAC;YACrB,EAAE,EAAE,CAAC;QACP,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE;YAC/B,MAAM,KAAK,GAAG,IAAI,+CAAmC,CACnD,UAAU,EACV,CAAC,CAAC,WAAW,EACb,CAAC,CAAC,SAAS,EACX,CAAC,CAAC,cAAc,CACjB,CAAC;YACF,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,8BAAkB,CAAC,CAAC,UAAU,CAAC;gBAAE,OAAO;YACrD,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,K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