maxpool 1.24.53 → 1.24.55

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.53",
3
+ "version": "1.24.55",
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",
@@ -4762,6 +4762,35 @@ export class AccountManager {
4762
4762
  this.applyPoolLinks();
4763
4763
  }
4764
4764
 
4765
+ /** Boot-time single-writer guard: seed each link's persisted identity map
4766
+ * (state.json) so a boot during a link outage keeps local copies benched
4767
+ * until the first successful poll (red-team 2026-10-31). */
4768
+ seedPoolLinks(saved, savedAt) {
4769
+ if (!saved || typeof saved !== 'object') return;
4770
+ for (const l of this.poolLinks) {
4771
+ const byName = saved[l.name];
4772
+ if (byName) l.seedPoolIdentities?.(byName, savedAt);
4773
+ }
4774
+ this.applyPoolLinks();
4775
+ }
4776
+
4777
+ /** When these identities were last CONFIRMED by a good poll (a seed keeps its own
4778
+ * age, so the expiry in seedPoolIdentities can actually fire in a long outage). */
4779
+ poolIdentitiesAt() {
4780
+ const times = this.poolLinks.map(l => l.lastOkAt ?? l._seedAt ?? 0);
4781
+ return times.length ? Math.max(...times) : null;
4782
+ }
4783
+
4784
+ /** Per-link identity maps for state.json (keyed by link name). */
4785
+ exportPoolIdentities() {
4786
+ const out = {};
4787
+ for (const l of this.poolLinks) {
4788
+ const ids = l.exportPoolIdentities?.();
4789
+ if (ids) out[l.name] = ids;
4790
+ }
4791
+ return Object.keys(out).length ? out : null;
4792
+ }
4793
+
4765
4794
  /** Apply duplicate benching + link health from the links' last polls. Idempotent. */
