maxpool 1.24.16 → 1.24.18

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.16",
3
+ "version": "1.24.18",
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/server.js CHANGED
@@ -163,7 +163,14 @@ export function createProxyServer(accountManager, config, hooks = {}) {
163
163
  // upstream-bound request headers elsewhere.
164
164
  const workerStamp = String(process.pid);
165
165
 
166
- const server = http.createServer(async (req, res) => {
166
+ // REQUEST-ARRIVAL TIMEOUTS (2026-10-11 outage). Node's defaults (300s request
167
+ // timeout, 30s checking interval) are what fired live — but they must be in the
168
+ // constructor to be settable at all (property assignment after listen is a no-op
169
+ // in Node 20, measured), so they are read here, env-tunable, never mutated later.
170
+ const server = http.createServer({
171
+ requestTimeout: Math.max(1_000, Number(process.env.MAXPOOL_REQUEST_TIMEOUT_MS) || 300_000),
172
+ connectionsCheckingInterval: Math.max(100, Number(process.env.MAXPOOL_CONNECTIONS_CHECK_MS) || 30_000),
173
+ }, async (req, res) => {
167
174
  try {
168
175
  // Disable Nagle on the client socket: flush each SSE event immediately instead
169
176
  // of coalescing small writes into bursts. Smooths streaming cadence toward the
@@ -343,6 +350,28 @@ export function createProxyServer(accountManager, config, hooks = {}) {
343
350
  // this releasing worker.
344
351
  server.maxpoolBeginDrain = () => { draining = true; };
345
352
 
353
+ // STALLED-UPLOAD ANSWER (2026-10-11 outage). When a request body never finishes
354
+ // arriving, Node's requestTimeout fires and its default handler writes a BODY-LESS
355
+ // `408 Request Timeout`, which Claude Code surfaces as the opaque "API Error: 408
356
+ // status code (no body)" (1,711 of them overnight, while the Mac's network stack
357
+ // was starved). Answer with the standard Anthropic error envelope instead, naming
358
+ // the actual cause, so the user sees a real message and the CLI treats it like any
359
+ // other retryable API error. Every other client error keeps Node's own handling.
360
+ server.on('clientError', (err, socket) => {
361
+ if (err?.code === 'ERR_HTTP_REQUEST_TIMEOUT' && socket.writable && !socket._httpMessage?.headersSent) {
362
+ const body = JSON.stringify({
363
+ type: 'error',
364
+ error: {
365
+ type: 'request_timeout',
366
+ message: 'Maxpool did not receive the full request in time (the upload stalled — usually a network problem on this machine). Retrying should work once the network recovers.',
367
+ },
368
+ });
369
+ socket.end(`HTTP/1.1 408 Request Timeout\r\nContent-Type: application/json\r\nContent-Length: ${Buffer.byteLength(body)}\r\nConnection: close\r\n\r\n${body}`);
370
+ return;
371
+ }
372
+ socket.destroy(err);
373
+ });
374
+
346
375
  return server;
347
376
  }
348
377
 
@@ -3015,9 +3044,29 @@ function prepareRuntimeProviders(accountManager, headers) {
3015
3044
  .filter(a => a.configSourced && a.credential)
3016
3045
  .map(a => a.credential),
3017
3046
  );
3047
+ // THE PROXY OWNS THE KEYS (2026-10-10). When config already manages accounts of a
3048
+ // provider kind, a session-supplied key for that kind is ignored outright. Dedup by
3049
+ // token alone was not enough: a session launched before a key rotation keeps sending
3050
+ // the OLD key for its whole life, and it surfaced as a duplicate "glm-fallback"
3051
+ // account for the same z.ai login (1,578 requests on the old key in 2 days).
3052
+ // A kind counts as proxy-managed only while at least one of its config accounts
3053
+ // HOLDS a key: if every one is unresolved (the secret-unresolved outages of
3054
+ // 2026-10-05/08) the session key still stands in as the safety net.
3055
+ const configKinds = new Set(
3056
+ (accountManager.accounts || []).filter(a => a.configSourced && a.credential).map(a => a.provider),
3057
+ );
3058
+ // Self-clean: a fallback created before the config keys loaded (or restored from
3059
+ // state) is dropped as soon as it is idle — no restart, no waiting for old sessions.
3060
+ // (removeAccount itself refuses an account with a request in flight.)
3061
+ for (const a of [...(accountManager.accounts || [])]) {
3062
+ if (a.runtime && !a.configSourced && a.type === 'provider' && configKinds.has(a.provider)
3063
+ && accountManager.removeAccount(accountManager.accounts.indexOf(a))) {
3064
+ console.log(`[Maxpool] Dropped session-supplied "${a.name}" — ${a.provider} keys are managed by the pool config`);
3065
+ }
3066
+ }
3018
3067
 
3019
3068
  const zaiToken = headerValue(headers, 'x-maxpool-zai-token');
3020
- if (zaiToken && !configTokens.has(zaiToken)) {
3069
+ if (zaiToken && !configKinds.has('zai') && !configTokens.has(zaiToken)) {
3021
3070
  const opus = headerValue(headers, 'x-maxpool-zai-opus-model') || headerValue(headers, 'x-maxpool-zai-model') || 'glm-5.3';
3022
3071
  const sonnet = headerValue(headers, 'x-maxpool-zai-sonnet-model') || headerValue(headers, 'x-maxpool-zai-model') || opus;
3023
3072
  const haiku = headerValue(headers, 'x-maxpool-zai-haiku-model') || 'glm-5.3';
@@ -3036,7 +3085,7 @@ function prepareRuntimeProviders(accountManager, headers) {
3036
3085
  }
3037
3086
 
3038
3087
  const kimiToken = headerValue(headers, 'x-maxpool-kimi-token');
3039
- if (kimiToken && !configTokens.has(kimiToken)) {
3088
+ if (kimiToken && !configKinds.has('kimi') && !configTokens.has(kimiToken)) {
3040
3089
  // Fallback only — `cc all` always sends x-maxpool-kimi-model from the llm_config SSOT,
3041
3090
  // so this is what a bare/older client gets. Kept current deliberately: it read
3042
3091
  // 'kimi-k2.7' while the fleet had moved to k3.
@@ -3652,3 +3701,6 @@ function computeRetryAfter(accountManager, requestInfo = {}) {
3652
3701
  const ms = accountManager.nextRetryForRequest?.(requestInfo, new Set())?.retryAfterMs ?? Infinity;
3653
3702
  return ms === Infinity ? 60 : Math.max(1, Math.ceil(ms / 1000));
3654
3703
  }
3704
+
3705
+ // Test seam: prepareRuntimeProviders with a plain headers object.
3706
+ export const __test = { prepareRuntimeProviders };