maxpool 1.13.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxpool",
3
- "version": "1.13.0",
3
+ "version": "1.13.2",
4
4
  "description": "Multi-account Claude Code proxy with adaptive, rate-aware load balancing across Claude accounts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,5 +1,5 @@
1
1
  import { refreshAccessToken, isTokenExpiringSoon, modelFamily, tokenFingerprint } from './oauth.js';
2
- import { CapacityLedger } from './capacity-ledger.js';
2
+ import { CapacityLedger, TANK_MIN_UTIL } from './capacity-ledger.js';
3
3
 
4
4
  // Nominal window length per kind — mirrors capacity-ledger's WINDOW_MS (kept here as a
5
5
  // local table so account-manager does not import a private constant).
@@ -3299,6 +3299,10 @@ export class AccountManager {
3299
3299
  if (measured) return { ...measured, source: 'cycles' };
3300
3300
  const est = this.capacityEstimate(accountIndex, window);
3301
3301
  if (!est) return null;
3302
+ // Same rounding-noise guard as tankStats: a 1%-full window divides by vendor
3303
+ // whole-percent rounding and can read absurd (measured live: 455k ÷ 1% = "≥45M").
3304
+ // Below the floor the reading is noise — withhold rather than print a fiction.
3305
+ if (est.utilization < TANK_MIN_UTIL) return null;
3302
3306
  return {
3303
3307
  avg: est.tokens, last: est.tokens, n: 0, exact: est.lowerBound ? 0 : 1,
3304
3308
  bounded: est.lowerBound ? 1 : 0, lowerBound: Boolean(est.lowerBound),
@@ -35,6 +35,14 @@ const SAME_BOUNDARY_MS = 5_000;
35
35
  // The minimum span of a COMPLETE cycle per window (80% of nominal): a real one is
36
36
  // flagged partial by the writer, so a complete cycle below this is corrupt history.
37
37
  const READ_FLOOR_MS = { ses: 4 * 3600_000, wk: 5 * 86400_000 };
38
+
39
+ // TANK floor. tank = tokens ÷ utilization, and vendors report WHOLE percents — so at
40
+ // 1% full, one percentage point of rounding swings the answer by 100% (measured live
41
+ // 2026-08-25: a 1%-full window read "≥45M"). Below this the reading is rounding noise,
42
+ // not a measurement. Exported because BOTH the closed-cycle average and the live
43
+ // in-window estimate must apply the same floor; one guarding without the other is how
44
+ // the absurd number reached the screen in the first place.
45
+ export const TANK_MIN_UTIL = 0.05;
38
46
  const MAX_CYCLES_PER_WINDOW = 50;
39
47
  const MAX_DAY_BUCKETS = 10;
40
48
 
@@ -401,17 +409,31 @@ export class CapacityLedger {
401
409
  tankStats(name, window) {
402
410
  const rec = this._accounts.get(name);
403
411
  const floor = (this._readFloorOverride ?? READ_FLOOR_MS)[window] ?? 0;
404
- const usable = (rec?.[window]?.closed || []).filter(c =>
405
- c.complete && !c.disabledDuring
406
- && Number.isFinite(c.finalUtilization)
407
- && c.finalUtilization >= 0.05
408
- && (c.endedAt - c.startedAt) >= floor - 1_000);
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);
409
431
  if (!usable.length) return null;
410
432
  let sum = 0, exact = 0, bounded = 0;
411
433
  for (const c of usable) {
412
434
  const observedFromStart = c.startedAt != null && c.windowStartedAt != null
413
435
  && c.startedAt <= c.windowStartedAt + 60_000;
414
- sum += c.tokens / c.finalUtilization;
436
+ sum += Math.max(c.tokens / c.finalUtilization, maxDelivered);
415
437
  if (observedFromStart) exact++; else bounded++;
416
438
  }
417
439
  const last = usable[usable.length - 1];
package/src/tui.js CHANGED
@@ -2089,13 +2089,14 @@ export class TUI {
2089
2089
  continue;
2090
2090
  }
2091
2091
  const st = ledger.windowStats(a.name, win);
2092
- let tank = this.am.capacityTank?.(i, win);
2092
+ const tank = this.am.capacityTank?.(i, win);
2093
2093
  const nowOpen = ledger.openCycle(a.name, win);
2094
2094
  const util = this.am._windowUtilization?.(a, win);
2095
- // A reading we cannot prove is from THIS window must not badge the capacity
2096
- // number as "live" — it may describe the previous window entirely (the estimate
2097
- // still renders; the basis line just stops claiming freshness it can't prove).
2098
- if (tank?.source === 'live' && tank.fresh === false) tank = null;
2095
+ // A reading we cannot prove is from THIS window may describe the previous one —
2096
+ // the basis line says "unproven" instead of "live", but the number still renders:
2097
+ // a restored reading after a restart is real data, and suppressing it would blank
2098
+ // the page at exactly the moment the user opens it.
2099
+ const unproven = tank?.source === 'live' && tank.fresh === false;
2099
2100
 
2100
2101
  // A row with NEITHER a tank nor any delivery has genuinely nothing to say. Say
2101
2102
  // WHY in the account's own terms — "no completed cycle yet" was true and useless
@@ -2131,7 +2132,7 @@ export class TUI {
2131
2132
  const basis = !tank ? dim('no capacity reading yet')
2132
2133
  : tank.source === 'cycles'
2133
2134
  ? dim(`${tank.n} full ${tank.n === 1 ? 'window' : 'windows'}`)
2134
- : dim(`live · ${((tank.utilization ?? 0) * 100).toFixed(0)}% used`);
2135
+ : dim(`${unproven ? 'from an older reading' : 'live'} · ${((tank.utilization ?? 0) * 100).toFixed(0)}% used`);
2135
2136
  const pct = util != null && tank?.source !== 'live' ? dim(` (${(util * 100).toFixed(0)}% full now)`) : '';
2136
2137
  out.push(' ' + name + ' ' + prov + ' ' + cyan(cells) + ' ' + basis + pct);
2137
2138
  }