maxpool 1.24.76 → 1.24.78

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.76",
3
+ "version": "1.24.78",
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",
@@ -343,6 +343,12 @@ const PERSISTED_QUOTA_FIELDS = [
343
343
  ];
344
344
 
345
345
  const CONVERSATION_AFFINITY_MAX = 5000;
346
+ const IDENTITY_WINDOW_MS = 15 * 60_000;
347
+ const IDENTITY_MAX_SAMPLES = 4000;
348
+ const IDENTITY_MIN_PER_SESSION = 8;
349
+ const IDENTITY_MIN_SAMPLE = 60;
350
+ const IDENTITY_DEGRADED_RATE = 0.9;
351
+ const IDENTITY_RECOVER_RATE = 0.7;
346
352
  const PROVIDER_429_MIN_BENCH_SEC = 60;
347
353
  const PROVIDER_429_MAX_BENCH_SEC = 15 * 60;
348
354
  const PROVIDER_429_STREAK_FORGET_MS = 60 * 60 * 1000;
@@ -603,6 +609,12 @@ export class AccountManager {
603
609
  // Bounded LRU — oldest conversations drop first; a dropped entry only means the
604
610
  // next turn is balanced fresh.
605
611
  this.conversationLastAccount = new Map();
612
+ // Conversation-identity HEALTH (owner 2026-11-08: "make sure this cannot degrade
613
+ // silently"). Twice in one day a Claude Code request-shape detail (a moving
614
+ // cache_control marker, then a per-request billing checksum) made every turn hash
615
+ // to a new conversation id — affinity went silently inert. Rolling sample of
616
+ // (terminal, conversation id) per request; see _noteIdentityHealth.
617
+ this.identityHealth = { samples: [], degraded: false, since: null, lastRate: null, lastN: 0 };
606
618
  this._peakCache = null; // per-UTC-minute peak-window memo (see _peakStateFor)
607
619
  // CAPACITY LEDGER (2026-08-22): observed tokens per completed window cycle, so
608
620
  // "true capacity" is comparable across providers. Restored from state on boot.
@@ -882,6 +894,7 @@ export class AccountManager {
882
894
  // disagree with the peak tier that caused the move (defaults to real time).
883
895
  this._bindSession(requestInfo.sessionKey, account, requestInfo.model, requestInfo.now);
884
896
  }
897
+ this._noteIdentityHealth(requestInfo);
885
898
  this._noteConversationAccount(requestInfo, account);
886
899
  account.inFlight++;
887
900
  account.activeWeight += weight;
@@ -3202,9 +3215,50 @@ export class AccountManager {
3202
3215
  * falls back to the terminal session key (callers that never set the hash,
3203
3216
  * e.g. tests and pre-hash call sites). */
3204
3217
  _affinityKey(requestInfo = {}) {
3218
+ // SELF-HEAL: while conversation identity looks broken, fall back to the
3219
+ // per-terminal key — cruder (subagents share it) but immune to request-shape
3220
+ // drift, so stickiness degrades instead of switching off.
3221
+ if (this.identityHealth.degraded) return requestInfo.sessionKey || requestInfo.affinityKey || null;
3205
3222
  return requestInfo.affinityKey || requestInfo.sessionKey || null;
3206
3223
  }
3207
3224
 
3225
+ /** Track how often each terminal's requests START a new conversation id. Healthy
3226
+ * traffic reuses ids (measured 2026-11-08 on 1.24.77: 68 turns → 19 conversations;
3227
+ * a busy terminal 32 requests → 6 ids). A broken identity gives ~every request a
3228
+ * fresh id. Window: last IDENTITY_WINDOW_MS; judged only over terminals with at
3229
+ * least IDENTITY_MIN_PER_SESSION requests in it (a terminal sending 2 requests
3230
+ * proves nothing) and IDENTITY_MIN_SAMPLE requests in total. Flip to degraded at
3231
+ * ≥ IDENTITY_DEGRADED_RATE new-id share; recover below IDENTITY_RECOVER_RATE
3232
+ * (hysteresis — no flapping). One log line per transition; status shows the state. */
3233
+ _noteIdentityHealth(requestInfo, now = Date.now()) {
3234
+ if (!requestInfo.sessionKey || !requestInfo.conversationHash) return;
3235
+ const h = this.identityHealth;
3236
+ h.samples.push({ t: now, s: requestInfo.sessionKey, c: requestInfo.conversationHash });
3237
+ const cutoff = now - IDENTITY_WINDOW_MS;
3238
+ while (h.samples.length && h.samples[0].t < cutoff) h.samples.shift();
3239
+ if (h.samples.length > IDENTITY_MAX_SAMPLES) h.samples.splice(0, h.samples.length - IDENTITY_MAX_SAMPLES);
3240
+ const perSession = new Map();
3241
+ for (const x of h.samples) {
3242
+ if (!perSession.has(x.s)) perSession.set(x.s, []);
3243
+ perSession.get(x.s).push(x.c);
3244
+ }
3245
+ let reqs = 0; let fresh = 0;
3246
+ for (const ids of perSession.values()) {
3247
+ if (ids.length < IDENTITY_MIN_PER_SESSION) continue;
3248
+ reqs += ids.length; fresh += new Set(ids).size;
3249
+ }
3250
+ if (reqs < IDENTITY_MIN_SAMPLE) return;
3251
+ const rate = fresh / reqs;
3252
+ h.lastRate = rate; h.lastN = reqs;
3253
+ if (!h.degraded && rate >= IDENTITY_DEGRADED_RATE) {
3254
+ h.degraded = true; h.since = now;
3255
+ console.log(`[Maxpool] cache affinity: conversation identity looks BROKEN (${Math.round(rate * 100)}% of ${reqs} requests started a new conversation) — Claude Code's request shape probably changed. Falling back to per-terminal stickiness until it recovers; the hash in describeRequest needs updating.`);
3256
+ } else if (h.degraded && rate < IDENTITY_RECOVER_RATE) {
3257
+ h.degraded = false; h.since = now;
3258
+ console.log(`[Maxpool] cache affinity: conversation identity healthy again (${Math.round(rate * 100)}% new over ${reqs} requests) — per-conversation stickiness restored.`);
3259
+ }
3260
+ }
3261
+
3208
3262
  _cacheAffinity(account, requestInfo = {}) {
3209
3263
  const base = Number(this.scheduler.cacheAffinityBonus) || 0;
3210
3264
  // Sticky mode has its own binding; its score loop runs only once the session has
@@ -5213,6 +5267,14 @@ export class AccountManager {
5213
5267
  // verifies the wrong thing (measured 2026-08-23: reported 1.8.7 while executing
5214
5268
  // 1.8.6). This field is the one to assert on.
5215
5269
  runningVersion: this.runningVersion || null,
5270
+ // Cache-affinity identity health — 'ok' | 'degraded' (+ the measured new-id
5271
+ // share). A post-release check asserts 'ok' on live traffic.
5272
+ affinityIdentity: {
5273
+ state: this.identityHealth.degraded ? 'degraded' : 'ok',
5274
+ newConversationShare: this.identityHealth.lastRate,
5275
+ sampledRequests: this.identityHealth.lastN,
5276
+ since: this.identityHealth.since,
5277
+ },
5216
5278
  currentAccount: this.accounts[this.currentIndex]?.name,
5217
5279
  switchThreshold: this.switchThreshold,
5218
5280
  routing: {
package/src/server.js CHANGED
@@ -3496,7 +3496,15 @@ function describeRequest(req, body) {
3496
3496
  // 1,360 tagged turns unique on 2026-11-08), which made the affinity inert and
3497
3497
  // the join useless. Strip cache_control (and any future positioning hints)
3498
3498
  // before hashing; identity = system text + first message CONTENT.
3499
- const stable = (v) => JSON.stringify(v, (k, val) => (k === 'cache_control' || k === '_pf') ? undefined : val);
3499
+ // Positioning markers AND Claude Code's billing header both change per request:
3500
+ // the first system block carries `x-anthropic-billing-header: … cch=<checksum>;
3501
+ // cc_prev_req=<id>; …` whose values differ every turn (measured on live traffic
3502
+ // 2026-11-08: identical 170,024-char systems differing only inside that header).
3503
+ // Identity must come from CONTENT: drop cache_control/_pf keys and skip any
3504
+ // system block that starts with x-anthropic-billing-header.
3505
+ const stable = (v) => JSON.stringify(
3506
+ Array.isArray(v) ? v.filter(b => !(b && typeof b === 'object' && String(b.text || '').startsWith('x-anthropic-billing-header'))) : v,
3507
+ (k, val) => (k === 'cache_control' || k === '_pf') ? undefined : val);
3500
3508
  info.conversationHash = createHash('sha256')
3501
3509
  .update(stable(json.system ?? ''))
3502
3510
  .update('\u0000')