maxpool 1.24.15 → 1.24.17

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.15",
3
+ "version": "1.24.17",
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",
@@ -4375,8 +4375,12 @@ export class AccountManager {
4375
4375
  const configTokens = new Set(
4376
4376
  entries.map(e => e.token).filter(Boolean),
4377
4377
  );
4378
+ // Same rule for a provider KIND config already covers: a header-derived fallback
4379
+ // of that kind is a duplicate login even when its token differs (a pre-rotation key).
4380
+ const configKinds = new Set(entries.filter(e => e.token).map(e => e.provider).filter(Boolean));
4378
4381
  for (const a of [...this.accounts]) {
4379
- if (!a.configSourced && a.type === 'provider' && a.credential && configTokens.has(a.credential)) {
4382
+ if (!a.configSourced && a.type === 'provider' && a.credential
4383
+ && (configTokens.has(a.credential) || (a.runtime && configKinds.has(a.provider)))) {
4380
4384
  const idx = this.accounts.indexOf(a);
4381
4385
  if (idx >= 0 && this.accounts[idx].inFlight === 0) this.removeAccount(idx);
4382
4386
  }
package/src/index.js CHANGED
@@ -777,6 +777,15 @@ async function serverWorkerCommand() {
777
777
  }, 5 * 60_000);
778
778
  secretTimer.unref?.();
779
779
  }
780
+ // Key rotation: a new secret version reaches the live pool within 30 min.
781
+ const { refreshRotatedProviders } = await import('./secret-resolver.js');
782
+ const rotateTimer = setInterval(async () => {
783
+ try {
784
+ const n = await refreshRotatedProviders(accountManager.accounts);
785
+ if (n) console.log(`[Maxpool] Key rotation: ${n} provider key(s) updated from Secret Manager`);
786
+ } catch { /* next tick */ }
787
+ }, 30 * 60_000);
788
+ rotateTimer.unref?.();
780
789
  }
781
790
 
782
791
  // Seed the running version immediately so the TUI header always shows it, even
@@ -199,6 +199,28 @@ export function pendingProviders(accounts) {
199
199
  return accounts.filter(a => a.configSourced && a.type === 'provider' && a.secretName && !a.credential);
200
200
  }
201
201
 
