@rulvar/core 1.201.0 → 1.203.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/dist/index.d.ts +50 -1
- package/dist/index.js +79 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6199,6 +6199,25 @@ declare class RunBudget {
|
|
|
6199
6199
|
/** Live dispatch estimates held by reserveTurnExposure (RV711). */
|
|
6200
6200
|
private inFlightExposureUsd;
|
|
6201
6201
|
/**
|
|
6202
|
+
* The same live estimates attributed to their holders (RV2001): one
|
|
6203
|
+
* entry per holder scope with a nonzero balance, kept in lockstep
|
|
6204
|
+
* with the scalar above by every acquire and release. The holder is
|
|
6205
|
+
* the agent invocation the dispatch belongs to, so a terminal can
|
|
6206
|
+
* return whatever its agent still holds; entries at zero are removed,
|
|
6207
|
+
* making the map size the live holder count.
|
|
6208
|
+
*/
|
|
6209
|
+
private readonly exposureHolds;
|
|
6210
|
+
/**
|
|
6211
|
+
* Live holds taken without a holder attribution (a direct caller of
|
|
6212
|
+
* reserveTurnExposure): counted so the zero-holders snap below knows
|
|
6213
|
+
* when NOTHING is held. Subtraction leaves float residue (three 0.18
|
|
6214
|
+
* releases leave 5.5e-17), and a residue above zero would park the
|
|
6215
|
+
* exposure wait on money nobody holds, the epsilon-scale rebirth of
|
|
6216
|
+
* the very deadlock RV2001 closes; when the last hold of any kind
|
|
6217
|
+
* releases, the scalar snaps to exactly zero.
|
|
6218
|
+
*/
|
|
6219
|
+
private unattributedHoldCount;
|
|
6220
|
+
/**
|
|
6202
6221
|
* Waiters parked on the next exposure release (RV1902): the
|
|
6203
6222
|
* orchestrate root's dispatch waits out a transient refusal here
|
|
6204
6223
|
* instead of settling a budget error. Notified (and self-removed)
|
|
@@ -6418,7 +6437,37 @@ declare class RunBudget {
|
|
|
6418
6437
|
* (committedReserveUsd) stay out of the formula, because a child's
|
|
6419
6438
|
* lifetime reserve and its own turn exposure would double-count.
|
|
6420
6439
|
*/
|
|
6421
|
-
reserveTurnExposure(servedBy: ModelRef, estimatedInputTokens: number, plannedOutputTokens: number): (() => void) | undefined;
|
|
6440
|
+
reserveTurnExposure(servedBy: ModelRef, estimatedInputTokens: number, plannedOutputTokens: number, holderScope?: string): (() => void) | undefined;
|
|
6441
|
+
/**
|
|
6442
|
+
* The one release chokepoint of the exposure scalar (RV2001):
|
|
6443
|
+
* subtracts, snaps to exactly zero when no hold of any kind remains
|
|
6444
|
+
* (float subtraction leaves residue, and a residue would park the
|
|
6445
|
+
* exposure wait on money nobody holds), and wakes the parked
|
|
6446
|
+
* waiters. Spend never shrinks, so releases stay the only wake
|
|
6447
|
+
* source that can turn a refusal into a fit.
|
|
6448
|
+
*/
|
|
6449
|
+
private settleExposureRelease;
|
|
6450
|
+
/**
|
|
6451
|
+
* The terminal backstop of the exposure surface (RV2001, the third
|
|
6452
|
+
* parity rerun's quiescence deadlock): EVERY terminal of an agent
|
|
6453
|
+
* invocation (ok, error, exhausted, cancelled) returns whatever live
|
|
6454
|
+
* dispatch estimates that holder still has to the exposure budget.
|
|
6455
|
+
* The attempt settle owns the per-hold closure in a finally, so this
|
|
6456
|
+
* usually finds nothing; the parity crash proved a dispatch path can
|
|
6457
|
+
* die without its closure (three killed children left 0.478 USD of
|
|
6458
|
+
* live estimates parked against the cap forever, and the root's
|
|
6459
|
+
* exposure wait starved on money no live dispatch was holding). A
|
|
6460
|
+
* real release wakes the parked waiters exactly like the closure
|
|
6461
|
+
* does; a holder with nothing held is a free no-op. Returns the USD
|
|
6462
|
+
* actually returned.
|
|
6463
|
+
*/
|
|
6464
|
+
releaseExposureHolder(holderScope: string): number;
|
|
6465
|
+
/**
|
|
6466
|
+
* Live exposure holders: agents with a nonzero held balance (RV2001).
|
|
6467
|
+
* Zero with live waiters means nothing can ever release, the drained
|
|
6468
|
+
* signal the quiescence machinery keys on.
|
|
6469
|
+
*/
|
|
6470
|
+
get liveExposureHolderCount(): number;
|
|
6422
6471
|
/** Live in-flight exposure currently held by open dispatches (RV1902). */
|
|
6423
6472
|
get liveExposureUsd(): number;
|
|
6424
6473
|
/**
|
package/dist/index.js
CHANGED
|
@@ -13523,6 +13523,25 @@ var RunBudget = class {
|
|
|
13523
13523
|
/** Live dispatch estimates held by reserveTurnExposure (RV711). */
|
|
13524
13524
|
inFlightExposureUsd = 0;
|
|
13525
13525
|
/**
|
|
13526
|
+
* The same live estimates attributed to their holders (RV2001): one
|
|
13527
|
+
* entry per holder scope with a nonzero balance, kept in lockstep
|
|
13528
|
+
* with the scalar above by every acquire and release. The holder is
|
|
13529
|
+
* the agent invocation the dispatch belongs to, so a terminal can
|
|
13530
|
+
* return whatever its agent still holds; entries at zero are removed,
|
|
13531
|
+
* making the map size the live holder count.
|
|
13532
|
+
*/
|
|
13533
|
+
exposureHolds = /* @__PURE__ */ new Map();
|
|
13534
|
+
/**
|
|
13535
|
+
* Live holds taken without a holder attribution (a direct caller of
|
|
13536
|
+
* reserveTurnExposure): counted so the zero-holders snap below knows
|
|
13537
|
+
* when NOTHING is held. Subtraction leaves float residue (three 0.18
|
|
13538
|
+
* releases leave 5.5e-17), and a residue above zero would park the
|
|
13539
|
+
* exposure wait on money nobody holds, the epsilon-scale rebirth of
|
|
13540
|
+
* the very deadlock RV2001 closes; when the last hold of any kind
|
|
13541
|
+
* releases, the scalar snaps to exactly zero.
|
|
13542
|
+
*/
|
|
13543
|
+
unattributedHoldCount = 0;
|
|
13544
|
+
/**
|
|
13526
13545
|
* Waiters parked on the next exposure release (RV1902): the
|
|
13527
13546
|
* orchestrate root's dispatch waits out a transient refusal here
|
|
13528
13547
|
* instead of settling a budget error. Notified (and self-removed)
|
|
@@ -13920,7 +13939,7 @@ var RunBudget = class {
|
|
|
13920
13939
|
* (committedReserveUsd) stay out of the formula, because a child's
|
|
13921
13940
|
* lifetime reserve and its own turn exposure would double-count.
|
|
13922
13941
|
*/
|
|
13923
|
-
reserveTurnExposure(servedBy, estimatedInputTokens, plannedOutputTokens) {
|
|
13942
|
+
reserveTurnExposure(servedBy, estimatedInputTokens, plannedOutputTokens, holderScope) {
|
|
13924
13943
|
const cap = this.maxInFlightExposureUsd;
|
|
13925
13944
|
if (cap === void 0) return;
|
|
13926
13945
|
const pricing = this.pricingOf?.(servedBy);
|
|
@@ -13941,14 +13960,69 @@ var RunBudget = class {
|
|
|
13941
13960
|
estimateUsd
|
|
13942
13961
|
} });
|
|
13943
13962
|
this.inFlightExposureUsd += estimateUsd;
|
|
13963
|
+
if (estimateUsd > 0) if (holderScope === void 0) this.unattributedHoldCount += 1;
|
|
13964
|
+
else this.exposureHolds.set(holderScope, (this.exposureHolds.get(holderScope) ?? 0) + estimateUsd);
|
|
13944
13965
|
let released = false;
|
|
13945
13966
|
return () => {
|
|
13946
13967
|
if (released) return;
|
|
13947
13968
|
released = true;
|
|
13948
|
-
|
|
13949
|
-
|
|
13969
|
+
let amount = estimateUsd;
|
|
13970
|
+
if (estimateUsd > 0) if (holderScope === void 0) this.unattributedHoldCount = Math.max(0, this.unattributedHoldCount - 1);
|
|
13971
|
+
else {
|
|
13972
|
+
const held = this.exposureHolds.get(holderScope) ?? 0;
|
|
13973
|
+
amount = Math.min(amount, held);
|
|
13974
|
+
const next = held - amount;
|
|
13975
|
+
if (next <= 0) this.exposureHolds.delete(holderScope);
|
|
13976
|
+
else this.exposureHolds.set(holderScope, next);
|
|
13977
|
+
}
|
|
13978
|
+
this.settleExposureRelease(amount);
|
|
13950
13979
|
};
|
|
13951
13980
|
}
|
|
13981
|
+
/**
|
|
13982
|
+
* The one release chokepoint of the exposure scalar (RV2001):
|
|
13983
|
+
* subtracts, snaps to exactly zero when no hold of any kind remains
|
|
13984
|
+
* (float subtraction leaves residue, and a residue would park the
|
|
13985
|
+
* exposure wait on money nobody holds), and wakes the parked
|
|
13986
|
+
* waiters. Spend never shrinks, so releases stay the only wake
|
|
13987
|
+
* source that can turn a refusal into a fit.
|
|
13988
|
+
*/
|
|
13989
|
+
settleExposureRelease(amountUsd) {
|
|
13990
|
+
this.inFlightExposureUsd = Math.max(0, this.inFlightExposureUsd - amountUsd);
|
|
13991
|
+
if (this.exposureHolds.size === 0 && this.unattributedHoldCount === 0) this.inFlightExposureUsd = 0;
|
|
13992
|
+
for (const waiter of [...this.exposureWaiters]) waiter();
|
|
13993
|
+
}
|
|
13994
|
+
/**
|
|
13995
|
+
* The terminal backstop of the exposure surface (RV2001, the third
|
|
13996
|
+
* parity rerun's quiescence deadlock): EVERY terminal of an agent
|
|
13997
|
+
* invocation (ok, error, exhausted, cancelled) returns whatever live
|
|
13998
|
+
* dispatch estimates that holder still has to the exposure budget.
|
|
13999
|
+
* The attempt settle owns the per-hold closure in a finally, so this
|
|
14000
|
+
* usually finds nothing; the parity crash proved a dispatch path can
|
|
14001
|
+
* die without its closure (three killed children left 0.478 USD of
|
|
14002
|
+
* live estimates parked against the cap forever, and the root's
|
|
14003
|
+
* exposure wait starved on money no live dispatch was holding). A
|
|
14004
|
+
* real release wakes the parked waiters exactly like the closure
|
|
14005
|
+
* does; a holder with nothing held is a free no-op. Returns the USD
|
|
14006
|
+
* actually returned.
|
|
14007
|
+
*/
|
|
14008
|
+
releaseExposureHolder(holderScope) {
|
|
14009
|
+
const held = this.exposureHolds.get(holderScope) ?? 0;
|
|
14010
|
+
if (held <= 0) {
|
|
14011
|
+
this.exposureHolds.delete(holderScope);
|
|
14012
|
+
return 0;
|
|
14013
|
+
}
|
|
14014
|
+
this.exposureHolds.delete(holderScope);
|
|
14015
|
+
this.settleExposureRelease(held);
|
|
14016
|
+
return held;
|
|
14017
|
+
}
|
|
14018
|
+
/**
|
|
14019
|
+
* Live exposure holders: agents with a nonzero held balance (RV2001).
|
|
14020
|
+
* Zero with live waiters means nothing can ever release, the drained
|
|
14021
|
+
* signal the quiescence machinery keys on.
|
|
14022
|
+
*/
|
|
14023
|
+
get liveExposureHolderCount() {
|
|
14024
|
+
return this.exposureHolds.size;
|
|
14025
|
+
}
|
|
13952
14026
|
/** Live in-flight exposure currently held by open dispatches (RV1902). */
|
|
13953
14027
|
get liveExposureUsd() {
|
|
13954
14028
|
return this.inFlightExposureUsd;
|
|
@@ -17761,7 +17835,7 @@ function createCtx(internals, rootWorkflow) {
|
|
|
17761
17835
|
remainingUsd: () => internals.budget.remainingUsd(budgetAccount),
|
|
17762
17836
|
...internals.budget.strictPricing === void 0 ? {} : { assertPricedDispatch: (servedBy) => internals.budget.assertPricedDispatch(servedBy) },
|
|
17763
17837
|
...internals.budget.maxInFlightExposureUsd === void 0 ? {} : {
|
|
17764
|
-
admitTurnExposure: (servedBy, estimatedInputTokens, plannedOutputTokens) => internals.budget.reserveTurnExposure(servedBy, estimatedInputTokens, plannedOutputTokens),
|
|
17838
|
+
admitTurnExposure: (servedBy, estimatedInputTokens, plannedOutputTokens) => internals.budget.reserveTurnExposure(servedBy, estimatedInputTokens, plannedOutputTokens, `agent:${running.seq}`),
|
|
17765
17839
|
awaitExposureRelease: (signal) => internals.budget.awaitExposureRelease(signal),
|
|
17766
17840
|
liveExposureUsd: () => internals.budget.liveExposureUsd
|
|
17767
17841
|
},
|
|
@@ -17865,6 +17939,7 @@ function createCtx(internals, rootWorkflow) {
|
|
|
17865
17939
|
}, spanId), branchOrRunSignal);
|
|
17866
17940
|
} finally {
|
|
17867
17941
|
exitActivity?.();
|
|
17942
|
+
internals.budget.releaseExposureHolder(`agent:${running.seq}`);
|
|
17868
17943
|
}
|
|
17869
17944
|
internals.budget.releaseReserve(reserve, budgetAccount);
|
|
17870
17945
|
const declaredRules = internals.quota?.declaredRules;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.203.0",
|
|
4
4
|
"description": "Rulvar core: L0 contracts, journal kernel, ctx primitives, agent runtime, model router, tool system, dynamic orchestrator, InMemory and JSONL stores, event stream.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|