maxpool 1.24.30 → 1.24.32

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.24.30",
3
+ "version": "1.24.32",
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",
@@ -34,6 +34,13 @@
34
34
  * R5 PACE — at most ONE redeem per account per evaluation. The caller invokes the
35
35
  * policy each poll cycle; the deterministic z.ai requestId makes an accidental
36
36
  * double-fire harmless, but the policy still returns a single action.
37
+ *
38
+ * R6 WAIT FOR THE FREE REFILL (owner, 2026-10-23) — a wall redeem (R1) burns a card
39
+ * that z.ai's free weekly refill is about to make redundant: when the refill
40
+ * lands <24h away and weekly util < 0.98, HOLD the card. At >= 0.98 redeem
41
+ * immediately — the owner is never blocked waiting for a free refill that is
42
+ * merely hours away. Dying-value redeems (R2) are exempt: an expiring card's
43
+ * value cannot survive a wait.
37
44
  */
38
45
  export const POLICY = {
39
46
  wallWeekly: 0.90, // weekly at 90% = at the wall
@@ -41,6 +48,8 @@ export const POLICY = {
41
48
  dyingWindowMs: 24 * 3600 * 1000, // redeem-don't-save horizon
42
49
  dyingMinUtilWeekly: 0.30, // below this a dying weekly refill buys too little
43
50
  dyingMinUtilSes: 0.50, // 5h refills are cheap capacity; demand more waste first
51
+ freeRefillWaitMs: 24 * 3600 * 1000, // R6: hold a wall redeem this close to the free refill
52
+ freeRefillImmediate: 0.98, // R6: ...unless this full — never block the owner
44
53
  };
45
54
 
46
55
  function msLeft(t, now) { return t == null ? Infinity : t - now; }
@@ -62,6 +71,7 @@ export function decideZai(account, cards, now = Date.now()) {
62
71
 
63
72
  const weeklyCard = weeklyCards[0] || null;
64
73
  const sesCard = sesCards[0] || null;
74
+ let weeklyHeld = false; // R6: weekly card HELD for the free refill (5h branch may still fire)
65
75
 
66
76
  // --- weekly card: clears BOTH windows (z.ai docs; measured: glm1 100%->0% both)
67
77
  if (weeklyCard) {
@@ -70,15 +80,26 @@ export function decideZai(account, cards, now = Date.now()) {
70
80
  const dying = msLeft(weeklyCard.expiresAt, now) < POLICY.dyingWindowMs
71
81
  && worst >= POLICY.dyingMinUtilWeekly;
72
82
  if (atWall || dying) {
73
- return { kind: 'card', card: weeklyCard, resetType: 'WEEK',
74
- reason: atWall ? 'weekly at wall' : 'dying value' };
83
+ // R6: a wall redeem waits when the FREE weekly refill is imminent and the
84
+ // account isn't critically full (dying-value redeems stay exempt above).
85
+ // A HELD weekly card is spendable-redundant, not absent: the 5h branch below
86
+ // may still fire (red-team: holding must not starve a 5h wall — the 5h card
87
+ // sits redundant behind the free refill anyway, so spending it is pure gain).
88
+ if (atWall && !dying && q.providerWkReset != null
89
+ && msLeft(q.providerWkReset, now) < POLICY.freeRefillWaitMs
90
+ && wkUtil < POLICY.freeRefillImmediate) {
91
+ weeklyHeld = true; // fall through — do NOT return; the 5h branch checks this
92
+ } else {
93
+ return { kind: 'card', card: weeklyCard, resetType: 'WEEK',
94
+ reason: atWall ? 'weekly at wall' : 'dying value' };
95
+ }
75
96
  }
76
97
  }
77
98
 
78
99
  // --- 5h card: clears only the session window
79
100
  if (sesCard) {
80
101
  const atWall = sesUtil != null && sesUtil >= POLICY.wallSes
81
- && (weeklyCard == null); // R4: a weekly card can do this job AND more
102
+ && (weeklyCard == null || weeklyHeld); // R4: a weekly card can do this job AND more — except when R6 HELD it for the free refill
82
103
  const dying = msLeft(sesCard.expiresAt, now) < POLICY.dyingWindowMs
83
104
  && (sesUtil ?? 0) >= POLICY.dyingMinUtilSes;
84
105
  if (atWall || dying) {