maxpool 1.8.4 → 1.8.6

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.8.4",
3
+ "version": "1.8.6",
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",
@@ -3066,7 +3066,13 @@ export class AccountManager {
3066
3066
  // window (>=5h) — the 60s epsilon separates it by three orders of magnitude.
3067
3067
  // Provider stamps (z.ai/Kimi probe) are absolute and never jitter.
3068
3068
  const nowMs = Date.now();
3069
- const boundary = nextResetAt <= nowMs ? nowMs : nextResetAt;
3069
+ // A close can never be dated in the FUTURE. An advance stamp legitimately points
3070
+ // at the NEW window's reset (a fresh 5h away) — that is evidence the OLD window
3071
+ // rolled, not the moment it rolled. Close at NOW (live 2026-08-23: a 3,658-token
3072
+ // cycle was recorded as endedAt 4.9h in the future; the invariant checker caught
3073
+ // it minutes later). `min` also floors the late-probe case (a stamp already
3074
+ // expired) — endedAt is always within [start, now].
3075
+ const boundary = Math.min(nextResetAt, nowMs);
3070
3076
  if (boundary - prevResetAt < WINDOW_ADVANCE_EPSILON_MS) return;
3071
3077
  this.capacity.closeCycle(accountName, window, boundary, { resetAt: prevResetAt });
3072
3078
  }
@@ -34,6 +34,17 @@ const SAME_BOUNDARY_MS = 5_000;
34
34
  const MAX_CYCLES_PER_WINDOW = 50;
35
35
  const MAX_DAY_BUCKETS = 10;
36
36
 
37
+ // Demote a pre-v3 closed cycle: unverifiable (every one predates the joined-mid-window
38
+ // fix) AND untrustworthy in its timestamps (the v1.8.4 advance-close could date a row
39
+ // hours into the future — live: a row ending 19:54 while the clock read 15:02). Also
40
+ // CLAMPS a future endedAt to startedAt so the stored row itself stops violating
41
+ // invariants after migration, not just the averages.
42
+ function demote(c) {
43
+ const fixed = { ...c, complete: false, partialReason: 'pre-v3-unverified' };
44
+ if (fixed.endedAt > Date.now() + 60_000) fixed.endedAt = fixed.startedAt;
45
+ return fixed;
46
+ }
47
+
37
48
  export class CapacityLedger {
38
49
  constructor({ now = () => Date.now() } = {}) {
39
50
  this._now = now;
@@ -55,9 +66,9 @@ export class CapacityLedger {
55
66
  for (const [name, rec] of Object.entries(payload.accounts || {})) {
56
67
  migrated.accounts[name] = {
57
68
  ses: { open: rec.ses?.open || null,
58
- closed: (rec.ses?.closed || []).map(c => ({ ...c, complete: false, partialReason: 'pre-v3-unverified' })) },
69
+ closed: (rec.ses?.closed || []).map(c => demote(c)) },
59
70
  wk: { open: rec.wk?.open || null,
60
- closed: (rec.wk?.closed || []).map(c => ({ ...c, complete: false, partialReason: 'pre-v3-unverified' })) },
71
+ closed: (rec.wk?.closed || []).map(c => demote(c)) },
61
72
  days: rec.days || {},
62
73
  };
63
74
  }