202
+ /**
203
+ * Pick up ROTATED keys. A key resolves once at startup, so a new secret version (a
204
+ * key swap in Secret Manager) stayed invisible until the next restart — the pool kept
205
+ * calling with the old key (2026-10-09: all six z.ai keys moved to the account's
206
+ * "zcode-api-key", which is the only key z.ai issues reset cards for). Re-reads every
207
+ * loaded provider's secret, bypassing the local cache, and swaps `credential` when the
208
+ * value changed. A failed read keeps the current key. Returns the number swapped.
209
+ */
210
+ export async function refreshRotatedProviders(accounts, resolve = (names) => resolveSecrets(names, { useCache: false })) {
211
+ const loaded = accounts.filter(a => a.configSourced && a.type === 'provider' && a.secretName && a.credential);
212
+ if (!loaded.length) return 0;
213
+ const resolved = await resolve([...new Set(loaded.map(a => a.secretName))]);
214
+ let swapped = 0;
215
+ for (const a of loaded) {
216
+ const tok = resolved[a.secretName];
217
+ if (!tok || tok === a.credential) continue;
218
+ a.credential = tok;
219
+ swapped++;
220
+ }
221
+ return swapped;
222
+ }
223
+
202
224
  export async function reresolveProviders(accounts, resolve = resolveSecrets) {
203
225
  const pending = pendingProviders(accounts);
204
226
  if (!pending.length) return 0;
package/src/server.js CHANGED
@@ -1709,7 +1709,7 @@ function formatRetryDuration(seconds) {
1709
1709
  function computeQueueWindowMs({
1710
1710
  cause, stream, retryPlanCause,
1711
1711
  maxWaitMs, capacityMaxWaitMs, nonStreamMaxWaitMs, streamHoldMaxMs, streamClientToleranceMs,
1712
- isCountTokens, countTokensMaxWaitMs, networkMaxWaitMs,
1712
+ isCountTokens, countTokensMaxWaitMs,
1713
1713
  }) {
1714
1714
  let windowMs;
1715
1715
  if (!stream) {
@@ -2649,9 +2649,6 @@ async function queueAndRetry(
2649
2649
  const streamClientToleranceMs = Number.isFinite(requestInfo.clientToleranceMs)
2650
2650
  ? requestInfo.clientToleranceMs
2651
2651
  : Math.max(0, Number(queueConfig.streamClientToleranceMs) || 0);
2652
- const networkMaxWaitMs = queueConfig.networkMaxWaitMs == null
2653
- ? 2 * 60 * 1000
2654
- : Math.max(0, Number(queueConfig.networkMaxWaitMs) || 0);
2655
2652
  const queueWindowMs = computeQueueWindowMs({
2656
2653
  cause,
2657
2654
  stream: Boolean(requestInfo.stream),
@@ -2659,7 +2656,6 @@ async function queueAndRetry(
2659
2656
  maxWaitMs,
2660
2657
  capacityMaxWaitMs,
2661
2658
  nonStreamMaxWaitMs,
2662
- networkMaxWaitMs,
2663
2659
  streamHoldMaxMs,
2664
2660
  streamClientToleranceMs,
2665
2661
  isCountTokens: Boolean(requestInfo.isCountTokens),
@@ -3019,9 +3015,29 @@ function prepareRuntimeProviders(accountManager, headers) {
3019
3015
  .filter(a => a.configSourced && a.credential)
3020
3016
  .map(a => a.credential),
3021
3017
  );
3018
+ // THE PROXY OWNS THE KEYS (2026-10-10). When config already manages accounts of a
3019
+ // provider kind, a session-supplied key for that kind is ignored outright. Dedup by
3020
+ // token alone was not enough: a session launched before a key rotation keeps sending
3021
+ // the OLD key for its whole life, and it surfaced as a duplicate "glm-fallback"
3022
+ // account for the same z.ai login (1,578 requests on the old key in 2 days).
3023
+ // A kind counts as proxy-managed only while at least one of its config accounts
3024
+ // HOLDS a key: if every one is unresolved (the secret-unresolved outages of
3025
+ // 2026-10-05/08) the session key still stands in as the safety net.
3026
+ const configKinds = new Set(
3027
+ (accountManager.accounts || []).filter(a => a.configSourced && a.credential).map(a => a.provider),
3028
+ );
3029
+ // Self-clean: a fallback created before the config keys loaded (or restored from
3030
+ // state) is dropped as soon as it is idle — no restart, no waiting for old sessions.
3031
+ // (removeAccount itself refuses an account with a request in flight.)
3032
+ for (const a of [...(accountManager.accounts || [])]) {
3033
+ if (a.runtime && !a.configSourced && a.type === 'provider' && configKinds.has(a.provider)
3034
+ && accountManager.removeAccount(accountManager.accounts.indexOf(a))) {
3035
+ console.log(`[Maxpool] Dropped session-supplied "${a.name}" — ${a.provider} keys are managed by the pool config`);
3036
+ }
3037
+ }
3022
3038
 
3023
3039
  const zaiToken = headerValue(headers, 'x-maxpool-zai-token');
3024
- if (zaiToken && !configTokens.has(zaiToken)) {
3040
+ if (zaiToken && !configKinds.has('zai') && !configTokens.has(zaiToken)) {
3025
3041
  const opus = headerValue(headers, 'x-maxpool-zai-opus-model') || headerValue(headers, 'x-maxpool-zai-model') || 'glm-5.3';
3026
3042
  const sonnet = headerValue(headers, 'x-maxpool-zai-sonnet-model') || headerValue(headers, 'x-maxpool-zai-model') || opus;
3027
3043
  const haiku = headerValue(headers, 'x-maxpool-zai-haiku-model') || 'glm-5.3';
@@ -3040,7 +3056,7 @@ function prepareRuntimeProviders(accountManager, headers) {
3040
3056
  }
3041
3057
 
3042
3058
  const kimiToken = headerValue(headers, 'x-maxpool-kimi-token');
3043
- if (kimiToken && !configTokens.has(kimiToken)) {
3059
+ if (kimiToken && !configKinds.has('kimi') && !configTokens.has(kimiToken)) {
3044
3060
  // Fallback only — `cc all` always sends x-maxpool-kimi-model from the llm_config SSOT,
3045
3061
  // so this is what a bare/older client gets. Kept current deliberately: it read
3046
3062
  // 'kimi-k2.7' while the fleet had moved to k3.
@@ -3656,3 +3672,6 @@ function computeRetryAfter(accountManager, requestInfo = {}) {
3656
3672
  const ms = accountManager.nextRetryForRequest?.(requestInfo, new Set())?.retryAfterMs ?? Infinity;
3657
3673
  return ms === Infinity ? 60 : Math.max(1, Math.ceil(ms / 1000));
3658
3674
  }
3675
+
3676
+ // Test seam: prepareRuntimeProviders with a plain headers object.
3677
+ export const __test = { prepareRuntimeProviders };