maxpool 1.24.19 → 1.24.21

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.js +36 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxpool",
3
- "version": "1.24.19",
3
+ "version": "1.24.21",
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",
package/src/server.js CHANGED
@@ -507,7 +507,19 @@ async function forwardRequest(
507
507
  ctx.account = '(none available)';
508
508
  const retryPlan = accountManager.nextRetryForRequest?.(requestInfo, new Set()) || {};
509
509
  const willRecoverSoon = Number.isFinite(retryPlan.retryAfterMs);
510
- const retryAfter = willRecoverSoon ? Math.max(1, Math.ceil(retryPlan.retryAfterMs / 1000)) : 60;
510
+ // CLI-RETRIABLE CAP (2026-10-11 "bricked sessions"). The real soonest reset can
511
+ // be hours out; sending `retry-after: 10800` makes Claude Code's SDK treat the
512
+ // 429 as terminal (binary-verified 2.1.296: a plain rate_limit 429 whose
513
+ // retry-after exceeds 60s + 25% headroom aborts with tengu_api_retry_after_too_long
514
+ // — it neither sleeps nor retries; the turn dies and the session looks dead).
515
+ // The pool has ALREADY decided not to hold this request, so the honest and
516
+ // useful header is "retry soon": every SDK retries ≤60s values with backoff,
517
+ // and the pool answers again immediately with a fresh estimate. The body text
518
+ // still carries the real wait.
519
+ const RETRY_AFTER_RETRIABLE_S = 60;
520
+ const retryAfter = willRecoverSoon
521
+ ? Math.min(Math.max(1, Math.ceil(retryPlan.retryAfterMs / 1000)), RETRY_AFTER_RETRIABLE_S)
522
+ : 60;
511
523
  // Surface the routing decision (logs go to the TUI; this is the only record
512
524
  // of WHY a request was rejected rather than queued).
513
525
  console.log(`[Maxpool] No route for request — returning 429 (cause: ${retryPlan.cause || 'unavailable'}, recovers-soon: ${willRecoverSoon})`);
@@ -2702,7 +2714,25 @@ async function queueAndRetry(
2702
2714
  // (all accounts logged out, the only healthy account removed, etc.).
2703
2715
  const retryAfterMs = retryPlan.retryAfterMs;
2704
2716
  if (!Number.isFinite(retryAfterMs) || retryAfterMs > queueWindowMs) {
2705
- return finishQueuedStreamIfNeeded(res, requestInfo, honestMessage);
2717
+ // FINITE-but-BEYOND-WINDOW (2026-10-12, "they should have just waited"): a
2718
+ // STREAMING request with a known reset 1h out used to instant-429 here for the
2719
+ // whole wait (measured 75 min, 08:13–09:34Z) while sessions burned their CLI
2720
+ // retry budgets and some died entirely. Hold the stream for the window with
2721
+ // the heartbeat keeping the client alive, then end with the retriable error —
2722
+ // the client re-enters and the hold chains window-by-window until the reset
2723
+ // lands. Non-streaming requests keep the fast error (no heartbeat = the hold
2724
+ // would die on the client's idle timeout anyway).
2725
+ // Capacity-class causes (concurrency cap, momentary saturation) are NOT
2726
+ // chained: their "reset" is a re-poll guess, not a scheduled quota reset, and
2727
+ // the capacity window exists precisely to shed that load (the soft-deadlock
2728
+ // guard — pinned at cap forever must 429 within the window, never spin).
2729
+ // Only quota-class resets (a scheduled 5h/weekly rollover) chain.
2730
+ if (requestInfo.stream && queueWindowMs > 0 && Number.isFinite(retryAfterMs)
2731
+ && retryPlan.cause !== 'concurrency_cap' && cause !== 'capacity') {
2732
+ requestInfo.queueHoldChain = true;
2733
+ } else {
2734
+ return finishQueuedStreamIfNeeded(res, requestInfo, honestMessage);
2735
+ }
2706
2736
  }
2707
2737
 
2708
2738
  requestInfo.queueStartedAt ||= Date.now();
@@ -2729,12 +2759,14 @@ async function queueAndRetry(
2729
2759
 
2730
2760
  ctx.account = '(queued)';
2731
2761
  hooks.onRequestRouted?.(reqId, { account: '(queued)' });
2732
- console.log(`[Maxpool] ${reason}; queueing request for up to ${Math.ceil(remaining / 1000)}s (cause: ${cause}, retry: ${retryPlan.cause})`);
2762
+ // Hold-chain note: when this hold expires still-full (queueHoldChain), the
2763
+ // finishQueuedStreamIfNeeded below ends the stream with the retriable error and
2764
+ // the client re-enters — the log line makes the chaining visible.
2765
+ console.log(`[Maxpool] ${reason}; queueing request for up to ${Math.ceil(remaining / 1000)}s (cause: ${cause}, retry: ${retryPlan.cause}${requestInfo.queueHoldChain ? ', hold-chain: reset beyond window' : ''})`);
2733
2766
  ensureQueueHeartbeat(res, requestInfo, queueConfig, accountManager);
2734
2767
 
2735
2768
  const available = await waitForAvailableRoute(req, res, accountManager, requestInfo, queueConfig, remaining);
2736
2769
  if (!available) {
2737
- if (res.destroyed || req.destroyed) return true;
2738
2770
  accountManager.removeQueuedRequest?.(requestInfo);
2739
2771
  return finishQueuedStreamIfNeeded(res, requestInfo, honestMessage);
2740
2772
  }