maxpool 1.24.54 → 1.24.56

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.54",
3
+ "version": "1.24.56",
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",
@@ -3437,12 +3437,23 @@ export class AccountManager {
3437
3437
  if (account.type === 'provider') {
3438
3438
  const sesUsed = q.providerSes != null ? clamp01(q.providerSes) : null;
3439
3439
  const wkUsed = q.providerWk != null ? clamp01(q.providerWk) : null;
3440
- const used = Math.max(sesUsed ?? 0, wkUsed ?? 0);
3440
+ // The WEEKLY ladder tiers on the weekly window ALONE when the plan HAS one
3441
+ // (owner 2026-10-30: GLM serves to 100% of the session window; the old
3442
+ // Math.max(ses, wk) demoted a 97%-session / 20%-weekly key to 'critical' —
3443
+ // last-resort behind every Claude account with four-fifths of its weekly
3444
+ // window empty — council review 2026-10-31). A weeklyAbsent plan (providerWk
3445
+ // null: z.ai unlimited-weekly) keeps its historical ses-driven tiering — the
3446
+ // session window is its ONLY quota signal. Session availability otherwise
3447
+ // belongs to _isSessionQuotaUnavailable + PROVIDER_SES_WALL.
3448
+ const used = wkUsed != null ? wkUsed : (sesUsed ?? 0);
3441
3449
  // USAGE CAP — checked FIRST, before every tier: a reservation is owner intent
3442
3450
  // and outranks both the tier ladder and the upstream verdict. There is no
3443
3451
  // upstreamAllows carve-out for providers anyway, but the ordering documents
3444
- // that a cap can never be talked out of by the vendor's "allowed".
3445
- if (this._capped(account, used, 'wk', now)) return 'capped';
3452
+ // that a cap can never be talked out of by the vendor's "allowed". The cap
3453
+ // reads the WORST window (max of ses/wk): a z.ai cap bounds total spend, and
3454
+ // the 5h reading is real consumption against it.
3455
+ const capUsed = Math.max(sesUsed ?? 0, wkUsed ?? 0);
3456
+ if (this._capped(account, capUsed, 'wk', now)) return 'capped';
3446
3457
  if (used >= this.scheduler.weeklyExhaustedThreshold) return 'exhausted';
3447
3458
  if (used >= this.scheduler.weeklyCriticalThreshold) return 'critical';
3448
3459
  if (used >= this.scheduler.weeklyReserveThreshold) return 'reserve';
@@ -4774,6 +4785,13 @@ export class AccountManager {
4774
4785
  this.applyPoolLinks();
4775
4786
  }
4776
4787
 
4788
+ /** When these identities were last CONFIRMED by a good poll (a seed keeps its own
4789
+ * age, so the expiry in seedPoolIdentities can actually fire in a long outage). */
4790
+ poolIdentitiesAt() {
4791
+ const times = this.poolLinks.map(l => l.lastOkAt ?? l._seedAt ?? 0);
4792
+ return times.length ? Math.max(...times) : null;
4793
+ }
4794
+
4777
4795
  /** Per-link identity maps for state.json (keyed by link name). */
4778
4796
  exportPoolIdentities() {
4779
4797
  const out = {};
@@ -4804,9 +4822,15 @@ export class AccountManager {
4804
4822
  const remoteRow = (this.poolLinks || [])
4805
4823
  .flatMap(l => (l.status?.accounts || []).filter(r => r.name === d.remoteName))[0];
4806
4824
  if (remoteRow?.refreshDead && !a.refreshDead && a.refreshToken) {
4807
- const msg = `[Maxpool] Token divergence: team pool's "${d.remoteName}" is refreshDead but local "${a.name}" holds a live token — run /login on the local row to re-auth the team pool (one keystroke), or the account stays dark on both sides`;
4808
- console.log(msg);
4809
- appendEventLog(msg);
4825
+ // Once per episode: this runs on every 30s poll.
4826
+ if (!a._divergenceLogged) {
4827
+ a._divergenceLogged = true;
4828
+ const msg = `[Maxpool] Token divergence: team pool's "${d.remoteName}" needs login while local "${a.name}" still has a stored token — log in again on that row, or the account stays unavailable on both sides`;
4829
+ console.log(msg);
4830
+ appendEventLog(msg);
4831
+ }
4832
+ } else {
4833
+ a._divergenceLogged = false;
4810
4834
  }
4811
4835
  }
4812
4836
  a.poolBenchedBy = d ? (d.remoteName || 'team pool') : null;
package/src/index.js CHANGED
@@ -648,12 +648,6 @@ async function serverWorkerCommand() {
648
648
  // final flush and restores fully (the reported zero-request case).
649
649
  if (savedState?.runtimeProviders) accountManager.restoreRuntimeProviders(savedState.runtimeProviders);
650
650
  if (savedState?.callerStats) accountManager.restoreCallerStats?.(savedState.callerStats);
651
- // Boot-time single-writer guard: seed each link's identity map from the last
652
- // persisted run so a boot during a link outage doesn't un-bench local copies
653
- // (red-team 2026-10-31). Replaced by the first successful poll.
654
- if (savedState?.poolIdentities) {
655
- accountManager.seedPoolLinks?.(savedState.poolIdentities, savedState.poolIdentitiesAt);
656
- }
657
651
 
658
652
  // ── config-sourced providers (GCP Secret Manager) ──────────────────────────
659
653
  // Provider keys (GLM, Kimi) defined in the config's `providers` section, each
@@ -709,6 +703,10 @@ async function serverWorkerCommand() {
709
703
  // as its own row (syncRemoteMirrors on every link poll) and balanced with the
710
704
  // local accounts by the unchanged routing logic.
711
705
  accountManager.setPoolLinks(links);
706
+ // Boot-time single-writer guard: seed from the last persisted run in the SAME
707
+ // tick as setPoolLinks, before the first poll or probe can run. Links must exist
708
+ // first (a seed above this point looped over an empty list and did nothing).
709
+ accountManager.seedPoolLinks(savedState?.poolIdentities, savedState?.poolIdentitiesAt);
712
710
  const armed = links.filter(l => l.key).length;
713
711
  console.log(`[Maxpool] Team pools: ${armed} linked${links.length - armed ? `, ${links.length - armed} unresolved key` : ''}`);
714
712
  } catch (err) {
@@ -756,7 +754,7 @@ async function serverWorkerCommand() {
756
754
  // Last-good remote identity maps — the boot-time single-writer guard reads
757
755
  // these (see restore above). Rides the same generation-guarded payload.
758
756
  poolIdentities: accountManager.exportPoolIdentities?.() || null,
759
- poolIdentitiesAt: Date.now(),
757
+ poolIdentitiesAt: accountManager.poolIdentitiesAt?.() ?? null,
760
758
  },
761
759
  { expectedGeneration },
762
760
  )
package/src/pool-link.js CHANGED
@@ -149,10 +149,13 @@ function sanitizeRemoteStatus(json) {
149
149
  for (const a of Array.isArray(p.accounts) ? p.accounts : []) if (a && typeof a === 'object') a.name = safeText(a.name);
150
150
  }
151
151
  }
152
- if (json.callers && typeof json.callers === 'object') {
153
- const clean = {};
154
- for (const [k, v] of Object.entries(json.callers)) clean[safeText(k)] = v;
155
- json.callers = clean;
152
+ // Person names key both maps; the People page reads callerWindows.
153
+ for (const field of ['callers', 'callerWindows']) {
154
+ if (json[field] && typeof json[field] === 'object') {
155
+ const clean = {};
156
+ for (const [k, v] of Object.entries(json[field])) clean[safeText(k)] = v;
157
+ json[field] = clean;
158
+ }
156
159
  }
157
160
  return json;
158
161
  }
@@ -196,7 +199,7 @@ export class PoolLink {
196
199
  const m = new Map(Object.entries(saved).map(([k, v]) => [k, v]));
197
200
  if (m.size > 0) {
198
201
  this.identities = m;
199
- this._bootSeeded = true;
202
+ this._seedAt = savedAt ?? null;
200
203
  }
201
204
  }
202
205
 
package/src/server.js CHANGED
@@ -358,10 +358,17 @@ export function createProxyServer(accountManager, config, hooks = {}) {
358
358
  });
359
359
  // Keep the in-memory config mirror in step so a later TUI saveConfig
360
360
  // can't clobber the fresh tokens with stale ones.
361
- const mem = config.accounts.find(a => a.accountUuid === acct.accountUuid);
361
+ const mem = (config.accounts || []).find(a => a.accountUuid === acct.accountUuid);
362
362
  if (mem) Object.assign(mem, tokenFields);
363
363
  } catch (err) {
364
+ // A single-use credential write is only "ok" when it is DURABLE: the browser
365
+ // login may have invalidated the previous refresh token, so memory-only means
366
+ // a restart bricks the account while both sides recorded success (council
367
+ // review 2026-10-31). Tell the caller to retry instead of claiming Done.
364
368
  console.error(`[Maxpool] Remote inject persisted to memory but NOT disk for uuid ${acct.accountUuid.slice(0, 8)}: ${err?.message || err}`);
369
+ res.writeHead(507, { 'Content-Type': 'application/json' });
370
+ res.end(JSON.stringify({ ok: false, error: 'not_persisted', message: 'Saved in memory only — the pool could not write it to disk. Log in again.' }));
371
+ return;
365
372
  }
366
373
  res.writeHead(200, { 'Content-Type': 'application/json' });
367
374
  res.end(JSON.stringify({ ok: true, result: amAcct ? 'reauthed' : 'added', name: amAcct ? amAcct.name : (acct.name || acct.accountUuid.slice(0, 8)) }));
@@ -477,6 +484,12 @@ export function createProxyServer(accountManager, config, hooks = {}) {
477
484
  // caller can't steer routing. Applied by selection as an exclusive filter.
478
485
  const pin = headerValue(req.headers, 'x-maxpool-pin-account');
479
486
  if (pin && req.callerName && req.callerName !== 'legacy-key') requestInfo.pinAccount = String(pin);
487
+ else if (pin) {
488
+ // A pin from a legacy-key link is silently dropped — the local pool has
489
+ // already made mirror-specific decisions on it. Name the misconfiguration
490
+ // once instead (council review 2026-10-31: no warning fired anywhere).
491
+ console.error('[Maxpool] x-maxpool-pin-account dropped: the link authenticated with the remote\'s legacy apiKey — mint a named client key (proxy.clients) so pins and per-person attribution work');
492
+ }
480
493
  requestInfo.sessionKey = headerValue(req.headers, 'x-maxpool-session');
481
494
  requestInfo.caller = req._caller || null;
482
495
  // The CLIENT tells us how long it will wait — the only source that is actually