Hub switch-on (Marty 2026-11-14). Rule 2: a hub arrival gets person.locks.linkspin's sponsor when the LinkSpin contract holds them, never the plain network sponsor; sponsor.changed stays ignored. Quiet: a wallet filled from a hub event never switches payouts on (isQuiet: no gas, no lock, no 'payouts are switched on' mail). Rule 3: the holding tank (waiting, release, expiry, rescue, readyTick, autoAssign) leaves out anyone the hub reports locked on any contract or sponsored, and hub waiting copies that never signed in here; /v1/locked detail cached 10 min, last answer kept 1 h, after that held (unknown). Alignment to the hub sponsor only with HUB_TANK_ALIGN=on. Needs network-hub b44dba6. hubsync 15 checks, sponsorfollow 30/30, tank-cap 15/15, networksso ALL PASSED, tank-hold, carry-hold ok

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 08:45:43 -06:00
parent 5fbaf4f17d
commit 42cbe96979
4 changed files with 212 additions and 19 deletions
+37 -3
View File
@@ -86,11 +86,28 @@ const countAll = async email => (await impl().countFor(email)) + remoteCount(ema
const mask = e => String(e || '').replace(/^(.).*(@.*)$/, '$1***$2');
const nameOf = a => a.username ? '@' + a.username : (a.memberId ? 'member #' + a.memberId : mask(a.email));
const inTank = a => !a.sponsorRef && !a.memberId; // arrived with no sponsor (or fell back), still free
// Rule 3 (Marty 2026-11-14): never offer anyone locked on ANY network contract or whom the network hub already knows a sponsor
// for, nor a waiting copy the hub made here for someone who never signed in here (their own door's tank has them).
// hooks.networkHeld = hubsync.heldAmong, wired only with HUB_ENABLED. A hook that throws holds everyone it was asked about:
// the conservative side. No hook (flag off, tests) = nothing held, the tank as before.
const lc = v => String(v || '').trim().toLowerCase();
async function heldSet(accts) {
if (!hooks.networkHeld || !accts.length) return new Map();
try { return (await hooks.networkHeld(accts)) || new Map(); } catch (e) { console.error('tank networkHeld', e.message); return new Map(accts.map(a => [lc(a.email), 'unknown'])); }
}
const HELD_WHY = { locked: 'they are locked on a network contract', sponsored: 'it already knows a sponsor for them', unknown: 'nothing (it is not answering)', 'hub-shell': 'they are a waiting copy from another door and never signed in here' };
// release / rescue / expiry: 'locked' | 'unknown' | null (hooks.networkLocked = hubsync.lockedAnywhere)
async function lockedWhy(email) {
if (!hooks.networkLocked) return null;
try { return (await hooks.networkLocked(email)) || null; } catch (e) { return 'unknown'; }
}
// waiting list: newest sign-in first so a live one is easy to spot
async function waiting() {
const all = await accounts.listAll(1e6); // was 2000: newest-first, so once the site passed 2000 accounts (BTC4Hits import 2026-11-11) older tank members fell off the list
return all.filter(a => inTank(a) && !remoteOpen(a.email)).map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, wallet: !!a.address,
const cand = all.filter(a => inTank(a) && !remoteOpen(a.email));
const held = await heldSet(cand); // rule 3: locked or sponsored elsewhere
return cand.filter(a => !held.has(lc(a.email))).map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, wallet: !!a.address,
// wallet linked = ready to switch on payouts, the plain activation held for an adopter (24-hour clock, autoAssign after that)
opensAt: inGrace(a) ? graceEnd(a) : 0, // new sign-up: nobody can adopt them by hand before this (0 = open now)
...(() => { const r = a.address ? readyRec(a.email) : null; return r ? { ready: true, readyAt: r.readyAt, holdUntil: r.readyAt + READY_MS } : { ready: false }; })() }))
@@ -183,6 +200,8 @@ async function release(ownerEmail, directEmail) {
const toks = [owner.code, owner.username, owner.memberId ? String(owner.memberId) : null].filter(Boolean).map(String);
if (!toks.includes(String(direct.sponsorRef || ''))) return { error: 'That member is not in your line.' };
if (direct.memberId) return { error: 'That member has already bought; on-chain sponsorship cannot move.' };
const lk = await lockedWhy(d); // rule 3: someone a network contract holds never goes to the tank
if (lk) return { error: lk === 'locked' ? nameOf(direct) + ' is locked to a sponsor on a network contract, so they cannot go to the holding tank.' : 'The network record for ' + nameOf(direct) + ' cannot be checked right now. Try again in a few minutes.' };
// picked up from the tank recently? then it is not theirs to drop yet (Bradley churned three in 80 seconds, 2026-09-13)
const openAds = (await impl().open(null)).filter(ad => ad.adoptee === d);
let young = openAds.find(ad => Date.now() - ad.ts < HOLD_MS);
@@ -213,6 +232,9 @@ async function sweep() {
if (!a) { await impl().setStatus(ad.id, 'expired'); continue; }
if (a.address || a.memberId) { await impl().setStatus(ad.id, 'done'); done++; continue; }
if (await impl().countFor(ad.adoptee) >= MAX_ADOPTIONS) { await impl().setStatus(ad.id, 'expired'); kept++; continue; }
const lk = await lockedWhy(ad.adoptee); // rule 3: a person a network contract holds stays with the adopter, never back in the tank
if (lk === 'unknown') continue; // the hub is not answering: try again next hour
if (lk === 'locked') { await impl().setStatus(ad.id, 'expired'); kept++; continue; }
await setSponsor(ad.adoptee, '', 'expire', 'adoption window ended');
await impl().setStatus(ad.id, 'expired'); back++;
}
@@ -281,11 +303,14 @@ async function rescueSweep() {
if (String(process.env.TANK_RESCUE || '').trim() !== 'on') return { warned: 0, rescued: 0, dead: 0, off: true };
const now = Date.now();
let warned = 0, rescued = 0, dead = 0;
for (const a of await accounts.listAll(5000)) {
const all = await accounts.listAll(5000);
await heldSet(all.filter(a => !a.memberId && !a.address && a.sponsorRef)); // one batched hub call warms the cache for lockedWhy below
for (const a of all) {
if (a.memberId || a.address || !a.sponsorRef) continue; // bound, wallet, or already in the tank
if (await impl().hasRecord(a.email)) continue; // adopted / rescued before: the tank's window rules
const pv = store && store.get(a.email);
if (remoteCount(a.email) || (pv && pv.by !== 'admin')) continue; // adopted / released / rescued on InstantAdPay: the tank's window rules there
if (await lockedWhy(a.email)) continue; // rule 3: locked on a network contract (or the hub is not answering): no warning, no move
const sp = await sponsorOf(a);
if (!sp) { // dead sponsor link: nobody can ever coach them, straight to the tank after a day
if (now - (a.created || 0) < 86400000) continue;
@@ -412,7 +437,7 @@ async function alignToNetwork(a, opts) {
const fresh = await accounts.byEmail(e); if (!fresh || !inTank(fresh)) return null;
const r = await accounts.setSponsorRef(e, token); if (r && r.error) return null;
const st = RS.load(); const via = n.via || 'same email';
const why = 'aligned to network sponsor ' + nameOf(sp) + ' from InstantAdPay (' + via + ')';
const why = 'aligned to network sponsor ' + nameOf(sp) + (/hub/.test(via) ? ' (' + via + ')' : ' from InstantAdPay (' + via + ')');
st.aligned.push({ email: e, to: sp.email, toName: nameOf(sp), via, at: clock(), why });
if (st.aligned.length > 300) st.aligned = st.aligned.slice(-300);
if (st.ready[e] && !st.ready[e].done) { st.ready[e].done = clock(); st.ready[e].aligned = sp.email; }
@@ -482,8 +507,14 @@ async function autoAssignRun() {
due.push([e, rec, a]);
}
due.sort((x, y) => x[1].readyAt - y[1].readyAt);
const netHeld = await heldSet(due.map(x => x[2]));
let pool = null;
for (const [e, rec, a] of due) {
if (netHeld.has(e)) { // rule 3: never auto-assigned; the admin hears once (their network sponsor has no usable account here yet, or the hub is not answering)
out.held++;
if (!rec.networkHeldAlerted) { rec.networkHeldAlerted = clock(); RS.save(); if (hooks.adminAlert && await claimOnce('tanknetheld:' + e + ':' + rec.readyAt)) { try { await hooks.adminAlert('LinkSpin holding tank: ' + nameOf(a) + ' (' + e + ') is held and NOT auto-assigned: the network hub says ' + (HELD_WHY[netHeld.get(e)] || netHeld.get(e)) + ', and no sponsor for them could be used here. Set their sponsor in Admin if it should be someone here.'); } catch (err) {} } }
continue;
}
// the double-assign guard: InstantAdPay holds this person in its own tank, so its safety net assigns them (asked fresh)
if (hooks.iapOwns && await Promise.resolve(hooks.iapOwns(e, { fresh: true })).catch(() => false)) { out.deferred++; if (!rec.deferred) { rec.deferred = clock(); RS.save(); } continue; }
if (!(await claimOnce('tankauto:' + e + ':' + Math.floor(clock() / 600000)))) continue; // the other app copy (deploy overlap) has this one
@@ -522,9 +553,12 @@ async function readyTick() {
const st = RS.load(); const fresh = []; let aligned = 0;
const tankers = (await accounts.listAll(5000)).filter(inTank);
if (hooks.prefetch) { try { await hooks.prefetch(tankers.map(a => a.email)); } catch (e) {} } // one signed batch call to InstantAdPay, not one per member
const netHeld = await heldSet(tankers); // one batched hub call; alignToNetwork below reads the same cache
for (const a of tankers) {
if (netHeld.get(lc(a.email)) === 'hub-shell') continue; // a waiting copy from another door: no alignment, no payouts switch-on here (quiet)
if (await alignToNetwork(a).catch(() => null)) { aligned++; continue; }
if (remoteOpen(a.email)) continue;
if (netHeld.has(lc(a.email))) continue; // rule 3: not announced, no 24-hour clock while the network holds them
const rec = markReady(a);
// Sign-up grace (2026-11-07): no "adopt them" post for someone who cannot be adopted yet; announced when the grace ends,
// and not at all when the safety net takes them in this same tick (nothing left for anyone to do)