maxpool 1.19.4 → 1.19.5

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.19.4",
3
+ "version": "1.19.5",
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
@@ -592,9 +592,11 @@ async function forwardRequest(
592
592
  // transcript. Hand the client the signal it already knows how to act on — it resends
593
593
  // the turn stateless and stops threading for the session — instead of letting the
594
594
  // upstream produce an error the user sees.
595
+ // `kind:'none'` when the gate is off makes every branch below a no-op, so the
596
+ // disabled path costs one comparison and needs no further guarding.
595
597
  const threadIntent = THREAD_GATE_ENABLED ? readThreadIntent(body) : { kind: 'none' };
596
- if (THREAD_GATE_ENABLED && threadOwners.shouldRefuse(requestInfo.sessionKey, account.name, threadIntent)) {
597
- threadOwners.noteRefused(requestInfo.sessionKey);
598
+ if (threadOwners.shouldRefuse(requestInfo.sessionKey, account.name, threadIntent)) {
599
+ threadOwners.noteRefused(requestInfo.sessionKey, account.name);
598
600
  accountManager.releaseAccount(lease, { neutral: true });
599
601
  console.log(`[Maxpool] thread not held by "${account.name}" — asking the client to resend this turn stateless [sess ${String(requestInfo.sessionKey || '?').slice(0, 8)}]`);
600
602
  ctx.status = 400;
@@ -603,7 +605,7 @@ async function forwardRequest(
603
605
  }
604
606
  // This account is about to serve the turn, so it holds the thread from here on.
605
607
  // Recorded optimistically: if the turn fails, the next one is refused anyway.
606
- if (THREAD_GATE_ENABLED) threadOwners.noteServed(requestInfo.sessionKey, account.name, threadIntent);
608
+ threadOwners.noteServed(requestInfo.sessionKey, account.name, threadIntent);
607
609
 
608
610
  // Build log sections
609
611
  const logSections = [];
@@ -29,7 +29,7 @@ export function readThreadIntent(body) {
29
29
  // `previous_message_id` can also ride in `diagnostics`; that alone is not a thread.
30
30
  return { kind: 'none' };
31
31
  }
32
- if (t.type === 'continue') return { kind: 'continue', previousMessageId: t.previous_message_id || null };
32
+ if (t.type === 'continue') return { kind: 'continue' };
33
33
  if (t.type === 'create') return { kind: 'create' };
34
34
  return { kind: 'none' };
35
35
  } catch {
@@ -57,6 +57,9 @@ const MAX_SESSIONS = 500;
57
57
  // did NOT take the downgrade (a different agent id, a model switch, an older build).
58
58
  // Refusing forever would double its request volume, so stop and forward instead.
59
59
  const MAX_CONSECUTIVE_REFUSALS = 2;
60
+ // Bucket for requests that carry no session header — keyed per account so the storm
61
+ // bound still applies without pretending we know whose conversation it is.
62
+ const NO_SESSION_PREFIX = '\u0000nosession:';
60
63
 
61
64
  export class ThreadOwners {
62
65
  constructor({ maxSessions = MAX_SESSIONS, maxRefusals = MAX_CONSECUTIVE_REFUSALS } = {}) {
@@ -80,27 +83,38 @@ export class ThreadOwners {
80
83
  /** Decide AFTER routing has chosen. Returns true only for a `continue` turn that the
81
84
  * chosen account cannot serve, and only while refusals are still under the bound. */
82
85
  shouldRefuse(sessionKey, accountName, intent) {
83
- if (!sessionKey || !accountName) return false;
86
+ if (!accountName) return false;
84
87
  if (intent?.kind !== 'continue') return false; // `create` carries the full transcript
85
- const entry = this._touch(sessionKey);
88
+ // A request with NO session header is invisible to ownership tracking, and measured
89
+ // 2026-09-11 those are the majority of traffic — 14 of 20 consecutive /v1/messages
90
+ // lines carried no `[sess …]`. Skipping them left threaded turns reaching GLM and
91
+ // failing exactly as before the gate existed. We cannot know the owner, so treat it
92
+ // as an unknown session (refuse, the safe direction) and bucket the refusal COUNT
93
+ // per account so the storm bound still applies.
94
+ const key = sessionKey || `${NO_SESSION_PREFIX}${accountName}`;
95
+ const entry = this._touch(key);
86
96
  if (entry && entry.owner === accountName) return false; // the account that holds it
87
97
  if (entry && entry.refusals >= this.maxRefusals) return false; // bounded fail-open
88
98
  return true;
89
99
  }
90
100
 
91
101
  /** Record a refusal we are about to emit. */
92
- noteRefused(sessionKey) {
93
- if (!sessionKey) return;
94
- const entry = this._touch(sessionKey) || { owner: null, refusals: 0 };
95
- this._set(sessionKey, { owner: entry.owner, refusals: entry.refusals + 1 });
102
+ noteRefused(sessionKey, accountName = null) {
103
+ const key = sessionKey || (accountName ? `${NO_SESSION_PREFIX}${accountName}` : null);
104
+ if (!key) return;
105
+ const entry = this._touch(key) || { owner: null, refusals: 0 };
106
+ this._set(key, { owner: entry.owner, refusals: entry.refusals + 1 });
96
107
  }
97
108
 
98
109
  /** Record that `accountName` served a threaded turn for this session — it now holds
99
110
  * the thread. Any refusal streak ends here. */
100
111
  noteServed(sessionKey, accountName, intent) {
101
- if (!sessionKey || !accountName) return;
112
+ if (!accountName) return;
102
113
  if (intent?.kind !== 'create' && intent?.kind !== 'continue') return;
103
- this._set(sessionKey, { owner: accountName, refusals: 0 });
114
+ // Without a session header there is no conversation to attribute ownership to; only
115
+ // clear the per-account refusal streak so a served turn re-arms the bound.
116
+ const key = sessionKey || `${NO_SESSION_PREFIX}${accountName}`;
117
+ this._set(key, { owner: sessionKey ? accountName : null, refusals: 0 });
104
118
  }
105
119
 
106
120
  get size() { return this.map.size; }
package/src/tui.js CHANGED
@@ -332,7 +332,28 @@ function emptyBar(label, w = 10) {
332
332
  return `${ESC}100m${' '.repeat(lp)}${text}${' '.repeat(rp)}${RESET}`;
333
333
  }
334
334
 
335
- export const __tuiTest = { formatReset, quotaLabel, bar, emptyBar, strip, loadText, countdown, acctHeader, fitLine, providerLabel };
335
+ /** Write a provider's enabled flag into the CONFIG entry `loadConfigProviders` reads.
336
+ *
337
+ * A config-sourced provider is re-created from config on every reload
338
+ * (`enabled: entry.enabled !== false`), so a runtime-only flag is undone by the next
339
+ * auto-update. Measured 2026-09-11: Kimi, disabled by the owner, came back enabled
340
+ * after an update because its config entry carried no `enabled` key.
341
+ *
342
+ * Returns `{changed, previous}` so the caller can roll back if the save fails.
343
+ * `changed:false` means there is no config entry — a header-derived provider, whose
344
+ * runtime-only flag IS durable for it.
345
+ */
346
+ export function applyProviderEnabledToConfig(config, name, enabled) {
347
+ const list = config?.providers;
348
+ if (!Array.isArray(list)) return { changed: false, previous: undefined };
349
+ const i = list.findIndex(p => p?.name === name);
350
+ if (i < 0) return { changed: false, previous: undefined };
351
+ const previous = list[i].enabled;
352
+ list[i].enabled = enabled;
353
+ return { changed: true, previous };
354
+ }
355
+
356
+ export const __tuiTest = { applyProviderEnabledToConfig, formatReset, quotaLabel, bar, emptyBar, strip, loadText, countdown, acctHeader, fitLine, providerLabel };
336
357
 
337
358
  function timestamp() {
338
359
  return new Date().toLocaleTimeString('en-US', { hour12: false });
@@ -359,7 +380,8 @@ export class TUI {
359
380
  this.capacityWindow = 'ses'; // capacity page window: 'ses' (5h) | 'wk' (weekly)
360
381
  // Hide disabled accounts from the table. With 8 dead/disabled accounts the live
361
382
  // ones scroll off the top; `h` collapses them to a one-line summary.
362
- this.hideDisabled = false;
383
+ // Restored from config so an auto-update/reload does not un-hide what the user hid.
384
+ this.hideDisabled = this.config?.ui?.hideDisabled === true;
363
385
  this.selAction = null; // prefer | toggle | delete
364
386
  this.selIdx = 0;
365
387
  this.inputPrompt = '';
@@ -556,6 +578,13 @@ export class TUI {
556
578
  } else if (k === 'h') {
557
579
  this.hideDisabled = !this.hideDisabled;
558
580
  this._addLog(this.hideDisabled ? 'Hiding disabled accounts' : 'Showing all accounts');
581
+ // Persist the view choice; a reload otherwise resets it to "show all" every time.
582
+ // Fully defensive: a VIEW preference must never break the toggle itself, and the
583
+ // TUI is constructed without a config in several tests and in early startup.
584
+ if (this.config) {
585
+ this.config.ui = { ...(this.config.ui || {}), hideDisabled: this.hideDisabled };
586
+ try { this.saveConfig?.(this.config)?.catch?.(() => {}); } catch { /* view-only */ }
587
+ }
559
588
  }
560
589
  // Enable/disable lives ONLY under [a] Accounts now (with rename/delete/login) —
561
590
  // one home for every account mutation, instead of a duplicate top-level toggle.
@@ -1540,6 +1569,22 @@ export class TUI {
1540
1569
  // on the next save, so it stays benched across a restart too. Re-enable it here the
1541
1570
  // same way whenever the user wants it back — there's no "removed forever" state.
1542
1571
  if (account.type === 'provider') {
1572
+ // A CONFIG-SOURCED provider (one with a `providers:` entry) is re-created from
1573
+ // config on every reload — `loadConfigProviders` computes `enabled: entry.enabled
1574
+ // !== false` — so a runtime-only flag is silently undone by the next update or
1575
+ // restart. Persist it where that read happens. Measured 2026-09-11: Kimi, disabled
1576
+ // by the owner, came back enabled after an auto-update because its config entry
1577
+ // had no `enabled` key. Header-derived providers (no config entry) keep the
1578
+ // runtime-only path below, which is durable for them.
1579
+ const applied = applyProviderEnabledToConfig(this.config, account.name, enabled);
1580
+ if (applied.changed) {
1581
+ try {
1582
+ await this.saveConfig(this.config);
1583
+ } catch (error) {
1584
+ applyProviderEnabledToConfig(this.config, account.name, applied.previous);
1585
+ throw error;
1586
+ }
1587
+ }
1543
1588
  this.am.setAccountEnabled(idx, enabled);
1544
1589
  if (!enabled && this.am.preferredAccountName === account.name) this.am.setRoutingMode?.('automatic');
1545
1590
  this._addLog(`${enabled ? 'Enabled' : 'Disabled'} provider "${account.name}" — ${enabled ? 'routing resumed' : 'benched (stays off across cc all + restart; re-enable here anytime)'}`);