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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does running work fit the applied limits, and if not, which call should
|
|
3
|
+
* be stopped next to make it fit?
|
|
4
|
+
*
|
|
5
|
+
* Read-only. Limits come from their owner, slots from the gate and the
|
|
6
|
+
* class slots, and the running calls from the set that owns them. Used by
|
|
7
|
+
* the take-back in `stop.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Token limits are checked against the calls still running. A stopped
|
|
10
|
+
* call keeps its hold in the ledger until it settles, but it cannot be
|
|
11
|
+
* stopped a second time, so it is left out.
|
|
12
|
+
*/
|
|
13
|
+
import type { ClassSlots } from "./class-slots.js";
|
|
14
|
+
import type { Limits } from "./limits.js";
|
|
15
|
+
import type { RunningCall, RunningCalls } from "./running-calls.js";
|
|
16
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
17
|
+
type Deps = {
|
|
18
|
+
budgetEnabled: boolean;
|
|
19
|
+
concurrency: ConcurrencyGate;
|
|
20
|
+
limits: Limits;
|
|
21
|
+
slots: ClassSlots;
|
|
22
|
+
running: RunningCalls;
|
|
23
|
+
};
|
|
24
|
+
export declare function createLimitFit(deps: Deps): {
|
|
25
|
+
aboveLimits: () => boolean;
|
|
26
|
+
nextToStop: () => RunningCall | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type LimitFit = ReturnType<typeof createLimitFit>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=limit-fit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit-fit.d.ts","sourceRoot":"","sources":["../../../src/engine/limit-fit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAYF,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI;uBA2Gf,OAAO;sBAQR,WAAW,GAAG,SAAS;EAU/C;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Owner of the admission limits that change at runtime: the limit
|
|
3
|
-
* revision, the token budget, the high-priority reserve,
|
|
4
|
-
* floors and ceilings.
|
|
3
|
+
* revision, the token budget, the high-priority reserve, each class's
|
|
4
|
+
* floors and ceilings, and the stop policy.
|
|
5
5
|
*
|
|
6
6
|
* The two concurrency ceilings (`maxConcurrent`, `maxQueue`) live in the
|
|
7
7
|
* concurrency gate; this module installs them there as the last step of
|
|
8
8
|
* one synchronous update. Nothing outside this file writes a limit.
|
|
9
9
|
*/
|
|
10
|
-
import type { LLMAdmissionClassLimits, LLMAdmissionLimits, LLMApplyLimitsResult, LLMPriority, TokenBudgetOptions } from "../types.js";
|
|
10
|
+
import type { LLMAdmissionClassLimits, LLMAdmissionLimits, LLMAdmissionStopPolicy, LLMApplyLimitsResult, LLMPriority, TokenBudgetOptions } from "../types.js";
|
|
11
11
|
import type { EventHub } from "./events.js";
|
|
12
12
|
import type { ResolvedOptions } from "./options.js";
|
|
13
13
|
import type { ConcurrencyGate } from "./shared.js";
|
|
@@ -33,6 +33,8 @@ budget: TokenBudgetOptions | undefined, concurrency: ConcurrencyGate, events: Ev
|
|
|
33
33
|
/** Current budget ceiling; `undefined` when no token budget is configured. */
|
|
34
34
|
budget: () => number | undefined;
|
|
35
35
|
highPriorityReserve: () => number;
|
|
36
|
+
/** The applied stop policy; `undefined` when stopping is off. */
|
|
37
|
+
stopPolicy: () => LLMAdmissionStopPolicy | undefined;
|
|
36
38
|
effectiveBudget: (priority: LLMPriority) => number;
|
|
37
39
|
protectedConcurrentTotal: () => number;
|
|
38
40
|
protectedTokensTotal: () => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../../src/engine/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK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calls: every admitted call that has neither
|
|
3
|
+
* reached final settlement nor been stopped, in admission order.
|
|
4
|
+
*
|
|
5
|
+
* The other owners keep counters only, which is enough to admit and
|
|
6
|
+
* release work. Stopping admitted work needs the calls themselves: which
|
|
7
|
+
* ones are still running, what each holds right now, and which to stop
|
|
8
|
+
* first. Nothing outside this file adds to or removes from the set; the
|
|
9
|
+
* admitted token registers its call at admission and removes it at stop or
|
|
10
|
+
* final release.
|
|
11
|
+
*
|
|
12
|
+
* Every admission pays for being registered, whether or not anything is
|
|
13
|
+
* ever stopped, so the set is a linked list threaded through the calls
|
|
14
|
+
* themselves. Adding or removing a call is a few pointer writes: no
|
|
15
|
+
* allocation and no hashing.
|
|
16
|
+
*
|
|
17
|
+
* The stop order is fixed and lives here:
|
|
18
|
+
*
|
|
19
|
+
* 1. calls admitted on borrowed capacity
|
|
20
|
+
* 2. normal priority before high priority
|
|
21
|
+
* 3. on a tie, the call admitted last
|
|
22
|
+
*/
|
|
23
|
+
import type { LLMPriority } from "../types.js";
|
|
24
|
+
/**
|
|
25
|
+
* One running call, as the stop triggers see it: a read-only view of the
|
|
26
|
+
* admitted token's own record. `slotReturned` and `held` are live.
|
|
27
|
+
*/
|
|
28
|
+
export type RunningCall = {
|
|
29
|
+
readonly priority: LLMPriority;
|
|
30
|
+
readonly admissionClass: string | undefined;
|
|
31
|
+
/** Admitted on a slot or on tokens above its class floor. */
|
|
32
|
+
readonly borrowed: boolean;
|
|
33
|
+
/** Tokens reserved at admission; 0 without a token budget. */
|
|
34
|
+
readonly reservedTokens: number;
|
|
35
|
+
/** The concurrency slot went back before final settlement. */
|
|
36
|
+
readonly slotReturned: boolean;
|
|
37
|
+
/** Tokens the call holds against the budget right now. */
|
|
38
|
+
readonly held: number;
|
|
39
|
+
/**
|
|
40
|
+
* Neighbors in admission order. These two belong to the set of running
|
|
41
|
+
* calls: a call starts with both `undefined`, and only this file writes
|
|
42
|
+
* them.
|
|
43
|
+
*/
|
|
44
|
+
admittedBefore: RunningCall | undefined;
|
|
45
|
+
admittedAfter: RunningCall | undefined;
|
|
46
|
+
};
|
|
47
|
+
export declare function createRunningCalls(): {
|
|
48
|
+
add: (call: RunningCall) => void;
|
|
49
|
+
remove: (call: RunningCall) => void;
|
|
50
|
+
firstToStop: (eligible: (call: RunningCall) => boolean) => RunningCall | undefined;
|
|
51
|
+
inStopOrder: () => RunningCall[];
|
|
52
|
+
heldTokens: (classId?: string) => number;
|
|
53
|
+
};
|
|
54
|
+
export type RunningCalls = ReturnType<typeof createRunningCalls>;
|
|
55
|
+
//# sourceMappingURL=running-calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"running-calls.d.ts","sourceRoot":"","sources":["../../../src/engine/running-calls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,8DAA8D;IAC9D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,8DAA8D;IAC9D,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,WAAW,GAAG,SAAS,CAAC;IACxC,aAAa,EAAE,WAAW,GAAG,SAAS,CAAC;CACxC,CAAC;AAQF,wBAAgB,kBAAkB;gBAKb,WAAW,KAAG,IAAI;mBAYf,WAAW,KAAG,IAAI;4BAa5B,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,KACvC,WAAW,GAAG,SAAS;uBAYF,WAAW,EAAE;2BAgBP,MAAM,KAAG,MAAM;EAW9C;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* point re-exports only what `src/index.ts` lists.
|
|
6
6
|
*/
|
|
7
7
|
import type { AcquireOptions } from "async-bulkhead-ts";
|
|
8
|
+
import type { LLMAdmissionStoppedError } from "../errors.js";
|
|
8
9
|
import type { createReconfigurableBulkhead } from "../reconfigurable-bulkhead.js";
|
|
9
10
|
import type { LLMAcquireResult, LLMAdmissionResources, LLMBorrowedConcurrencyAbandonCause, LLMCapacityConstraint, LLMPriority, LLMRejectReason, LLMReservationEstimate, LLMToken } from "../types.js";
|
|
10
11
|
/** Abort signal accepted by the underlying concurrency acquire. */
|
|
@@ -50,8 +51,20 @@ export declare const NO_ADMISSION_RESOURCES: LLMAdmissionResources;
|
|
|
50
51
|
* from a published token.
|
|
51
52
|
*/
|
|
52
53
|
export declare const ABANDON_WITH_CAUSE: unique symbol;
|
|
54
|
+
/**
|
|
55
|
+
* How `run()` learns that the engine stopped its call. Engine-private for
|
|
56
|
+
* the same reason as `ABANDON_WITH_CAUSE`: a published token must not let
|
|
57
|
+
* a caller intercept or fake a stop.
|
|
58
|
+
*/
|
|
59
|
+
export declare const ON_STOP: unique symbol;
|
|
53
60
|
export type WrappedLLMToken = LLMToken & {
|
|
54
61
|
[ABANDON_WITH_CAUSE](cause: LLMBorrowedConcurrencyAbandonCause): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Register what to do when the engine stops this call. If the call was
|
|
64
|
+
* already stopped, the handler is not kept and the stop error is
|
|
65
|
+
* returned instead.
|
|
66
|
+
*/
|
|
67
|
+
[ON_STOP](handler: (error: LLMAdmissionStoppedError) => void): LLMAdmissionStoppedError | undefined;
|
|
55
68
|
};
|
|
56
69
|
export type InternalAcquireResult = (Extract<LLMAcquireResult, {
|
|
57
70
|
ok: true;
|
|
@@ -1 +1 @@
|
|
|
1
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IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAErE,eAAO,MAAM,sBAAsB,EAAE,qBAGnC,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,eAAgD,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,OAAO,eAAmB,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG;IACvC,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,kCAAkC,GAAG,OAAO,CAAC;IACzE;;;;OAIG;IACH,CAAC,OAAO,CAAC,CACP,OAAO,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,GACjD,wBAAwB,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,CAAC,OAAO,CAAC,gBAAgB,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,GAAG;IAAE,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC,GACtE,OAAO,CAAC,gBAAgB,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `drain()` waits for two things: the concurrency gate to empty, and every
|
|
5
5
|
* admitted call to reach final settlement. The second matters because a
|
|
6
|
-
* call that abandoned its borrowed slot no longer holds
|
|
7
|
-
* holds tokens until it releases.
|
|
6
|
+
* call that abandoned its borrowed slot, or was stopped, no longer holds a
|
|
7
|
+
* slot, yet still holds tokens until it releases.
|
|
8
8
|
*/
|
|
9
9
|
import type { LLMDrainResult } from "../types.js";
|
|
10
10
|
import type { AdmissionCounts } from "./admission-counts.js";
|
|
11
11
|
import type { ConcurrencyGate } from "./shared.js";
|
|
12
|
-
export declare function createShutdown(concurrency: ConcurrencyGate, counts: AdmissionCounts
|
|
12
|
+
export declare function createShutdown(concurrency: ConcurrencyGate, counts: AdmissionCounts,
|
|
13
|
+
/** Stop every running call for a drain deadline; returns how many. */
|
|
14
|
+
stopForDrain: () => number): {
|
|
13
15
|
settleDrainWaiters: () => void;
|
|
14
16
|
close: () => void;
|
|
15
17
|
drain: (opts?: {
|
|
16
18
|
timeoutMs?: number;
|
|
19
|
+
stopOnTimeout?: boolean;
|
|
17
20
|
}) => Promise<void> | Promise<LLMDrainResult>;
|
|
18
21
|
};
|
|
19
22
|
export type Shutdown = ReturnType<typeof createShutdown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,cAAc,CAC5B,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,eAAe;
|
|
1
|
+
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,cAAc,CAC5B,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,eAAe;AACvB,sEAAsE;AACtE,YAAY,EAAE,MAAM,MAAM;8BAKK,IAAI;iBAajB,IAAI;mBAIA;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,KAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;EA+C5C;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/engine/stats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAGV,QAAQ,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/engine/stats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAGV,QAAQ,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAyEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,SAIX,QAAQ,CAwClC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validator for the `stop` part of a limits snapshot.
|
|
3
|
+
*
|
|
4
|
+
* A pure function, like the class-limit validators: it reads a
|
|
5
|
+
* caller-supplied value and either returns a validated, frozen copy or
|
|
6
|
+
* throws. It never touches engine state.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMAdmissionStopPolicy } from "../types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Read the `stop` part of a limits snapshot. `undefined` means the
|
|
11
|
+
* snapshot carries no stop policy. Each property is read once, so an
|
|
12
|
+
* accessor cannot return one value here and another later.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readStopPolicy(supplied: unknown, tokenBudgetEnabled: boolean): LLMAdmissionStopPolicy | undefined;
|
|
15
|
+
//# sourceMappingURL=stop-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-policy.d.ts","sourceRoot":"","sources":["../../../src/engine/stop-policy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAM1D;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,OAAO,EACjB,kBAAkB,EAAE,OAAO,GAC1B,sBAAsB,GAAG,SAAS,CAoCpC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three triggers that stop admitted work, and the decision of which
|
|
3
|
+
* calls to stop. All of it is off until a limits snapshot carries a `stop`
|
|
4
|
+
* policy or a drain asks for `stopOnTimeout`.
|
|
5
|
+
*
|
|
6
|
+
* - overrun: a usage report raised a hold too far
|
|
7
|
+
* - drain: a bounded drain reached its deadline
|
|
8
|
+
* - take-back: a limits snapshot left running work above the new limits
|
|
9
|
+
* and its grace period ran out
|
|
10
|
+
*
|
|
11
|
+
* This module keeps one piece of state, the timer of the take-back that is
|
|
12
|
+
* waiting. Everything else is read live. Whether running work fits the
|
|
13
|
+
* applied limits is answered by `limit-fit.ts`, and stopping itself is
|
|
14
|
+
* done by the admitted token, through `deps.stop`.
|
|
15
|
+
*
|
|
16
|
+
* Token fitting counts only the calls still running. A stopped call keeps
|
|
17
|
+
* its hold in the ledger until it settles, which keeps blocking new
|
|
18
|
+
* admissions, but it cannot be stopped a second time.
|
|
19
|
+
*/
|
|
20
|
+
import type { LLMAdmissionStopCause } from "../types.js";
|
|
21
|
+
import type { ClassSlots } from "./class-slots.js";
|
|
22
|
+
import type { Limits } from "./limits.js";
|
|
23
|
+
import type { RunningCall, RunningCalls } from "./running-calls.js";
|
|
24
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
25
|
+
type Deps = {
|
|
26
|
+
budgetEnabled: boolean;
|
|
27
|
+
concurrency: ConcurrencyGate;
|
|
28
|
+
limits: Limits;
|
|
29
|
+
slots: ClassSlots;
|
|
30
|
+
running: RunningCalls;
|
|
31
|
+
/**
|
|
32
|
+
* Stop one running call. Returns false when it had already been stopped
|
|
33
|
+
* or had settled, so it is never counted twice.
|
|
34
|
+
*/
|
|
35
|
+
stop: (call: RunningCall, cause: LLMAdmissionStopCause) => boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare function createStopper(deps: Deps): {
|
|
38
|
+
holdGrew: (call: RunningCall, delta: number) => void;
|
|
39
|
+
limitsApplied: () => void;
|
|
40
|
+
stopForDrain: () => number;
|
|
41
|
+
};
|
|
42
|
+
export type Stopper = ReturnType<typeof createStopper>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=stop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../src/engine/stop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,qBAAqB,KAAK,OAAO,CAAC;CACpE,CAAC;AAIF,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI;qBA8Dd,WAAW,SAAS,MAAM,KAAG,IAAI;yBAzC/B,IAAI;wBA0EL,MAAM;EAShC;AAED,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -59,5 +59,7 @@ export declare function usageSnapshot(call: {
|
|
|
59
59
|
outputCap: number | null;
|
|
60
60
|
sequence: number;
|
|
61
61
|
held: number;
|
|
62
|
+
/** The engine has stopped this call. Never set for bypassed work. */
|
|
63
|
+
stopped?: boolean;
|
|
62
64
|
}): UsageReport;
|
|
63
65
|
//# sourceMappingURL=usage-report.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-report.d.ts","sourceRoot":"","sources":["../../../src/engine/usage-report.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACV,WAAW,EACZ,MAAM,aAAa,CAAC;AAKrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,EAAE,UAAU,GAAG,SAAS,CAAA;CAAE,CAAC;AAE7D,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,gCAAgC,GAAG,SAAS,EAC5D,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAC7B,IAAI,CAkBN;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,UAAU,GAAG,SAAS,EAChC,KAAK,EAAE,UAAU,GAChB,UAAU,CAOZ;AAED,kEAAkE;AAClE,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,UAAU,GAAG,SAAS,GAC/B,OAAO,CAMT;AAED;;;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
+
* Typed errors returned by `run()` for admission rejection, lease expiry
|
|
3
|
+
* and stopped admissions.
|
|
4
|
+
*/
|
|
5
|
+
import type { LLMAdmissionResources, LLMAdmissionStopCause, LLMRejectDetail, LLMRejectReason } from "./types.js";
|
|
3
6
|
export declare class LLMBulkheadRejectedError extends Error {
|
|
4
7
|
readonly reason: LLMRejectReason;
|
|
5
8
|
readonly code: "LLM_BULKHEAD_REJECTED";
|
|
@@ -19,4 +22,20 @@ export declare class LLMBorrowedConcurrencyDeadlineError extends Error {
|
|
|
19
22
|
readonly code: "LLM_BORROWED_CONCURRENCY_DEADLINE";
|
|
20
23
|
constructor(deadlineMs: number, admissionId: string, resources: LLMAdmissionResources, admissionClass?: string | undefined);
|
|
21
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Returned by `run()` when the engine stops a call it had admitted (v3.18).
|
|
27
|
+
* It is also the abort reason of the callback's signal.
|
|
28
|
+
*
|
|
29
|
+
* `cause` names the trigger: `"overrun"`, `"drain_deadline"` or `"limits"`.
|
|
30
|
+
* The local concurrency slot has been returned, but token accounting
|
|
31
|
+
* remains held until the underlying callback actually settles.
|
|
32
|
+
*/
|
|
33
|
+
export declare class LLMAdmissionStoppedError extends Error {
|
|
34
|
+
readonly cause: LLMAdmissionStopCause;
|
|
35
|
+
readonly admissionId: string;
|
|
36
|
+
readonly resources: LLMAdmissionResources;
|
|
37
|
+
readonly admissionClass?: string | undefined;
|
|
38
|
+
readonly code: "LLM_ADMISSION_STOPPED";
|
|
39
|
+
constructor(cause: LLMAdmissionStopCause, admissionId: string, resources: LLMAdmissionResources, admissionClass?: string | undefined);
|
|
40
|
+
}
|
|
22
41
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":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|
-
* - `errors.ts` — `LLMBulkheadRejectedError`
|
|
8
|
+
* - `errors.ts` — `LLMBulkheadRejectedError` and the two errors for
|
|
9
|
+
* admitted work that ended early
|
|
9
10
|
* - `profiles.ts` — `PROFILES` presets
|
|
10
11
|
* - `estimators.ts` — naive + model-aware estimators, `extractTextLength`
|
|
11
12
|
* - `adaptive.ts` — `createAdaptiveTokenEstimator` (v3.8)
|
|
@@ -18,14 +19,15 @@
|
|
|
18
19
|
* - `engine/` — the parts of the admission engine, one concern per
|
|
19
20
|
* file (limits, token ledger, class slots, admission
|
|
20
21
|
* counts, capacity checks, the admitted token, `run()`,
|
|
21
|
-
* observe mode, deduplication, stats, shutdown
|
|
22
|
-
*
|
|
22
|
+
* observe mode, deduplication, stats, shutdown, the
|
|
23
|
+
* running calls and the stop triggers); the full list
|
|
24
|
+
* is in the header of `bulkhead.ts`
|
|
23
25
|
*
|
|
24
26
|
* Deep-importing the internal modules is not supported; the package
|
|
25
27
|
* `exports` map exposes only this entry point.
|
|
26
28
|
*/
|
|
27
|
-
export type { ContentBlock, DeduplicationOptions, Listener, LLMAdmissionClassLimits, LLMAdmissionResources, LLMBorrowedConcurrencyAbandonCause, LLMAdmissionClassesOptions, LLMAdmissionClassStats, LLMAdmissionClassSharedStats, LLMAdmissionLimits, LLMApplyLimitsResult, LLMAcquireOptions, LLMAcquireResult, LLMAdmissionMode, LLMBulkheadOptions, LLMCapacityConstraint, LLMDrainResult, LLMEventMap, LLMEventType, LLMMessage, LLMPriority, LLMRejectDetail, LLMRejectReason, LLMRequest, LLMRequestStats, LLMReservationEstimate, LLMRunAdmission, LLMRunOptions, LLMReservationOverride, LLMRunContext, LLMShadowableRejectReason, LLMStats, LLMObserveStats, LLMToken, LLMWouldAdmitResult, OpaqueContentBlock, ProgressiveReconciliationOptions, TextContentBlock, TokenBudgetOptions, TokenEstimate, TokenEstimator, TokenUsage, UsageReport, } from "./types.js";
|
|
28
|
-
export { LLMBorrowedConcurrencyDeadlineError, LLMBulkheadRejectedError, } from "./errors.js";
|
|
29
|
+
export type { ContentBlock, DeduplicationOptions, Listener, LLMAdmissionClassLimits, LLMAdmissionResources, LLMBorrowedConcurrencyAbandonCause, LLMAdmissionClassesOptions, LLMAdmissionClassStats, LLMAdmissionClassSharedStats, LLMAdmissionLimits, LLMAdmissionStopCause, LLMAdmissionStopPolicy, LLMApplyLimitsResult, LLMAcquireOptions, LLMAcquireResult, LLMAdmissionMode, LLMBulkheadOptions, LLMCapacityConstraint, LLMDrainResult, LLMEventMap, LLMEventType, LLMMessage, LLMPriority, LLMRejectDetail, LLMRejectReason, LLMRequest, LLMRequestStats, LLMReservationEstimate, LLMRunAdmission, LLMRunOptions, LLMReservationOverride, LLMRunContext, LLMShadowableRejectReason, LLMStats, LLMObserveStats, LLMToken, LLMWouldAdmitResult, OpaqueContentBlock, ProgressiveReconciliationOptions, TextContentBlock, TokenBudgetOptions, TokenEstimate, TokenEstimator, TokenUsage, UsageReport, } from "./types.js";
|
|
30
|
+
export { LLMAdmissionStoppedError, LLMBorrowedConcurrencyDeadlineError, LLMBulkheadRejectedError, } from "./errors.js";
|
|
29
31
|
export { PROFILES } from "./profiles.js";
|
|
30
32
|
export type { LLMBulkheadPreset } from "./profiles.js";
|
|
31
33
|
export { createModelAwareTokenEstimator, extractTextLength, naiveTokenEstimator, } from "./estimators.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,QAAQ,EACR,uBAAuB,EACvB,qBAAqB,EACrB,kCAAkC,EAClC,0BAA0B,EAC1B,sBAAsB,EACtB,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,eAAe,EACf,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,aAAa,EACb,yBAAyB,EACzB,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,kBAAkB,EAClB,gCAAgC,EAChC,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACxB,mCAAmC,EACnC,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EACL,8BAA8B,EAC9B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC7D,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -128,11 +128,17 @@ export type LLMWouldAdmitResult = {
|
|
|
128
128
|
* `pending` report what was still outstanding at that moment. `inFlight`
|
|
129
129
|
* includes token-holding LLM admissions whose borrowed local concurrency
|
|
130
130
|
* slot has already been abandoned but whose token has not been released.
|
|
131
|
+
*
|
|
132
|
+
* `stopped` (v3.18) is present only when the call passed
|
|
133
|
+
* `stopOnTimeout: true`: the number of admitted calls the deadline stopped.
|
|
134
|
+
* A stopped call still counts in `inFlight` until its callback settles or
|
|
135
|
+
* its `acquire()` token is released.
|
|
131
136
|
*/
|
|
132
137
|
export type LLMDrainResult = {
|
|
133
138
|
drained: boolean;
|
|
134
139
|
inFlight: number;
|
|
135
140
|
pending: number;
|
|
141
|
+
stopped?: number;
|
|
136
142
|
};
|
|
137
143
|
/**
|
|
138
144
|
* Actual token usage returned by the provider after a call completes.
|
|
@@ -175,8 +181,9 @@ export type LLMPriority = "high" | "normal";
|
|
|
175
181
|
* IDs rather than using arbitrary tenant IDs directly.
|
|
176
182
|
*
|
|
177
183
|
* Protected capacity is reserved before shared capacity is lent to requests
|
|
178
|
-
* above their class floor.
|
|
179
|
-
*
|
|
184
|
+
* above their class floor. When a floor grows, new borrowing pauses until the
|
|
185
|
+
* protected capacity is restored. Existing work is left to finish by itself
|
|
186
|
+
* unless the snapshot opts in to `stop.takeBackGraceMs` (v3.18).
|
|
180
187
|
* Omitted ceilings inherit the enclosing bulkhead's global ceiling. Class
|
|
181
188
|
* limits are fail-fast and do not create a separate per-class queue.
|
|
182
189
|
*/
|
|
@@ -318,6 +325,53 @@ export type LLMAcquireOptions = AcquireOptions & {
|
|
|
318
325
|
*/
|
|
319
326
|
reservation?: LLMReservationOverride;
|
|
320
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* Why the engine stopped a call it had already admitted (v3.18).
|
|
330
|
+
*
|
|
331
|
+
* - `"overrun"` — a usage report pushed the call's token hold past its
|
|
332
|
+
* reservation plus `stop.overrunAllowanceTokens`, or left its class or the
|
|
333
|
+
* pool above a token ceiling.
|
|
334
|
+
* - `"drain_deadline"` — `drain({ timeoutMs, stopOnTimeout: true })` reached
|
|
335
|
+
* its deadline while the call was still running.
|
|
336
|
+
* - `"limits"` — a limits snapshot left running work above the new limits
|
|
337
|
+
* and `stop.takeBackGraceMs` elapsed.
|
|
338
|
+
*/
|
|
339
|
+
export type LLMAdmissionStopCause = "overrun" | "drain_deadline" | "limits";
|
|
340
|
+
/**
|
|
341
|
+
* Opt-in policy for stopping admitted work (v3.18). It is part of the
|
|
342
|
+
* limits snapshot: a snapshot without `stop` has no policy, and nothing is
|
|
343
|
+
* carried over from the previous revision.
|
|
344
|
+
*
|
|
345
|
+
* Stopping a call always means the same thing. The signal passed to its
|
|
346
|
+
* `run()` callback is aborted, the caller's promise rejects with
|
|
347
|
+
* `LLMAdmissionStoppedError`, and the concurrency slot returns at once. The
|
|
348
|
+
* token hold stays charged until the callback settles, because a local
|
|
349
|
+
* abort does not prove the provider stopped work.
|
|
350
|
+
*
|
|
351
|
+
* `run()` hands the callback a signal the engine can abort only while a
|
|
352
|
+
* policy is active at admission. An empty object enables neither trigger
|
|
353
|
+
* below but still makes callbacks abortable, which is what
|
|
354
|
+
* `drain({ stopOnTimeout: true })` needs.
|
|
355
|
+
*/
|
|
356
|
+
export type LLMAdmissionStopPolicy = {
|
|
357
|
+
/**
|
|
358
|
+
* Tokens a call's hold may grow above its reservation. One token more
|
|
359
|
+
* stops the call with cause `"overrun"`. Setting this also turns on
|
|
360
|
+
* ceiling fitting: when a usage report grows a hold and leaves a class
|
|
361
|
+
* above `maxInFlightTokens` or the pool above its budget, calls are
|
|
362
|
+
* stopped until the holds of the calls still running fit. Requires a
|
|
363
|
+
* token budget. Non-negative integer.
|
|
364
|
+
*/
|
|
365
|
+
readonly overrunAllowanceTokens?: number;
|
|
366
|
+
/**
|
|
367
|
+
* Grace period, in milliseconds, before work that a limits snapshot left
|
|
368
|
+
* above the new limits is stopped with cause `"limits"`. Calls that
|
|
369
|
+
* finish inside the grace period are left alone, and a newer snapshot
|
|
370
|
+
* replaces a take-back that is still waiting. Integer from 0 through
|
|
371
|
+
* 2,147,483,647.
|
|
372
|
+
*/
|
|
373
|
+
readonly takeBackGraceMs?: number;
|
|
374
|
+
};
|
|
321
375
|
/**
|
|
322
376
|
* Complete, versioned snapshot of every admission limit that can change at
|
|
323
377
|
* runtime. Updates are intentionally not partial: callers must provide the
|
|
@@ -344,6 +398,12 @@ export type LLMAdmissionLimits = {
|
|
|
344
398
|
* Keys cannot be added or removed at runtime.
|
|
345
399
|
*/
|
|
346
400
|
readonly admissionClasses?: Readonly<Record<string, LLMAdmissionClassLimits>>;
|
|
401
|
+
/**
|
|
402
|
+
* Opt-in policy for stopping admitted work (v3.18). Omit it and nothing
|
|
403
|
+
* is ever stopped by an overrun or a limit change. Like every other
|
|
404
|
+
* field it is not inherited: a later snapshot must state it again.
|
|
405
|
+
*/
|
|
406
|
+
readonly stop?: LLMAdmissionStopPolicy;
|
|
347
407
|
};
|
|
348
408
|
/** Result of applying a versioned admission-limit snapshot. */
|
|
349
409
|
export type LLMApplyLimitsResult = {
|
|
@@ -370,6 +430,13 @@ export type LLMRequestStats = {
|
|
|
370
430
|
rejected: number;
|
|
371
431
|
/** LLM-layer rejections by reason. */
|
|
372
432
|
rejectedByReason: Partial<Record<LLMRejectReason, number>>;
|
|
433
|
+
/**
|
|
434
|
+
* Admitted calls the engine stopped (v3.18). Absent until the first
|
|
435
|
+
* stop, so a bulkhead that never stops anything reports the 3.17 shape.
|
|
436
|
+
*/
|
|
437
|
+
stopped?: number;
|
|
438
|
+
/** Stopped calls split by cause. Absent until the first stop. */
|
|
439
|
+
stoppedByCause?: Partial<Record<LLMAdmissionStopCause, number>>;
|
|
373
440
|
};
|
|
374
441
|
export type LLMObserveStats = {
|
|
375
442
|
/** Callbacks executed without acquiring concurrency or token capacity. */
|
|
@@ -407,6 +474,11 @@ export type LLMAdmissionClassStats = {
|
|
|
407
474
|
totalBorrowedAdmissions: number;
|
|
408
475
|
/** Reservation tokens placed in shared capacity at admission time. */
|
|
409
476
|
totalBorrowedTokensReserved: number;
|
|
477
|
+
/**
|
|
478
|
+
* Calls of this class the engine stopped (v3.18). Absent on every class
|
|
479
|
+
* until the bulkhead's first stop; from then on each class reports it.
|
|
480
|
+
*/
|
|
481
|
+
stopped?: number;
|
|
410
482
|
};
|
|
411
483
|
export type LLMAdmissionClassSharedStats = {
|
|
412
484
|
maxConcurrent: number;
|
|
@@ -453,6 +525,7 @@ export type LLMStats = {
|
|
|
453
525
|
* `reportUsage()` reported consumption exceeding the reserved hold.
|
|
454
526
|
* Overrun expands `inFlightTokens` (possibly above `budget`), which
|
|
455
527
|
* correctly blocks new admissions until the overrunning work releases.
|
|
528
|
+
* `stop.overrunAllowanceTokens` (v3.18) bounds how far it can go.
|
|
456
529
|
*/
|
|
457
530
|
totalOverrun: number;
|
|
458
531
|
/** Budget headroom reserved for `priority: "high"` requests. */
|
|
@@ -522,6 +595,24 @@ export type LLMEventMap = {
|
|
|
522
595
|
cause: LLMBorrowedConcurrencyAbandonCause;
|
|
523
596
|
heldTokens: number;
|
|
524
597
|
};
|
|
598
|
+
/**
|
|
599
|
+
* Fired once when the engine stops a call it had admitted (v3.18).
|
|
600
|
+
*
|
|
601
|
+
* The concurrency slot has already been returned when this fires.
|
|
602
|
+
* `heldTokens` stay charged until the eventual `release` event: a stop
|
|
603
|
+
* asks the callback to end, it does not prove the provider did. This is
|
|
604
|
+
* also how an `acquire()` caller, which has no signal, learns of a stop.
|
|
605
|
+
*/
|
|
606
|
+
stop: {
|
|
607
|
+
request: LLMRequest;
|
|
608
|
+
admissionId: string;
|
|
609
|
+
limitRevision: number;
|
|
610
|
+
priority: LLMPriority;
|
|
611
|
+
admissionClass?: string;
|
|
612
|
+
resources: LLMAdmissionResources;
|
|
613
|
+
cause: LLMAdmissionStopCause;
|
|
614
|
+
heldTokens: number;
|
|
615
|
+
};
|
|
525
616
|
/**
|
|
526
617
|
* Fired when a request is rejected at any stage.
|
|
527
618
|
*
|
|
@@ -884,6 +975,12 @@ export type UsageReport = {
|
|
|
884
975
|
outputRemaining: number | null;
|
|
885
976
|
/** True once cumulative consumption exceeds the original reservation. */
|
|
886
977
|
overReservation: boolean;
|
|
978
|
+
/**
|
|
979
|
+
* Present, and `true`, once the engine has stopped this admission
|
|
980
|
+
* (v3.18), including on the report that caused the stop. The token hold
|
|
981
|
+
* stays charged until release.
|
|
982
|
+
*/
|
|
983
|
+
stopped?: true;
|
|
887
984
|
};
|
|
888
985
|
/**
|
|
889
986
|
* Why a borrowed local concurrency slot was returned before settlement.
|
|
@@ -974,6 +1071,10 @@ export type LLMRunOptions<T> = LLMAcquireOptions & {
|
|
|
974
1071
|
* reservation is retained).
|
|
975
1072
|
* - If reported consumption exceeds the hold, the hold expands (overrun),
|
|
976
1073
|
* which blocks new admissions until this request releases.
|
|
1074
|
+
* - Under a stop policy (v3.18) the engine may stop the admission. A token
|
|
1075
|
+
* has no signal: it learns of the stop from the `stop` event and from
|
|
1076
|
+
* `stopped: true` on its usage reports. The slot is already returned; the
|
|
1077
|
+
* token hold stays charged until `release()`.
|
|
977
1078
|
* - Reports are clamped to be monotonically non-decreasing per field.
|
|
978
1079
|
* - If `release()` is later called without usage, the last reported
|
|
979
1080
|
* usage is used for the final refund.
|