maxpool 1.5.6 → 1.5.7
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 +9 -5
- package/src/config.js +19 -2
- package/src/index.js +7 -2
- package/src/prober.js +6 -5
package/package.json
CHANGED
package/src/account-manager.js
CHANGED
|
@@ -1432,11 +1432,15 @@ export class AccountManager {
|
|
|
1432
1432
|
|
|
1433
1433
|
const ramp = this._recoveryRamp(account, now);
|
|
1434
1434
|
const failurePenalty = account.consecutiveFailures * 5;
|
|
1435
|
-
//
|
|
1436
|
-
//
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1435
|
+
// NO unknown-quota bonus. An account whose quota we cannot see must never be
|
|
1436
|
+
// MORE attractive than a known-healthy one — the old -0.5 nudge (safe only
|
|
1437
|
+
// while the prober quickly resolved "unknown") turned into a relentless pull
|
|
1438
|
+
// toward blind accounts once probing was off, driving an out-of-band-burned
|
|
1439
|
+
// account to exhaustion. Unknown now scores neutral; the prober (on by
|
|
1440
|
+
// default) learns the real number within a cycle. `probing`/requalify still
|
|
1441
|
+
// flags a never-seen account for learning — that path is unchanged.
|
|
1442
|
+
|
|
1443
|
+
return concurrency + capPenalty + paceCost + spread + ramp + failurePenalty;
|
|
1440
1444
|
}
|
|
1441
1445
|
|
|
1442
1446
|
/**
|
package/src/config.js
CHANGED
|
@@ -62,7 +62,11 @@ export function createDefaultConfig() {
|
|
|
62
62
|
// Raise toward 0.97 to squeeze more out of accounts before rotating
|
|
63
63
|
// (less margin, slightly higher 429 risk); lower to rotate more eagerly.
|
|
64
64
|
switchThreshold: 0.90,
|
|
65
|
-
|
|
65
|
+
// Background quota probe: poll every account's real 5h/7d utilization from the
|
|
66
|
+
// zero-spend usage endpoint every N seconds. ON by default — without it maxpool
|
|
67
|
+
// is blind to idle / out-of-band-used accounts and the scorer will pile traffic
|
|
68
|
+
// onto exactly the account it cannot see. 0 = off.
|
|
69
|
+
quotaProbeSeconds: 60,
|
|
66
70
|
routing: {
|
|
67
71
|
mode: 'automatic',
|
|
68
72
|
preferredAccount: null,
|
|
@@ -135,8 +139,9 @@ export async function loadConfig() {
|
|
|
135
139
|
if (err.code === 'ENOENT') return null;
|
|
136
140
|
throw err;
|
|
137
141
|
}
|
|
142
|
+
let parsed;
|
|
138
143
|
try {
|
|
139
|
-
|
|
144
|
+
parsed = JSON.parse(raw);
|
|
140
145
|
} catch (err) {
|
|
141
146
|
// With atomic temp+rename writes a torn read is impossible, so a parse
|
|
142
147
|
// failure means genuine corruption. Surface it clearly rather than as a
|
|
@@ -144,6 +149,18 @@ export async function loadConfig() {
|
|
|
144
149
|
// the file with defaults and lose recoverable OAuth credentials.
|
|
145
150
|
throw new Error(`config at ${path} is not valid JSON (corrupt?): ${err.message}`);
|
|
146
151
|
}
|
|
152
|
+
// Backfill top-level keys ABSENT from an older on-disk config with the current
|
|
153
|
+
// defaults, so a changed default (e.g. quotaProbeSeconds flipping on) actually
|
|
154
|
+
// reaches existing installs instead of shipping inert. A key that is present —
|
|
155
|
+
// even falsy, like an explicit `0` — is an intentional user choice and always
|
|
156
|
+
// wins; only genuinely-missing keys inherit the default.
|
|
157
|
+
if (parsed && typeof parsed === 'object') {
|
|
158
|
+
const defaults = createDefaultConfig();
|
|
159
|
+
for (const key of Object.keys(defaults)) {
|
|
160
|
+
if (!(key in parsed)) parsed[key] = defaults[key];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return parsed;
|
|
147
164
|
}
|
|
148
165
|
|
|
149
166
|
export async function loadOrCreateConfig() {
|
package/src/index.js
CHANGED
|
@@ -530,8 +530,13 @@ async function serverWorkerCommand() {
|
|
|
530
530
|
// Persist quota every minute; unref so it never keeps the process alive.
|
|
531
531
|
let quotaSaveInterval = null;
|
|
532
532
|
|
|
533
|
-
//
|
|
534
|
-
|
|
533
|
+
// Background quota probe (config.quotaProbeSeconds, default 60s). Keeps every
|
|
534
|
+
// account's real 5h/7d utilization fresh so the scorer is never blind to an idle
|
|
535
|
+
// or out-of-band-used account. MAXPOOL_DISABLE_QUOTA_PROBE=1 forces it off — used
|
|
536
|
+
// by spawned integration tests so a startup probe can't race their refresh/rotation
|
|
537
|
+
// assertions (mirrors MAXPOOL_DISABLE_SLEEP_GUARD).
|
|
538
|
+
const probeSeconds = process.env.MAXPOOL_DISABLE_QUOTA_PROBE === '1' ? 0 : (config.quotaProbeSeconds || 0);
|
|
539
|
+
const prober = new Prober(accountManager, { intervalMs: probeSeconds * 1000 });
|
|
535
540
|
|
|
536
541
|
// Persist refreshed tokens back to config. Defense-in-depth: the updater reads
|
|
537
542
|
// the on-disk refresh token and SKIPS the rotation if a fresher writer already
|
package/src/prober.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Background quota probe.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// ON BY DEFAULT (config.quotaProbeSeconds, default 60s; 0 = off). Periodically
|
|
4
4
|
// reads each OAuth account's quota from the zero-spend /api/oauth/usage endpoint
|
|
5
|
-
// so idle accounts' utilization/reset stay fresh without waiting
|
|
6
|
-
// to — and without consuming any message quota.
|
|
7
|
-
//
|
|
5
|
+
// so idle / out-of-band-used accounts' utilization/reset stay fresh without waiting
|
|
6
|
+
// to be rotated to — and without consuming any message quota. Without it the scorer
|
|
7
|
+
// is blind to an account it isn't actively routing to and will pile traffic onto it.
|
|
8
|
+
// This is the one sanctioned active-upstream feature; the proxy is otherwise passive.
|
|
8
9
|
|
|
9
10
|
import { fetchUsage } from './oauth.js';
|
|
10
11
|
|