maxpool 1.24.78 → 1.24.80
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 +1 -1
- package/src/account-manager.js +132 -27
- package/src/index.js +39 -10
- package/src/reload-protocol.js +1 -0
package/package.json
CHANGED
package/src/account-manager.js
CHANGED
|
@@ -183,9 +183,31 @@ const DEFAULT_SCHEDULER = {
|
|
|
183
183
|
// a conversation's last-used healthy account sheds (every mode except sticky).
|
|
184
184
|
// On an undiscounted row one in-flight weight unit costs ~12 points past the
|
|
185
185
|
// per-account target (the bonus is rescaled per row so discounted rows match),
|
|
186
|
-
// and a Claude Code turn weighs 3-30 units: 400 ≈ 33 units
|
|
187
|
-
//
|
|
186
|
+
// and a Claude Code turn weighs 3-30 units: 400 ≈ 33 units of extra depth before
|
|
187
|
+
// the conversation moves. It scales up with conversation size (to 3x) but is then
|
|
188
|
+
// CAPPED at cacheAffinityMaxExtraDepth below (40 units ≈ 480 points), so the
|
|
189
|
+
// effective bonus is 400-480 whatever the size. 0 = pure per-request.
|
|
188
190
|
cacheAffinityBonus: 400,
|
|
191
|
+
// ANTI-DOGPILE CAP on what the hold may buy (owner hard rule 2026-11-08: many parallel
|
|
192
|
+
// sessions must SPREAD; a hold must never stack conversations on one account until it
|
|
193
|
+
// throttles). The size-scaled bonus above reaches 3x (1200 points ≈ 100 weight units ≈
|
|
194
|
+
// 11 big turns) for a 450KB+ conversation — measured: 11 bound 450KB conversations on
|
|
195
|
+
// one account, depth 110 (old code with the account in weekly reserve: 2, depth 30).
|
|
196
|
+
// This is the most EXTRA depth, in weight units past the account's concurrency target
|
|
197
|
+
// (perAccountConcurrencyTarget, or the tighter reserveConcurrencyTarget for reserve /
|
|
198
|
+
// unlocked-critical), that a hold can ever tolerate on ANY account: 40 ≈ 4 turns of a
|
|
199
|
+
// ~450KB conversation (weight ~10). Priced per row at that row's own unit cost, so a
|
|
200
|
+
// discounted GLM row gets the same DEPTH. Hard bound on a held account's in-flight depth
|
|
201
|
+
// = concTarget + this + one request's weight, whatever the body size or bonus. A reserve /
|
|
202
|
+
// unlocked-critical row's hold is scaled by reserveConcurrencyTarget/perAccountConcurrencyTarget.
|
|
203
|
+
cacheAffinityMaxExtraDepth: 40,
|
|
204
|
+
// HOLD-UNTIL-CANNOT-SERVE (owner 2026-11-08): a bound conversation leaves its last
|
|
205
|
+
// account only when that account truly cannot serve it. A re-store costs the same
|
|
206
|
+
// whether the conversation leaves at 85% or at the wall, so leaving early buys
|
|
207
|
+
// nothing and staying avoids it if the conversation ends / the window resets first.
|
|
208
|
+
// This is the 5-hour-window level at which the hold lets go (providers; Claude
|
|
209
|
+
// benches at switchThreshold anyway). Weekly reserve/soft tiers do NOT release.
|
|
210
|
+
cacheAffinityFiveHourWall: 0.97,
|
|
189
211
|
concurrencyWeight: 2, // multiplies in-flight load (activeWeight+reqWeight) — dominant
|
|
190
212
|
perAccountConcurrencyTarget: 3, // D: soft per-account in-flight target; past it, capPenalty bites
|
|
191
213
|
capPenaltyWeight: 10, // steep penalty per unit of in-flight depth past D (throttle safety floor)
|
|
@@ -2358,7 +2380,9 @@ export class AccountManager {
|
|
|
2358
2380
|
const ckey = this._affinityKey(requestInfo);
|
|
2359
2381
|
const lastName = ckey ? this.conversationLastAccount.get(ckey) : null;
|
|
2360
2382
|
if (lastName && lastName !== best.name) {
|
|
2361
|
-
|
|
2383
|
+
let why = 'unknown';
|
|
2384
|
+
try { why = this._moveReason(lastName, best, requestInfo, excludedIndexes, scoringCtx, weeklyOptions, bestUnlockMap.get(best.name) || null, now); } catch (e) { why = `error:${e.message}`; }
|
|
2385
|
+
console.log(`[Maxpool] conversation moved: ${lastName} → ${best.name} (${requestInfo.bodyBytes ?? '?'}B) why=${why}`);
|
|
2362
2386
|
}
|
|
2363
2387
|
return best;
|
|
2364
2388
|
}
|
|
@@ -3066,10 +3090,10 @@ export class AccountManager {
|
|
|
3066
3090
|
return this._holdsUsableReset(account, now) ? 1 - Math.min(d, 0.9) : 1;
|
|
3067
3091
|
}
|
|
3068
3092
|
|
|
3069
|
-
|
|
3093
|
+
_scoreTerms(account, requestInfo = {}, ctx = null, criticalUnlock = null) {
|
|
3070
3094
|
const now = ctx?.now ?? Date.now();
|
|
3071
3095
|
// CACHE AFFINITY — see _cacheAffinity.
|
|
3072
|
-
const affinity = this._cacheAffinity(account, requestInfo);
|
|
3096
|
+
const affinity = this._cacheAffinity(account, requestInfo, criticalUnlock);
|
|
3073
3097
|
const reqWeight = Math.max(1, requestInfo.weight || 1);
|
|
3074
3098
|
// POOL LINK scores as the cloud's WORST-case load (owner 2026-10-29: "the team
|
|
3075
3099
|
// pool will respect the accounts within it... included in the balancing act").
|
|
@@ -3173,15 +3197,24 @@ export class AccountManager {
|
|
|
3173
3197
|
const reserveCost = this._reserveCost(account, now, weeklyState);
|
|
3174
3198
|
const criticalCost = this._criticalCost(account, now, criticalUnlock, weeklyState);
|
|
3175
3199
|
const failurePenalty = account.consecutiveFailures * 5;
|
|
3176
|
-
//
|
|
3177
|
-
//
|
|
3178
|
-
//
|
|
3179
|
-
//
|
|
3180
|
-
//
|
|
3181
|
-
//
|
|
3182
|
-
//
|
|
3183
|
-
|
|
3184
|
-
|
|
3200
|
+
// HELD conversation: the quota/steering terms (pace, utilization, scoped pace,
|
|
3201
|
+
// spread, recovery ramp, reserve/critical overflow cost) exist to steer NEW work
|
|
3202
|
+
// away from tight accounts. They must not, by themselves, pull an already-bound
|
|
3203
|
+
// conversation off an account that can still serve it — a re-store costs more
|
|
3204
|
+
// than any of them. Zeroed for the bound account only while the hold is live; the
|
|
3205
|
+
// LOAD terms (concurrency, capPenalty) stay, so the load-gap escape is untouched.
|
|
3206
|
+
// Structural, not a bonus-size accident: holds at any cacheAffinityBonus > the load gap.
|
|
3207
|
+
const held = affinity > 0;
|
|
3208
|
+
const steer = held ? { paceCost: 0, utilizationCost: 0, scopedPace: 0, spread: 0, ramp: 0, reserveCost: 0, criticalCost: 0 }
|
|
3209
|
+
: { paceCost, utilizationCost, scopedPace, spread, ramp, reserveCost, criticalCost };
|
|
3210
|
+
const terms = { concurrency, capPenalty, ...steer, failurePenalty, affinity };
|
|
3211
|
+
return terms;
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
/** Routing cost — lower is preferred. Sum of the named terms minus the affinity bonus. */
|
|
3215
|
+
_scoreAccount(account, requestInfo = {}, ctx = null, criticalUnlock = null) {
|
|
3216
|
+
const t = this._scoreTerms(account, requestInfo, ctx, criticalUnlock);
|
|
3217
|
+
return Math.max(0, t.concurrency + t.capPenalty + t.paceCost + t.utilizationCost + t.scopedPace + t.spread + t.ramp + t.reserveCost + t.criticalCost + t.failurePenalty - t.affinity);
|
|
3185
3218
|
}
|
|
3186
3219
|
|
|
3187
3220
|
/**
|
|
@@ -3259,7 +3292,35 @@ export class AccountManager {
|
|
|
3259
3292
|
}
|
|
3260
3293
|
}
|
|
3261
3294
|
|
|
3262
|
-
|
|
3295
|
+
/**
|
|
3296
|
+
* HOLD-UNTIL-CANNOT-SERVE (owner 2026-11-08). Returns null while the hold is live,
|
|
3297
|
+
* or the NAME of the gate that lets the conversation go. The hold survives the
|
|
3298
|
+
* weekly reserve (85%) and soft tiers and a high-but-not-walled 5-hour window: a
|
|
3299
|
+
* move costs one full re-store whenever it happens, so leaving early only spends
|
|
3300
|
+
* the re-store sooner. It releases only when the account truly cannot serve:
|
|
3301
|
+
* critical-no-unlock / exhausted / capped weekly, the 5h window at/over
|
|
3302
|
+
* cacheAffinityFiveHourWall, a failure streak, or Kimi's unreadable console-only
|
|
3303
|
+
* quota (nothing would ever release the hold before a 429). Availability gates
|
|
3304
|
+
* (cooldown, 429 bench, exclusion, in-flight cap) never reach here — the account
|
|
3305
|
+
* is not a candidate at all — so a throttled account releases on the very next request.
|
|
3306
|
+
*/
|
|
3307
|
+
_affinityRelease(account, criticalUnlock = null) {
|
|
3308
|
+
if (account.type === 'provider' && account.quota?.providerQuotaSource === 'console-only') return 'console-only';
|
|
3309
|
+
const weeklyState = this._weeklyRawState(account);
|
|
3310
|
+
if (weeklyState === 'critical') {
|
|
3311
|
+
if (!criticalUnlock) return 'critical-no-unlock';
|
|
3312
|
+
} else if (weeklyState === 'exhausted' || weeklyState === 'capped') {
|
|
3313
|
+
return `weekly-${weeklyState}`;
|
|
3314
|
+
}
|
|
3315
|
+
// 5-hour window: Anthropic reports unified5h; GLM/Kimi report providerSes.
|
|
3316
|
+
const five = account.type === 'provider' ? account.quota?.providerSes : account.quota?.unified5h;
|
|
3317
|
+
if (five != null && five >= this.scheduler.cacheAffinityFiveHourWall) return `5h-${five.toFixed(2)}`;
|
|
3318
|
+
const failures = account.consecutiveFailures || 0;
|
|
3319
|
+
if (failures > 0) return `failures-${failures}`;
|
|
3320
|
+
return null;
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
_cacheAffinity(account, requestInfo = {}, criticalUnlock = null) {
|
|
3263
3324
|
const base = Number(this.scheduler.cacheAffinityBonus) || 0;
|
|
3264
3325
|
// Sticky mode has its own binding; its score loop runs only once the session has
|
|
3265
3326
|
// decided to LEAVE a hot account — a discount there would pull it straight back.
|
|
@@ -3272,17 +3333,7 @@ export class AccountManager {
|
|
|
3272
3333
|
// the rest were 100K-500K-token conversations whose single in-flight turn
|
|
3273
3334
|
// already outweighed it. 1x below 150KB, rising to 3x at 450KB+.
|
|
3274
3335
|
const sizeMult = Math.min(3, Math.max(1, (requestInfo.bodyBytes || 0) / 150_000));
|
|
3275
|
-
|
|
3276
|
-
// release the hold before a 429; give such rows plain balancing (red-team r1).
|
|
3277
|
-
if (account.type === 'provider' && account.quota?.providerQuotaSource === 'console-only') return 0;
|
|
3278
|
-
const weeklyState = this._weeklyRawState(account);
|
|
3279
|
-
// Holds through 'soft' (≥65% weekly — most accounts by mid-week) and 'unknown'
|
|
3280
|
-
// (never probed); reserve/critical/exhausted/capped release the conversation.
|
|
3281
|
-
if (!['normal', 'soft', 'unknown'].includes(weeklyState)) return 0;
|
|
3282
|
-
// 5-hour window: Anthropic reports unified5h; GLM/Kimi report providerSes.
|
|
3283
|
-
const five = account.type === 'provider' ? account.quota?.providerSes : account.quota?.unified5h;
|
|
3284
|
-
if (five != null && five >= this.scheduler.weeklyReserveThreshold) return 0;
|
|
3285
|
-
if ((account.consecutiveFailures || 0) > 0) return 0;
|
|
3336
|
+
if (this._affinityRelease(account, criticalUnlock)) return 0;
|
|
3286
3337
|
// Scale to THIS row's price of one in-flight unit, so every account tolerates the
|
|
3287
3338
|
// same extra DEPTH (~33 units) — a fast-refill/soak-discounted GLM row prices a
|
|
3288
3339
|
// unit at ~0.4x, and an unscaled bonus let it run ~2.5x deeper (red-team r1).
|
|
@@ -3291,7 +3342,61 @@ export class AccountManager {
|
|
|
3291
3342
|
? this._fastRefillMultiplier(account, { capFloor: true }) : refillMult;
|
|
3292
3343
|
const unit = this.scheduler.concurrencyWeight * refillMult + this.scheduler.capPenaltyWeight * safetyMult;
|
|
3293
3344
|
const fullUnit = this.scheduler.concurrencyWeight + this.scheduler.capPenaltyWeight;
|
|
3294
|
-
|
|
3345
|
+
const bonus = base * sizeMult * Math.min(1, unit / fullUnit);
|
|
3346
|
+
// Anti-dogpile cap: never tolerate more than cacheAffinityMaxExtraDepth units of
|
|
3347
|
+
// extra depth at THIS row's unit price, however large the conversation or bonus.
|
|
3348
|
+
let maxExtra = Number(this.scheduler.cacheAffinityMaxExtraDepth);
|
|
3349
|
+
if (!Number.isFinite(maxExtra) || maxExtra < 0) return bonus;
|
|
3350
|
+
// A reserve (or unlocked-critical) account has the TIGHTER concurrency target; its
|
|
3351
|
+
// hold gets the same tightening so the hold never stretches the lowest-headroom tier
|
|
3352
|
+
// as far as a healthy one (reserveConcurrencyTarget / perAccountConcurrencyTarget).
|
|
3353
|
+
const wk = this._weeklyRawState(account);
|
|
3354
|
+
if (wk === 'reserve' || (wk === 'critical' && criticalUnlock)) {
|
|
3355
|
+
maxExtra *= Math.min(1, this.scheduler.reserveConcurrencyTarget / Math.max(1, this.scheduler.perAccountConcurrencyTarget));
|
|
3356
|
+
}
|
|
3357
|
+
return Math.min(bonus, maxExtra * unit);
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
/**
|
|
3361
|
+
* WHY a known conversation left its last account — one short string for the
|
|
3362
|
+
* `conversation moved:` log line. `released:<gate>` = the hold let go (the gate
|
|
3363
|
+
* names the reason, incl. availability causes); `outscored:` = the hold was live and
|
|
3364
|
+
* the sibling still won, with the dominant score terms that beat the bonus.
|
|
3365
|
+
*/
|
|
3366
|
+
_moveReason(lastName, best, requestInfo, excludedIndexes, scoringCtx, weeklyOptions, bestUnlock, now) {
|
|
3367
|
+
const last = this.accounts.find(a => a.name === lastName);
|
|
3368
|
+
if (!last) return 'released:account-gone';
|
|
3369
|
+
if (excludedIndexes.has(last.index)) return 'released:excluded';
|
|
3370
|
+
if (!this._matchesRequest(last, requestInfo.profile || 'claude', requestInfo)) return 'released:not-eligible';
|
|
3371
|
+
const unlock = weeklyOptions.allowWeeklyCritical ? null : this._criticalUnlock(last, requestInfo, excludedIndexes, null, now);
|
|
3372
|
+
const avail = { ...weeklyOptions, allowWeeklyCritical: weeklyOptions.allowWeeklyCritical || !!unlock, model: requestInfo.model, now };
|
|
3373
|
+
if (!this._isAvailable(last, avail)) return `released:unavailable(${this._unavailableCause(last, now)})`;
|
|
3374
|
+
const gate = this._affinityRelease(last, unlock);
|
|
3375
|
+
if (gate) return `released:${gate}`;
|
|
3376
|
+
if (this._effectivePriority(last, requestInfo, now) > this._effectivePriority(best, requestInfo, now)) return 'released:priority-tier';
|
|
3377
|
+
if (this._cacheAffinity(last, requestInfo, unlock) <= 0) return 'released:no-hold';
|
|
3378
|
+
const lt = this._scoreTerms(last, requestInfo, scoringCtx, unlock);
|
|
3379
|
+
const bt = this._scoreTerms(best, requestInfo, scoringCtx, bestUnlock);
|
|
3380
|
+
const sum = t => t.concurrency + t.capPenalty + t.paceCost + t.utilizationCost + t.scopedPace + t.spread + t.ramp + t.reserveCost + t.criticalCost + t.failurePenalty - t.affinity;
|
|
3381
|
+
const delta = sum(lt) - sum(bt);
|
|
3382
|
+
const diffs = ['concurrency', 'capPenalty', 'paceCost', 'utilizationCost', 'scopedPace', 'spread', 'ramp', 'reserveCost', 'criticalCost', 'failurePenalty', 'affinity']
|
|
3383
|
+
.map(k => [k, (k === 'affinity' ? -(lt[k] - bt[k]) : lt[k] - bt[k])])
|
|
3384
|
+
.filter(([, d]) => d > 0.05).sort((x, y) => y[1] - x[1]).slice(0, 2)
|
|
3385
|
+
.map(([k, d]) => `${k}+${d.toFixed(1)}`);
|
|
3386
|
+
return `outscored:${delta.toFixed(1)}(${diffs.join(',') || 'rank'};bonus=${lt.affinity.toFixed(0)};depth=${last.activeWeight}/${best.activeWeight})`;
|
|
3387
|
+
}
|
|
3388
|
+
|
|
3389
|
+
/** Short human cause for a not-available account (log text only). */
|
|
3390
|
+
_unavailableCause(account, now) {
|
|
3391
|
+
if (!account.enabled) return 'disabled';
|
|
3392
|
+
if (account.status === 'throttled' && account.rateLimitedUntil && now < account.rateLimitedUntil) return 'rate-limited';
|
|
3393
|
+
if (account.cooldownUntil && now < account.cooldownUntil) return 'cooldown';
|
|
3394
|
+
if (account.provisionalUpstreamUntil && now < account.provisionalUpstreamUntil) return 'upstream-failure';
|
|
3395
|
+
if (account.inFlight >= this.scheduler.safetyMaxActivePerAccount) return 'in-flight-cap';
|
|
3396
|
+
if (this._isSessionQuotaUnavailable(account, now)) return '5h-wall';
|
|
3397
|
+
const w = this._weeklyRawState(account, now);
|
|
3398
|
+
if (w !== 'normal' && w !== 'soft' && w !== 'unknown') return `weekly-${w}`;
|
|
3399
|
+
return account.status || 'other';
|
|
3295
3400
|
}
|
|
3296
3401
|
|
|
3297
3402
|
/**
|
package/src/index.js
CHANGED
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
RELOAD_SWAPPED, RELOAD_ROLLED_BACK,
|
|
52
52
|
MSG_LISTEN, MSG_RELEASE, MSG_TAKEOVER, MSG_PROBE_READY,
|
|
53
53
|
MSG_RELOAD_REQUEST, MSG_READY, MSG_FAILED, MSG_RELEASED, MSG_PRIMARY, MSG_ROLLED_BACK,
|
|
54
|
-
MSG_TTY_REASSERT,
|
|
54
|
+
MSG_TTY_REASSERT, MSG_CONN,
|
|
55
55
|
} from './reload-protocol.js';
|
|
56
56
|
|
|
57
57
|
const args = process.argv.slice(2);
|
|
@@ -222,12 +222,25 @@ async function supervisorCommand() {
|
|
|
222
222
|
|
|
223
223
|
// Bind once. EADDRINUSE / EACCES here is a cold-start failure → exit(1) is
|
|
224
224
|
// correct (there's no worker to keep alive yet).
|
|
225
|
-
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
// supervisor's
|
|
229
|
-
//
|
|
230
|
-
//
|
|
225
|
+
// pauseOnConnect: a socket the supervisor accepts must reach the worker with every
|
|
226
|
+
// byte still unread, so the supervisor never consumes the request it is relaying.
|
|
227
|
+
let masterServer = createServer({ pauseOnConnect: true });
|
|
228
|
+
// The supervisor's accept loop is LIVE from bind until a worker confirms it is the
|
|
229
|
+
// sole acceptor (MSG_PRIMARY), and again over the reload cutover gap. It shares the
|
|
230
|
+
// listening socket with the worker, so it WINS some accepts. A connection accepted
|
|
231
|
+
// here used to be left dangling (this server had no 'connection' handler): the client
|
|
232
|
+
// hung, then got ECONNRESET, and the request never reached any worker (the flaky
|
|
233
|
+
// reload-oauth-refresh test, 2026-11-08). Hand every such socket to the worker that
|
|
234
|
+
// is serving, or about to: `acceptTarget` (the incoming worker during a reload) else
|
|
235
|
+
// the active one. No live worker → close it so the client retries now, never hangs.
|
|
236
|
+
let acceptTarget = null;
|
|
237
|
+
masterServer.on('connection', sock => {
|
|
238
|
+
const target = acceptTarget || activeWorker;
|
|
239
|
+
if (!target || !target.child.connected) { sock.destroy(); return; }
|
|
240
|
+
try {
|
|
241
|
+
target.child.send({ type: MSG_CONN }, sock, err => { if (err) sock.destroy(); });
|
|
242
|
+
} catch { sock.destroy(); }
|
|
243
|
+
});
|
|
231
244
|
const relistenMaster = (retriesOnBusy = 20) => new Promise((resolve, reject) => {
|
|
232
245
|
if (masterServer.listening) { resolve(); return; }
|
|
233
246
|
const onListen = () => { masterServer.removeListener('error', onErr); resolve(); };
|
|
@@ -246,6 +259,14 @@ async function supervisorCommand() {
|
|
|
246
259
|
masterServer.once('listening', onListen);
|
|
247
260
|
masterServer.listen(port, host);
|
|
248
261
|
});
|
|
262
|
+
// What goes over IPC to a worker: the RAW listening handle, not the net.Server wrapper.
|
|
263
|
+
// Sent as a net.Server, Node builds an intermediate net.Server in the worker that
|
|
264
|
+
// listen()s on it and ACCEPTS whatever is already queued before user code can attach
|
|
265
|
+
// a listener (measured: with 8 connections queued, the worker's HTTP server got 0-5
|
|
266
|
+
// and the rest sat unread in that intermediate server, black-holed). The raw handle
|
|
267
|
+
// has no such wrapper: the worker's http.Server listen()s on it directly.
|
|
268
|
+
// Falls back to the wrapper if a future Node hides the handle (old behaviour).
|
|
269
|
+
const masterHandle = () => masterServer._handle || masterServer;
|
|
249
270
|
const closeMasterAccept = () => new Promise(resolve => {
|
|
250
271
|
if (!masterServer.listening) { resolve(); return; }
|
|
251
272
|
masterServer.close(() => resolve());
|
|
@@ -327,7 +348,7 @@ async function supervisorCommand() {
|
|
|
327
348
|
const worker = makeWorkerChannel(child);
|
|
328
349
|
if (!reload) {
|
|
329
350
|
// Cold start: hand the socket and tell it to go primary immediately.
|
|
330
|
-
worker.send({ type: MSG_LISTEN },
|
|
351
|
+
worker.send({ type: MSG_LISTEN }, masterHandle());
|
|
331
352
|
}
|
|
332
353
|
return worker;
|
|
333
354
|
};
|
|
@@ -373,11 +394,13 @@ async function supervisorCommand() {
|
|
|
373
394
|
const outcome = await runReloadBaton({
|
|
374
395
|
oldWorker,
|
|
375
396
|
newWorker,
|
|
376
|
-
handle:
|
|
397
|
+
handle: masterHandle(),
|
|
377
398
|
// After the OLD worker has released its fd, re-arm the supervisor's own
|
|
378
399
|
// listener to cover the cutover gap, then hand THAT live handle to the
|
|
379
400
|
// new worker. The new worker's MSG_PRIMARY then closes it again.
|
|
380
|
-
|
|
401
|
+
// The old worker has released, so gap-accepted connections now belong to the
|
|
402
|
+
// incoming worker (before this point the still-serving old one is the target).
|
|
403
|
+
prepareHandle: async () => { acceptTarget = newWorker; await relistenMaster(); return masterHandle(); },
|
|
381
404
|
// Generous, env-tunable readiness/takeover budgets — the 10s default rolled back
|
|
382
405
|
// on this user's loaded Mac (the update never landed). See RELOAD_READY_MS.
|
|
383
406
|
readyTimeoutMs: RELOAD_READY_MS,
|
|
@@ -427,6 +450,7 @@ async function supervisorCommand() {
|
|
|
427
450
|
activeWorker = null;
|
|
428
451
|
endTurn?.({ code: null, signal: 'SIGKILL', fallback: true });
|
|
429
452
|
} finally {
|
|
453
|
+
acceptTarget = null;
|
|
430
454
|
reloadInFlight = false;
|
|
431
455
|
}
|
|
432
456
|
};
|
|
@@ -1564,6 +1588,11 @@ async function serverWorkerCommand() {
|
|
|
1564
1588
|
// never sit alive-but-not-primary (the blank-screen `r`-restart hang).
|
|
1565
1589
|
console.error('[Maxpool] Cold worker received MSG_LISTEN with no socket handle — exiting for respawn.');
|
|
1566
1590
|
process.exit(SERVER_RESTART_EXIT_CODE);
|
|
1591
|
+
} else if (msg?.type === MSG_CONN) {
|
|
1592
|
+
// A connection the supervisor's own accept loop won the race for (cold start
|
|
1593
|
+
// before MSG_PRIMARY, or the reload cutover gap). Serve it exactly as if we
|
|
1594
|
+
// had accepted it: http.Server wires up on the 'connection' event.
|
|
1595
|
+
if (handle) { handle.resume?.(); server.emit('connection', handle); }
|
|
1567
1596
|
} else if (msg?.type === MSG_PROBE_READY) {
|
|
1568
1597
|
// Headless reload worker: we've booted the new code and restored quota
|
|
1569
1598
|
// in memory. Confirm readiness (we are NOT yet accepting / writing).
|
package/src/reload-protocol.js
CHANGED
|
@@ -30,6 +30,7 @@ export const MSG_FAILED = 'failed'; // worker failed to boot/bind/restore
|
|
|
30
30
|
export const MSG_RELEASED = 'released'; // old worker stopped accepting + writing, flushed
|
|
31
31
|
export const MSG_PRIMARY = 'primary'; // new worker is now sole acceptor + lease holder
|
|
32
32
|
export const MSG_QUOTA_STATE = 'quota-state'; // old worker hands its in-memory quota to supervisor
|
|
33
|
+
export const MSG_CONN = 'conn'; // (with socket) supervisor-accepted connection handed to a worker to serve
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Outcome codes for a reload attempt, surfaced to the supervisor so it can log
|