maxpool 1.13.1 → 1.13.2
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/package.json +1 -1
- package/src/capacity-ledger.js +20 -6
package/package.json
CHANGED
package/src/capacity-ledger.js
CHANGED
|
@@ -409,17 +409,31 @@ export class CapacityLedger {
|
|
|
409
409
|
tankStats(name, window) {
|
|
410
410
|
const rec = this._accounts.get(name);
|
|
411
411
|
const floor = (this._readFloorOverride ?? READ_FLOOR_MS)[window] ?? 0;
|
|
412
|
-
const
|
|
413
|
-
c.complete && !c.disabledDuring
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
412
|
+
const closed = (rec?.[window]?.closed || []).filter(c =>
|
|
413
|
+
c.complete && !c.disabledDuring && (c.endedAt - c.startedAt) >= floor - 1_000);
|
|
414
|
+
// PHYSICAL FLOOR: a tank can never be smaller than the most tokens ever
|
|
415
|
+
// delivered in one complete window — every token we count is a vendor token
|
|
416
|
+
// (C ≤ V ≤ tank), so maxDelivered ≤ tank is an invariant, not a heuristic.
|
|
417
|
+
// A reading implying a smaller tank is contaminated: the vendor % counted
|
|
418
|
+
// spend maxpool never saw (usage outside the proxy — an account also used
|
|
419
|
+
// directly), or the reading was stale. Measured live 2026-08-26: a window
|
|
420
|
+
// that delivered 497k at a reported "95% full" implied a 523k tank while an
|
|
421
|
+
// earlier window of the SAME account had delivered 1.53M — impossible, and
|
|
422
|
+
// the understated reading silently dragged the average down 3.6x.
|
|
423
|
+
// CLAMP, never discard: the contaminated reading is still a real lower bound
|
|
424
|
+
// (the tank is at least the tokens we saw), so it joins the average AT the
|
|
425
|
+
// floor rather than being thrown away — discarding left an account whose
|
|
426
|
+
// every reading was contaminated with NOTHING to show. After a plan
|
|
427
|
+
// downgrade the floor over-states until old cycles age out — conservative.
|
|
428
|
+
const maxDelivered = closed.reduce((m, c) => Math.max(m, c.tokens), 0);
|
|
429
|
+
const usable = closed.filter(c =>
|
|
430
|
+
Number.isFinite(c.finalUtilization) && c.finalUtilization >= TANK_MIN_UTIL);
|
|
417
431
|
if (!usable.length) return null;
|
|
418
432
|
let sum = 0, exact = 0, bounded = 0;
|
|
419
433
|
for (const c of usable) {
|
|
420
434
|
const observedFromStart = c.startedAt != null && c.windowStartedAt != null
|
|
421
435
|
&& c.startedAt <= c.windowStartedAt + 60_000;
|
|
422
|
-
sum += c.tokens / c.finalUtilization;
|
|
436
|
+
sum += Math.max(c.tokens / c.finalUtilization, maxDelivered);
|
|
423
437
|
if (observedFromStart) exact++; else bounded++;
|
|
424
438
|
}
|
|
425
439
|
const last = usable[usable.length - 1];
|