async-bulkhead-llm 3.16.0 → 3.17.1
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 +127 -4
- package/README.md +28 -2
- package/dist/cjs/bulkhead.cjs +119 -1666
- package/dist/cjs/bulkhead.cjs.map +1 -1
- package/dist/cjs/engine/acquire.cjs +144 -0
- package/dist/cjs/engine/acquire.cjs.map +1 -0
- package/dist/cjs/engine/admission-counts.cjs +92 -0
- package/dist/cjs/engine/admission-counts.cjs.map +1 -0
- package/dist/cjs/engine/admission-request.cjs +28 -0
- package/dist/cjs/engine/admission-request.cjs.map +1 -0
- package/dist/cjs/engine/admitted-run.cjs +100 -0
- package/dist/cjs/engine/admitted-run.cjs.map +1 -0
- package/dist/cjs/engine/admitted-token.cjs +192 -0
- package/dist/cjs/engine/admitted-token.cjs.map +1 -0
- package/dist/cjs/engine/bypass.cjs +162 -0
- package/dist/cjs/engine/bypass.cjs.map +1 -0
- package/dist/cjs/engine/capacity.cjs +89 -0
- package/dist/cjs/engine/capacity.cjs.map +1 -0
- package/dist/cjs/engine/class-limits.cjs +101 -0
- package/dist/cjs/engine/class-limits.cjs.map +1 -0
- package/dist/cjs/engine/class-slots.cjs +49 -0
- package/dist/cjs/engine/class-slots.cjs.map +1 -0
- package/dist/cjs/engine/dedup-flow.cjs +207 -0
- package/dist/cjs/engine/dedup-flow.cjs.map +1 -0
- package/dist/cjs/engine/events.cjs +35 -0
- package/dist/cjs/engine/events.cjs.map +1 -0
- package/dist/cjs/engine/limits.cjs +313 -0
- package/dist/cjs/engine/limits.cjs.map +1 -0
- package/dist/cjs/engine/observe-stats.cjs +43 -0
- package/dist/cjs/engine/observe-stats.cjs.map +1 -0
- package/dist/cjs/engine/options.cjs +79 -0
- package/dist/cjs/engine/options.cjs.map +1 -0
- package/dist/cjs/engine/reject-detail.cjs +103 -0
- package/dist/cjs/engine/reject-detail.cjs.map +1 -0
- package/dist/cjs/engine/reservation.cjs +55 -0
- package/dist/cjs/engine/reservation.cjs.map +1 -0
- package/dist/cjs/engine/run-options.cjs +59 -0
- package/dist/cjs/engine/run-options.cjs.map +1 -0
- package/dist/cjs/engine/run.cjs +76 -0
- package/dist/cjs/engine/run.cjs.map +1 -0
- package/dist/cjs/engine/shared-usage.cjs +70 -0
- package/dist/cjs/engine/shared-usage.cjs.map +1 -0
- package/dist/cjs/engine/shared.cjs +17 -0
- package/dist/cjs/engine/shared.cjs.map +1 -0
- package/dist/cjs/engine/shutdown.cjs +58 -0
- package/dist/cjs/engine/shutdown.cjs.map +1 -0
- package/dist/cjs/engine/stats.cjs +92 -0
- package/dist/cjs/engine/stats.cjs.map +1 -0
- package/dist/cjs/engine/token-ledger.cjs +117 -0
- package/dist/cjs/engine/token-ledger.cjs.map +1 -0
- package/dist/cjs/engine/usage-report.cjs +95 -0
- package/dist/cjs/engine/usage-report.cjs.map +1 -0
- package/dist/cjs/engine/would-admit.cjs +37 -0
- package/dist/cjs/engine/would-admit.cjs.map +1 -0
- package/dist/cjs/errors.cjs +22 -1
- package/dist/cjs/errors.cjs.map +1 -1
- package/dist/cjs/index.cjs +11 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/bulkhead.js +119 -1666
- package/dist/esm/bulkhead.js.map +1 -1
- package/dist/esm/engine/acquire.js +141 -0
- package/dist/esm/engine/acquire.js.map +1 -0
- package/dist/esm/engine/admission-counts.js +89 -0
- package/dist/esm/engine/admission-counts.js.map +1 -0
- package/dist/esm/engine/admission-request.js +25 -0
- package/dist/esm/engine/admission-request.js.map +1 -0
- package/dist/esm/engine/admitted-run.js +97 -0
- package/dist/esm/engine/admitted-run.js.map +1 -0
- package/dist/esm/engine/admitted-token.js +189 -0
- package/dist/esm/engine/admitted-token.js.map +1 -0
- package/dist/esm/engine/bypass.js +159 -0
- package/dist/esm/engine/bypass.js.map +1 -0
- package/dist/esm/engine/capacity.js +86 -0
- package/dist/esm/engine/capacity.js.map +1 -0
- package/dist/esm/engine/class-limits.js +95 -0
- package/dist/esm/engine/class-limits.js.map +1 -0
- package/dist/esm/engine/class-slots.js +46 -0
- package/dist/esm/engine/class-slots.js.map +1 -0
- package/dist/esm/engine/dedup-flow.js +204 -0
- package/dist/esm/engine/dedup-flow.js.map +1 -0
- package/dist/esm/engine/events.js +32 -0
- package/dist/esm/engine/events.js.map +1 -0
- package/dist/esm/engine/limits.js +310 -0
- package/dist/esm/engine/limits.js.map +1 -0
- package/dist/esm/engine/observe-stats.js +40 -0
- package/dist/esm/engine/observe-stats.js.map +1 -0
- package/dist/esm/engine/options.js +76 -0
- package/dist/esm/engine/options.js.map +1 -0
- package/dist/esm/engine/reject-detail.js +100 -0
- package/dist/esm/engine/reject-detail.js.map +1 -0
- package/dist/esm/engine/reservation.js +52 -0
- package/dist/esm/engine/reservation.js.map +1 -0
- package/dist/esm/engine/run-options.js +55 -0
- package/dist/esm/engine/run-options.js.map +1 -0
- package/dist/esm/engine/run.js +73 -0
- package/dist/esm/engine/run.js.map +1 -0
- package/dist/esm/engine/shared-usage.js +67 -0
- package/dist/esm/engine/shared-usage.js.map +1 -0
- package/dist/esm/engine/shared.js +14 -0
- package/dist/esm/engine/shared.js.map +1 -0
- package/dist/esm/engine/shutdown.js +55 -0
- package/dist/esm/engine/shutdown.js.map +1 -0
- package/dist/esm/engine/stats.js +89 -0
- package/dist/esm/engine/stats.js.map +1 -0
- package/dist/esm/engine/token-ledger.js +114 -0
- package/dist/esm/engine/token-ledger.js.map +1 -0
- package/dist/esm/engine/usage-report.js +86 -0
- package/dist/esm/engine/usage-report.js.map +1 -0
- package/dist/esm/engine/would-admit.js +34 -0
- package/dist/esm/engine/would-admit.js.map +1 -0
- package/dist/esm/errors.js +20 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +10 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/types/bulkhead.d.ts +33 -6
- package/dist/types/bulkhead.d.ts.map +1 -1
- package/dist/types/engine/acquire.d.ts +25 -0
- package/dist/types/engine/acquire.d.ts.map +1 -0
- package/dist/types/engine/admission-counts.d.ts +30 -0
- package/dist/types/engine/admission-counts.d.ts.map +1 -0
- package/dist/types/engine/admission-request.d.ts +12 -0
- package/dist/types/engine/admission-request.d.ts.map +1 -0
- package/dist/types/engine/admitted-run.d.ts +19 -0
- package/dist/types/engine/admitted-run.d.ts.map +1 -0
- package/dist/types/engine/admitted-token.d.ts +42 -0
- package/dist/types/engine/admitted-token.d.ts.map +1 -0
- package/dist/types/engine/bypass.d.ts +17 -0
- package/dist/types/engine/bypass.d.ts.map +1 -0
- package/dist/types/engine/capacity.d.ts +36 -0
- package/dist/types/engine/capacity.d.ts.map +1 -0
- package/dist/types/engine/class-limits.d.ts +20 -0
- package/dist/types/engine/class-limits.d.ts.map +1 -0
- package/dist/types/engine/class-slots.d.ts +20 -0
- package/dist/types/engine/class-slots.d.ts.map +1 -0
- package/dist/types/engine/dedup-flow.d.ts +41 -0
- package/dist/types/engine/dedup-flow.d.ts.map +1 -0
- package/dist/types/engine/events.d.ts +13 -0
- package/dist/types/engine/events.d.ts.map +1 -0
- package/dist/types/engine/limits.d.ts +45 -0
- package/dist/types/engine/limits.d.ts.map +1 -0
- package/dist/types/engine/observe-stats.d.ts +14 -0
- package/dist/types/engine/observe-stats.d.ts.map +1 -0
- package/dist/types/engine/options.d.ts +21 -0
- package/dist/types/engine/options.d.ts.map +1 -0
- package/dist/types/engine/reject-detail.d.ts +25 -0
- package/dist/types/engine/reject-detail.d.ts.map +1 -0
- package/dist/types/engine/reservation.d.ts +13 -0
- package/dist/types/engine/reservation.d.ts.map +1 -0
- package/dist/types/engine/run-options.d.ts +25 -0
- package/dist/types/engine/run-options.d.ts.map +1 -0
- package/dist/types/engine/run.d.ts +28 -0
- package/dist/types/engine/run.d.ts.map +1 -0
- package/dist/types/engine/shared-usage.d.ts +28 -0
- package/dist/types/engine/shared-usage.d.ts.map +1 -0
- package/dist/types/engine/shared.d.ts +63 -0
- package/dist/types/engine/shared.d.ts.map +1 -0
- package/dist/types/engine/shutdown.d.ts +20 -0
- package/dist/types/engine/shutdown.d.ts.map +1 -0
- package/dist/types/engine/stats.d.ts +28 -0
- package/dist/types/engine/stats.d.ts.map +1 -0
- package/dist/types/engine/token-ledger.d.ts +40 -0
- package/dist/types/engine/token-ledger.d.ts.map +1 -0
- package/dist/types/engine/usage-report.d.ts +63 -0
- package/dist/types/engine/usage-report.d.ts.map +1 -0
- package/dist/types/engine/would-admit.d.ts +16 -0
- package/dist/types/engine/would-admit.d.ts.map +1 -0
- package/dist/types/errors.d.ts +15 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +74 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,115 @@ and adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [3.17.1] - 2026-11-22
|
|
11
|
+
|
|
12
|
+
Internal restructuring release. No public API, runtime behavior, or
|
|
13
|
+
dependency changed; no upgrade action is required.
|
|
14
|
+
|
|
15
|
+
### Internal
|
|
16
|
+
|
|
17
|
+
* **`createLLMBulkhead` split into focused engine modules.** The former
|
|
18
|
+
2,690-line `src/bulkhead.ts` is now a short entry point that validates
|
|
19
|
+
options and wires together 25 modules under `src/engine/`, one concern
|
|
20
|
+
each: limits, token ledger, class slots, admission counts, capacity checks,
|
|
21
|
+
the admitted token, `run()`, observe mode, deduplication, stats, events,
|
|
22
|
+
and shutdown. No file under `src/engine/` is longer than 500 lines and no
|
|
23
|
+
function is longer than 150.
|
|
24
|
+
|
|
25
|
+
* **One owner per counter.** Every limit and counter is now written in
|
|
26
|
+
exactly one module, and a global counter and its per-class twin are always
|
|
27
|
+
moved by the same function. Token counters live in `token-ledger.ts`;
|
|
28
|
+
admitted, released, rejected, and abandoned counts in
|
|
29
|
+
`admission-counts.ts`; per-class slot counts in `class-slots.ts`; and the
|
|
30
|
+
revision, budget, high-priority reserve, and class limits in `limits.ts`.
|
|
31
|
+
The per-class state object that functions used to pass around is gone: a
|
|
32
|
+
class travels as its id. The global slot count stays inside
|
|
33
|
+
`reconfigurable-bulkhead.ts`, which is unchanged.
|
|
34
|
+
|
|
35
|
+
* **`rename-cjs.mjs` handles nested output folders.** The CommonJS rename
|
|
36
|
+
step now walks `dist/cjs` recursively, so the `.cjs` renames, `require()`
|
|
37
|
+
rewrites, `sourceMappingURL` trailers, and source-map `file` fields are
|
|
38
|
+
also correct for `dist/cjs/engine/*`.
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
|
|
42
|
+
* **Class-versus-global counter tests.**
|
|
43
|
+
`test/class_counter_invariants.test.ts` takes admissions through a
|
|
44
|
+
reserve, growing and shrinking usage reports, abandonment, limit updates,
|
|
45
|
+
and release, and checks after every step that each per-class counter adds
|
|
46
|
+
up to its global counterpart. The tests read `stats()` only. Before this,
|
|
47
|
+
nothing in the suite could see a class counter drift from its global twin.
|
|
48
|
+
|
|
49
|
+
### Compatibility
|
|
50
|
+
|
|
51
|
+
* The package entry point exports the identical surface, and the declared
|
|
52
|
+
type of `createLLMBulkhead` and of each of its methods is unchanged.
|
|
53
|
+
* Results, errors, event payloads, rejection reasons and constraints,
|
|
54
|
+
`stats()` snapshots, and the order of counter updates relative to events
|
|
55
|
+
match 3.17.0. This was checked by driving the 3.17.0 build and this build
|
|
56
|
+
with the same 30,000 seeded random scenarios, including listeners that call
|
|
57
|
+
back into the bulkhead, and comparing everything they returned and emitted.
|
|
58
|
+
* `dist/` gains an `engine/` folder for ESM, CJS, and declarations. Deep
|
|
59
|
+
imports of internal modules remain unsupported; the `exports` map still
|
|
60
|
+
exposes only the entry point.
|
|
61
|
+
* The runtime dependency remains `async-bulkhead-ts@^1.0.1`.
|
|
62
|
+
|
|
63
|
+
## [3.17.0] - 2026-09-03
|
|
64
|
+
|
|
65
|
+
### Added
|
|
66
|
+
|
|
67
|
+
* **Resource attribution for admitted work.** Successful acquire results,
|
|
68
|
+
tokens, run contexts, and admission/release events now expose immutable
|
|
69
|
+
`resources` with exact borrowed-concurrency and borrowed-token attribution.
|
|
70
|
+
|
|
71
|
+
* **Borrowed local-slot abandonment.** `LLMToken` and admitted run contexts add
|
|
72
|
+
idempotent `abandonBorrowedConcurrency()`. It returns only a concurrency slot
|
|
73
|
+
that came from shared class capacity; token holds remain charged until final
|
|
74
|
+
release. New global and per-class counters plus the
|
|
75
|
+
`borrowedConcurrencyAbandon` event expose the split lifecycle. The event
|
|
76
|
+
carries a `cause` of `manual` or `deadline`, and
|
|
77
|
+
`llm.borrowedConcurrencyAbandonedByCause` counts each separately, so
|
|
78
|
+
deliberate shedding is distinguishable from a lease configured too tight.
|
|
79
|
+
|
|
80
|
+
* **Wall-clock borrowed-slot deadline.** `run()` accepts
|
|
81
|
+
`borrowedConcurrencyDeadlineMs`. The post-admission timer applies only to a
|
|
82
|
+
borrowed local slot. Expiry returns that slot, aborts the callback signal,
|
|
83
|
+
and rejects the caller with `LLMBorrowedConcurrencyDeadlineError` while the
|
|
84
|
+
underlying callback retains responsibility for token settlement.
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
|
|
88
|
+
* `drain()` now waits for final LLM settlement even after local concurrency was
|
|
89
|
+
abandoned. Timed drain results report outstanding token-holding admissions
|
|
90
|
+
instead of incorrectly declaring the bulkhead drained when only the local
|
|
91
|
+
slot has returned.
|
|
92
|
+
|
|
93
|
+
### Contract
|
|
94
|
+
|
|
95
|
+
* A client-side deadline is an enforceable restoration bound for the local
|
|
96
|
+
admission slot only. It does not prove that a provider account, model queue,
|
|
97
|
+
or accelerator stopped work. Consumers needing a hard upstream guarantee
|
|
98
|
+
must keep an unlent floor or use authoritative provider-side reclamation.
|
|
99
|
+
|
|
100
|
+
### Compatibility
|
|
101
|
+
|
|
102
|
+
* Existing methods and event names remain available. Exact object-equality
|
|
103
|
+
consumers should account for new resource fields and counters. Callers that
|
|
104
|
+
do not use borrowed-slot abandonment retain their previous lifecycle.
|
|
105
|
+
|
|
106
|
+
* After `abandonBorrowedConcurrency()`, `drain()` without `timeoutMs` waits for
|
|
107
|
+
the matching token settlement even though the local slot is already free.
|
|
108
|
+
Manual `acquire()` callers must eventually call `release()` or an unbounded
|
|
109
|
+
drain remains pending; bounded drain reports the admission as outstanding.
|
|
110
|
+
This split lifecycle is new in 3.17 and prevents shutdown from reporting
|
|
111
|
+
false completion.
|
|
112
|
+
|
|
113
|
+
* `Listener` and `LLMBorrowedConcurrencyAbandonCause` are new entry-point type
|
|
114
|
+
exports. `Listener` was previously reachable only through `on()` without
|
|
115
|
+
being nameable by consumers.
|
|
116
|
+
|
|
117
|
+
* The runtime dependency remains `async-bulkhead-ts@^1.0.1`.
|
|
118
|
+
|
|
10
119
|
## [3.16.0] - 2026-08-25
|
|
11
120
|
|
|
12
121
|
### Added
|
|
@@ -77,8 +186,9 @@ dependency behavior changed.
|
|
|
77
186
|
|
|
78
187
|
## [3.15.2] - 2026-08-17
|
|
79
188
|
|
|
80
|
-
Documentation
|
|
81
|
-
identical to 3.15.1; no upgrade action is
|
|
189
|
+
Documentation release, with one development-only dependency update. No runtime
|
|
190
|
+
code changed and the public API is identical to 3.15.1; no upgrade action is
|
|
191
|
+
required.
|
|
82
192
|
|
|
83
193
|
### Changed
|
|
84
194
|
|
|
@@ -136,9 +246,22 @@ identical to 3.15.1; no upgrade action is required.
|
|
|
136
246
|
use absolute repository URLs so they work from GitHub, npm, and the
|
|
137
247
|
documentation site.
|
|
138
248
|
|
|
249
|
+
### Security
|
|
250
|
+
|
|
251
|
+
* **Resolved GHSA-2v37-7h3g-55p8 in `nanoid` (development-only).** `npm audit`
|
|
252
|
+
reported this high-severity advisory -- custom generators can loop
|
|
253
|
+
indefinitely when `size` is zero -- against every `nanoid` before 3.3.18. The
|
|
254
|
+
lockfile now resolves 3.3.18, which carries the fix. `nanoid` reaches this
|
|
255
|
+
repository only as a development-time transitive dependency (`vitest` ->
|
|
256
|
+
`vite` -> `postcss` -> `nanoid`); it has never been a runtime dependency and
|
|
257
|
+
is not part of the published tarball, so consumers of `async-bulkhead-llm`
|
|
258
|
+
were never exposed. `npm audit` now reports no known vulnerabilities at any
|
|
259
|
+
severity.
|
|
260
|
+
|
|
139
261
|
### Compatibility
|
|
140
262
|
|
|
141
|
-
* No API, behavior, or dependency changes for consumers
|
|
263
|
+
* No API, behavior, or runtime dependency changes for consumers; the `nanoid`
|
|
264
|
+
bump is confined to development-only tooling. The published tarball
|
|
142
265
|
contents are unchanged apart from the rewritten `README.md`. `guides/` and
|
|
143
266
|
the documentation tooling are development-only and are not published.
|
|
144
267
|
|
|
@@ -1032,4 +1155,4 @@ Changes required only if you:
|
|
|
1032
1155
|
* `tryAcquire()` from the base library is not exposed — synchronous non-blocking admission is not meaningful for LLM workloads where token budget requires the full request object
|
|
1033
1156
|
* Zero dependencies beyond `async-bulkhead-ts`
|
|
1034
1157
|
|
|
1035
|
-
---
|
|
1158
|
+
---
|
package/README.md
CHANGED
|
@@ -161,6 +161,24 @@ bulkhead.on('reject', ({ reason, detail }) => metrics.increment(reason));
|
|
|
161
161
|
underlying concurrency wait, so local admission cost and queue contention stay
|
|
162
162
|
separate.
|
|
163
163
|
|
|
164
|
+
Admissions also expose exact resource attribution through `resources`.
|
|
165
|
+
For class policies that lend shared concurrency, `run()` can enforce a
|
|
166
|
+
wall-clock lease on the borrowed local slot:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
await bulkhead.run(request, callProvider, {
|
|
170
|
+
admissionClass: 'background',
|
|
171
|
+
borrowedConcurrencyDeadlineMs: 30_000,
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Expiry returns that local concurrency slot, aborts the callback signal, and
|
|
176
|
+
rejects with `LLMBorrowedConcurrencyDeadlineError`. It deliberately retains
|
|
177
|
+
the token hold until the callback settles. This is a local restoration bound,
|
|
178
|
+
not proof that a provider account, accelerator queue, or remote generation was
|
|
179
|
+
reclaimed. Keep an unlent floor or a real provider-side partition for upstream
|
|
180
|
+
capacity that client cancellation cannot authoritatively release.
|
|
181
|
+
|
|
164
182
|
→ [Stats and events](guides/telemetry.md)
|
|
165
183
|
|
|
166
184
|
## Shutting down cleanly
|
|
@@ -171,8 +189,16 @@ bulkhead.close(); // stop admitting
|
|
|
171
189
|
await bulkhead.drain({ timeoutMs: 10_000 }); // wait, but not forever
|
|
172
190
|
```
|
|
173
191
|
|
|
174
|
-
`drain()` with a deadline always resolves and
|
|
175
|
-
|
|
192
|
+
`drain()` with a deadline always resolves and reports what remains outstanding;
|
|
193
|
+
it does not abandon or release that work. One stuck upstream stream therefore
|
|
194
|
+
cannot hold the shutdown decision open indefinitely.
|
|
195
|
+
|
|
196
|
+
Without `timeoutMs`, `drain()` waits for final token settlement as well as base
|
|
197
|
+
concurrency. In particular, returning a borrowed slot with
|
|
198
|
+
`abandonBorrowedConcurrency()` does not complete the admission: a manual
|
|
199
|
+
`acquire()` caller must still call `release()`, or the unbounded drain remains
|
|
200
|
+
pending. This preserves the distinction between restoring a local slot and
|
|
201
|
+
settling the resource accounting for the work behind it.
|
|
176
202
|
|
|
177
203
|
---
|
|
178
204
|
|