maxpool 1.24.69 → 1.24.70

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.69",
3
+ "version": "1.24.70",
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/index.js CHANGED
@@ -18,6 +18,7 @@ import { loadOrCreateConfig, loadConfig, saveConfig, atomicConfigUpdate, getConf
18
18
  import { setEventLogPath, installConsoleMirror, setConsoleStdoutSuppressed, appendEventLog } from './event-log.js';
19
19
  import { sendLoginToPool, planCliLogin, resolveUsablePools } from './cloud-login.js';
20
20
  import { SleepGuard } from './sleep-guard.js';
21
+ import { controllingTerminalAlive } from './terminal-alive.js';
21
22
  import { AccountManager } from './account-manager.js';
22
23
  import { createProxyServer, REQUEST_IDLE_MAX_MS } from './server.js';
23
24
 
@@ -1638,7 +1639,18 @@ async function serverWorkerCommand() {
1638
1639
  // drain + exit cleanly so we never reload into a headless orphan that outlives
1639
1640
  // the terminal and squats the port. Headless/service mode keeps SIGHUP as the
1640
1641
  // conventional reload signal (baton under the supervisor, else exit-75).
1641
- process.on('SIGHUP', () => { if (isInteractiveTerminal()) shutdownGracefully('SIGHUP', { terminalClose: true }); else requestReload(); });
1642
+ // A SIGHUP while the terminal is still open came from another program (`kill
1643
+ // -HUP`), not a closed window — ignore it rather than kill every session using
1644
+ // the pool. Re-check shortly after, in case the signal raced the terminal revoke.
1645
+ const hangupShutdown = () => shutdownGracefully('SIGHUP', { terminalClose: true });
1646
+ process.on('SIGHUP', () => {
1647
+ if (!isInteractiveTerminal()) return requestReload();
1648
+ if (!controllingTerminalAlive()) return hangupShutdown();
1649
+ console.log('[Maxpool] Ignored SIGHUP: this terminal is still open, so another program sent it (not a closed window). Maxpool keeps running — press r to restart it.');
1650
+ for (const ms of [500, 2000]) {
1651
+ setTimeout(() => { if (!draining && !controllingTerminalAlive()) hangupShutdown(); }, ms).unref?.();
1652
+ }
1653
+ });
1642
1654
  }
1643
1655
 
1644
1656
  function logPlainServerStart({ host, port, accounts, threshold, config }) {
package/src/pool-link.js CHANGED
@@ -178,6 +178,17 @@ function sanitizeRemoteStatus(json) {
178
178
  * so a link that hasn't polled yet still benches what it benched last run.
179
179
  */
180
180
  const BOOT_IDS_TTL_MS = 14 * 24 * 3600 * 1000; // stale beyond this → trust a fresh boot instead
181
+ export const FAILS_BEFORE_DOWN = 2;
182
+
183
+ /** Plain-English cause of a link failure, for the one-line cloud banner. */
184
+ export function describeLinkError(err) {
185
+ const e = String(err || '');
186
+ if (e === 'key rejected') return "the cloud pool rejected this laptop's key";
187
+ if (/^HTTP 5\d\d$/.test(e)) return `the cloud pool answered with an error (${e})`;
188
+ if (/^HTTP /.test(e)) return `the cloud pool answered ${e}`;
189
+ // timeout, ECONNREFUSED/RESET, "fetch failed", DNS… — from here they look alike.
190
+ return `no connection — check your internet or the tunnel (${e || 'network error'})`;
191
+ }
181
192
 
182
193
  export class PoolLink {
183
194
  constructor(def, deps = {}) {
@@ -194,6 +205,8 @@ export class PoolLink {
194
205
  this.status = null; // raw remote status JSON when ok
195
206
  this.lastError = null;
196
207
  this.lastOkAt = null;
208
+ this.failStreak = 0; // consecutive failed checks
209
+ this.downSince = null; // when lastError was first set (the outage start)
197
210
  this.identities = new Map();
198
211
  this.summary = null;
199
212
  }
@@ -226,13 +239,23 @@ export class PoolLink {
226
239
  this.status = sanitizeRemoteStatus(r.json);
227
240
  this.lastOkAt = r.at;
228
241
  this.lastError = null;
242
+ this.failStreak = 0;
243
+ this.downSince = null;
229
244
  this.identities = remoteIdentities(r.json);
230
245
  this.summary = summarizeRemote(r.json);
231
246
  } else {
232
- // Keep the LAST good status for display, but mark the link degraded so
233
- // routing benches it and the UI names the error.
234
- this.lastError = r.error;
235
- this.summary = null;
247
+ // One missed check on a flaky network is not an outage: a single timeout
248
+ // used to flip every cloud row to ✕ while requests were still getting
249
+ // through. Mark the link down only after FAILS_BEFORE_DOWN checks in a row
250
+ // (a rejected key is never transient — down at once). Keep the LAST good
251
+ // status for display; down → routing benches it and the UI names the cause.
252
+ this.failStreak = (this.failStreak || 0) + 1;
253
+ this.lastPollError = r.error;
254
+ if (this.failStreak >= FAILS_BEFORE_DOWN || r.error === 'key rejected' || this.lastOkAt == null) {
255
+ if (!this.lastError) this.downSince = r.at;
256
+ this.lastError = r.error;
257
+ this.summary = null;
258
+ }
236
259
  }
237
260
  return r;
238
261
  } finally {
@@ -0,0 +1,24 @@
1
+ // Is the terminal running maxpool still open? A SIGHUP has two very different
2
+ // senders: the kernel, when the window closes (→ shut down, or we orphan onto a
3
+ // dead terminal), and another program running `kill -HUP` to "reload" (→ shutting
4
+ // down kills every session using the pool; happened 2026-11-07). When the window
5
+ // really closed, the controlling terminal is revoked: opening /dev/tty fails and
6
+ // writes to it fail. When it is still open, both succeed.
7
+ import { openSync, closeSync, writeSync } from 'node:fs';
8
+
9
+ export function controllingTerminalAlive({
10
+ isTTY = Boolean(process.stdout.isTTY),
11
+ fd = process.stdout.fd,
12
+ open = openSync, close = closeSync, write = writeSync,
13
+ } = {}) {
14
+ // Not a real terminal (a pipe, or the test suite's forced-terminal mode): no way
15
+ // to tell, so keep the long-standing answer — treat the SIGHUP as a hangup.
16
+ if (!isTTY) return false;
17
+ try {
18
+ close(open('/dev/tty', 'r+'));
19
+ write(fd, '');
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
package/src/tui.js CHANGED
@@ -4,6 +4,7 @@ import { homedir } from 'node:os';
4
4
  import { fetchProfile, loginOAuth, tokenFingerprint, isLoginCancelled } from './oauth.js';
5
5
  import { appendEventLog, setConsoleStdoutSuppressed } from './event-log.js';
6
6
  import { sendLoginToPool } from './cloud-login.js';
7
+ import { describeLinkError } from './pool-link.js';
7
8
 
8
9
  // ── ANSI helpers ─────────────────────────────────────────────
9
10
 
@@ -815,6 +816,22 @@ export class TUI {
815
816
  return ` Routing ${cyan(routing)}${xpText}`;
816
817
  }
817
818
 
819
+ /** One line per unreachable team pool, so a lost connection reads as ONE cause
820
+ * instead of every cloud row turning red. '' lines are skipped by the caller. */
821
+ _cloudLinkLines(W = 80, now = Date.now()) {
822
+ const out = [];
823
+ for (const l of this.am.poolLinks || []) {
824
+ if (!l.lastError && l.lastOkAt != null) continue;
825
+ const since = l.downSince ?? l.lastOkAt;
826
+ const forTxt = since ? ` for ${formatAge(now - since)}` : '';
827
+ const synced = l.lastOkAt ? ` · last synced ${new Date(l.lastOkAt).toLocaleTimeString()}` : '';
828
+ const why = l.lastOkAt == null && !l.lastError ? 'connecting…' : describeLinkError(l.lastError);
829
+ const line = ` Cloud ${yellow(`⟐ ${l.name} unreachable${forTxt}`)} ${dim('—')} ${why}${dim(`. Cloud accounts paused; local accounts still serving${synced}.`)}`;
830
+ out.push(fitLine(line, W));
831
+ }
832
+ return out;
833
+ }
834
+
818
835
  _renderUpdatesDetail() {
819
836
  const v = this.am.versionInfo;
820
837
  const running = v?.current ? `v${v.current}` : 'unknown';
@@ -2076,6 +2093,7 @@ export class TUI {
2076
2093
  if (provReq > 0) xpText += ` ${dim('·')} ${yellow(`providers: ${provReq} req/15m`)}`;
2077
2094
  }
2078
2095
  lines.push(this._routingLine(routing, xpText));
2096
+ lines.push(...this._cloudLinkLines(W));
2079
2097
  const queuedCount = this.am.queueState?.waiting?.length || 0;
2080
2098
  // Throttle and WAITING are different things and used to share one line labelled
2081
2099
  // "Anthropic upstream throttled" — so a request parked purely because every account
@@ -2367,7 +2385,8 @@ export class TUI {
2367
2385
  case 'paused': status = yellow('paused'); break;
2368
2386
  case 'disabled': status = red('✕ disabled'); break;
2369
2387
  case 'pool-benched': status = gray('in cloud'); break;
2370
- case 'cloud-down': status = red('⟐ cloud ✕'); break;
2388
+ // The banner above names the cause once; each row just says it is out of reach.
2389
+ case 'cloud-down': status = yellow('⟐ offline'); break;
2371
2390
  // Disabled AND needs re-login — both facts matter, and DISABLED LEADS.
2372
2391
  // The owner's question that drove this (2026-09-30): "when I disable the account
2373
2392
  // and then the token expires, does it show disabled or reauth? It needs to