4766
4795
  applyPoolLinks() {
4767
4796
  const ids = new Map();
@@ -4774,6 +4803,25 @@ export class AccountManager {
4774
4803
  for (const a of this.accounts) {
4775
4804
  const wasBenched = Boolean(a.poolBenchedBy);
4776
4805
  const d = dups.find(x => x.index === a.index);
4806
+ // Token-divergence alarm (red-team 2026-10-31): the cloud row for this
4807
+ // identity is refreshDead while the local copy holds a healthy credential —
4808
+ // both sides went dark in the boot-outage scenario. Name it loudly instead
4809
+ // of silently benching the only working copy.
4810
+ if (d) {
4811
+ const remoteRow = (this.poolLinks || [])
4812
+ .flatMap(l => (l.status?.accounts || []).filter(r => r.name === d.remoteName))[0];
4813
+ if (remoteRow?.refreshDead && !a.refreshDead && a.refreshToken) {
4814
+ // Once per episode: this runs on every 30s poll.
4815
+ if (!a._divergenceLogged) {
4816
+ a._divergenceLogged = true;
4817
+ const msg = `[Maxpool] Token divergence: team pool's "${d.remoteName}" needs login while local "${a.name}" still has a stored token — log in again on that row, or the account stays unavailable on both sides`;
4818
+ console.log(msg);
4819
+ appendEventLog(msg);
4820
+ }
4821
+ } else {
4822
+ a._divergenceLogged = false;
4823
+ }
4824
+ }
4777
4825
  a.poolBenchedBy = d ? (d.remoteName || 'team pool') : null;
4778
4826
  if (d && !wasBenched) {
4779
4827
  console.log(`[Maxpool] Duplicate guard: local account "${a.name}" also lives in team pool (${a.poolBenchedBy}) — benched locally, no routing, no token refresh`);
package/src/index.js CHANGED
@@ -703,6 +703,10 @@ async function serverWorkerCommand() {
703
703
  // as its own row (syncRemoteMirrors on every link poll) and balanced with the
704
704
  // local accounts by the unchanged routing logic.
705
705
  accountManager.setPoolLinks(links);
706
+ // Boot-time single-writer guard: seed from the last persisted run in the SAME
707
+ // tick as setPoolLinks, before the first poll or probe can run. Links must exist
708
+ // first (a seed above this point looped over an empty list and did nothing).
709
+ accountManager.seedPoolLinks(savedState?.poolIdentities, savedState?.poolIdentitiesAt);
706
710
  const armed = links.filter(l => l.key).length;
707
711
  console.log(`[Maxpool] Team pools: ${armed} linked${links.length - armed ? `, ${links.length - armed} unresolved key` : ''}`);
708
712
  } catch (err) {
@@ -747,6 +751,10 @@ async function serverWorkerCommand() {
747
751
  // SC22 per-person analytics — same generation-guarded payload, survives
748
752
  // restarts and seamless reloads.
749
753
  callerStats: accountManager.exportCallerStats?.() || {},
754
+ // Last-good remote identity maps — the boot-time single-writer guard reads
755
+ // these (see restore above). Rides the same generation-guarded payload.
756
+ poolIdentities: accountManager.exportPoolIdentities?.() || null,
757
+ poolIdentitiesAt: accountManager.poolIdentitiesAt?.() ?? null,
750
758
  },
751
759
  { expectedGeneration },
752
760
  )
package/src/pool-link.js CHANGED
@@ -149,14 +149,28 @@ function sanitizeRemoteStatus(json) {
149
149
  for (const a of Array.isArray(p.accounts) ? p.accounts : []) if (a && typeof a === 'object') a.name = safeText(a.name);
150
150
  }
151
151
  }
152
- if (json.callers && typeof json.callers === 'object') {
153
- const clean = {};
154
- for (const [k, v] of Object.entries(json.callers)) clean[safeText(k)] = v;
155
- json.callers = clean;
152
+ // Person names key both maps; the People page reads callerWindows.
153
+ for (const field of ['callers', 'callerWindows']) {
154
+ if (json[field] && typeof json[field] === 'object') {
155
+ const clean = {};
156
+ for (const [k, v] of Object.entries(json[field])) clean[safeText(k)] = v;
157
+ json[field] = clean;
158
+ }
156
159
  }
157
160
  return json;
158
161
  }
159
162
 
163
+ /**
164
+ * Boot-time single-writer guard (red-team 2026-10-31, blocking): a fresh PoolLink
165
+ * starts with EMPTY identities, so a boot during a link outage saw ids={} and the
166
+ * duplicate guard RELEASED every local copy — which then served and rotated tokens
167
+ * the cloud still held (invalid_grant on the cloud row when the link returned; the
168
+ * healthy local copy re-benched → account dark on BOTH sides). The last good
169
+ * identity map is persisted in state.json; seedPoolIdentities() restores it at boot
170
+ * so a link that hasn't polled yet still benches what it benched last run.
171
+ */
172
+ const BOOT_IDS_TTL_MS = 14 * 24 * 3600 * 1000; // stale beyond this → trust a fresh boot instead
173
+
160
174
  export class PoolLink {
161
175
  constructor(def, deps = {}) {
162
176
  this.name = def.name;
@@ -176,6 +190,25 @@ export class PoolLink {
176
190
  this.summary = null;
177
191
  }
178
192
 
193
+ /** Seed identities persisted from a previous run (state.json). Used until the
194
+ * first successful poll replaces them; old seeds (>14d) are ignored. */
195
+ seedPoolIdentities(saved, savedAt) {
196
+ if (!saved || typeof saved !== 'object') return;
197
+ if (savedAt != null && Date.now() - savedAt > BOOT_IDS_TTL_MS) return;
198
+ if (this.identities && this.identities.size > 0) return; // a real poll already ran
199
+ const m = new Map(Object.entries(saved).map(([k, v]) => [k, v]));
200
+ if (m.size > 0) {
201
+ this.identities = m;
202
+ this._seedAt = savedAt ?? null;
203
+ }
204
+ }
205
+
206
+ /** Identity map for persistence (plain object). */
207
+ exportPoolIdentities() {
208
+ return this.identities && this.identities.size > 0
209
+ ? Object.fromEntries(this.identities) : null;
210
+ }
211
+
179
212
  async poll() {
180
213
  if (this._polling) return; // never stack polls
181
214
  this._polling = true;
package/src/prober.js CHANGED
@@ -333,7 +333,9 @@ export class Prober {
333
333
  // Claude banked resets (cedar_ember) piggyback on the oauth poll — same
334
334
  // OWNER GATE as z.ai cards: a DISABLED account is never listed or claimed.
335
335
  try {
336
- if (account.enabled !== false && account.credential && this.am.applyResetGrants) {
336
+ // A pool-benched duplicate never claims a grant: the cloud owns this account
337
+ // (mirror of the z.ai card guard above; red-team 2026-10-31).
338
+ if (account.enabled !== false && account.credential && !account.poolBenchedBy && this.am.applyResetGrants) {
337
339
  const listing = await this._withTimeout(this.grantsFn(account.credential));
338
340
  if (listing) {
339
341
  this.am.applyResetGrants(account.index, listing);