Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(x402): scan ring wallets by tier under a lock and a budget, fix a wallet-identity bug that zeroed out leak detection
nirholasf6dcafb23ad9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 22a493451..8795dde96 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr- **Sentiment Scout's X reads gained a second, independent path through xAI**: The Sentiment Scout reads X for posts quoting a coin's exact contract address, as evidence a holder can open and check. When our own X search credentials are unavailable or rate limited, it now fails over to xAI's x_search tool, a second route to the same posts, metered by its own daily cap so an outage on one path never silently costs more than planned on the other. No change for anyone reading the Scout: the evidence looks the same either way. (`/docs/sentiment-scout`) `[improvement, infra]`- **Share a finished Forge creation on X and it plays inline**: A link to a finished Forge creation now carries an X player card instead of a flat image: the post expands into the real 3D model, posed with its own poster frame and ready to orbit, through the same safe embed runtime the agent-profile embeds use (no audio or video element, HTTPS assets only). A creation that is still generating keeps the plain image card until it finishes, so a link never promises a model that isn't ready yet. (`/forge`) `[feature]`- **The @-mention reply bot now reports its own status, and /grok shows it live**: A new public endpoint, /api/x/mention-bot/status, answers whether the @-mention reply bot is live, in dry run, or paused, how many handles it has replied on, how many replies it sent in the last 24 hours, and its median reply time. No mention text or author identity is included. The /grok page now shows this as a live section, and /api/healthz carries the same signal as a platform subsystem, so an operator sees a wedged reply queue or a rising error rate within the hour it starts, instead of the bot quietly going silent with no signature anywhere. (`/grok`) `[feature, improvement]`+- **The on-chain leak alarm now scans smarter instead of scanning everything**: The background monitor that watches every platform-controlled Solana wallet for a leak now checks the handful of wallets that hold real balances every run, any wallet the platform's own payment ledger shows just moved money, and the rest of the registry in a rotation, instead of walking the full wallet list on every single pass. That cuts the monitor's own Solana RPC usage sharply, which means faster balance reads and snappier agent pages across the platform, and it no longer runs two overlapping schedules at once. A wallet-identity bug found along the way is fixed too: on-chain transactions were being matched by the wrong field shape, which silently kept both the leak detector and its fee-accounting cross-check from recording anything real. Both now work correctly. `[infra, fix]`## 2026-10-10diff --git a/api/_lib/migrations/20261011230000_x402_ring_scan_checked_at.sql b/api/_lib/migrations/20261011230000_x402_ring_scan_checked_at.sqlnew file mode 100644index 000000000..7223f949e--- /dev/null+++ b/api/_lib/migrations/20261011230000_x402_ring_scan_checked_at.sql@@ -0,0 +1,17 @@+-- x402_ring_scan_cursor.checked_at: when a wallet was last ATTEMPTED, distinct+-- from updated_at which only moves when a cursor actually advances (new+-- signatures found). The ring leak scanner (api/cron/x402-ring-leak-scan.js)+-- walks its registry oldest-checked_at-first so every enabled wallet is+-- guaranteed a scan at least once per rotation even when it has zero activity+-- forever; without a column that moves on a zero-signature run, those wallets+-- would sort to the front on every single run and starve the ones with real+-- cursor advances. api/cron/x402-ring-leak-scan.js ensureSchema() applies the+-- same ALTER idempotently for a fresh database.++ALTER TABLE x402_ring_scan_cursor ADD COLUMN IF NOT EXISTS checked_at timestamptz;++CREATE INDEX IF NOT EXISTS x402_ring_scan_cursor_checked_at+ ON x402_ring_scan_cursor (checked_at NULLS FIRST);++COMMENT ON COLUMN x402_ring_scan_cursor.checked_at IS+ 'Last time this wallet was scanned, including zero-signature runs. Drives the oldest-first rotation order.';diff --git a/api/cron/economy-tick.js b/api/cron/economy-tick.jsindex 87a21d4a9..9c163074a 100644--- a/api/cron/economy-tick.js+++ b/api/cron/economy-tick.js@@ -52,7 +52,14 @@ const TARGETS = [{ label: 'x402-autonomous', path: '/api/cron/x402-autonomous-loop', method: 'GET' },// Fresh-wallet workers: brand-new payer wallets buying real work every minute.{ label: 'fresh-workers', path: '/api/cron/x402-fresh-workers', method: 'GET' },- { label: 'ring-leak-scan', path: '/api/cron/x402-ring-leak-scan', method: 'GET' },+ // ring-leak-scan is deliberately NOT a target (removed 2026-10-11): it has its+ // own */10 Cloud Scheduler job, and firing it from this every-minute tick as+ // well left zero gap between runs: with a 2,006-wallet registry and no lock+ // at the time, production ran about eight overlapping full scans at once,+ // burning the Solana RPC quota every other read depends on (see order+ // prompts/finish/400-auto-ring-leak-scan-rpc-burn.md). The scanner now also+ // holds its own lease (acquireLock) so a second caller is cheap, but there is+ // still no reason to fire it 6x more often than its own schedule.{ label: 'wallets-leak-scan', path: '/api/cron/wallets-leak-scan', method: 'GET' },{ label: 'distribute-payments', path: '/api/cron/run-distribute-payments', method: 'GET' },{ label: 'payment-session-sweep', path: '/api/cron/payment-session-sweep', method: 'GET' },diff --git a/api/cron/wallets-leak-scan.js b/api/cron/wallets-leak-scan.jsindex b74546b8b..699a0c5ac 100644--- a/api/cron/wallets-leak-scan.js+++ b/api/cron/wallets-leak-scan.js@@ -19,6 +19,7 @@ import { json, method, wrapCron } from '../_lib/http.js';import { env } from '../_lib/env.js';import { sql } from '../_lib/db.js';import { sendOpsAlert } from '../_lib/alerts.js';+import { acquireLock } from '../_lib/cache.js';import { SOLANA_SIGNERS, resolveSignerPubkey } from '../_lib/solana-signers.js';import { ringAllowedAddresses } from '../_lib/x402/ring-allowlist.js';import { classifyWalletDebits } from './x402-ring-leak-scan.js';@@ -28,6 +29,14 @@ import { requireCron } from '../_lib/cron-auth.js';const SIG_LIMIT = 100;const CANONICAL_USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';+// Same shape as x402-ring-leak-scan.js: a lease that doubles as the native+// cadence (*/15 min, see vercel.json) so an economy-tick re-fire or an overlap+// skips cheaply instead of running a second full pass over every controlled+// wallet concurrently. This scanner's own registry is small (SOLANA_SIGNERS),+// but the same overlap hazard applies at any size.+const LEASE_KEY = 'cron:wallets-leak-scan:lease';+const LEASE_SECONDS = 14 * 60;+async function ensureSchema() {await sql`CREATE TABLE IF NOT EXISTS wallet_scan_cursor (@@ -201,6 +210,11 @@ function signerEnvFor(name) {export default wrapCron(async (req, res) => {if (!method(req, res, ['GET', 'POST'])) return;if (!requireCron(req, res)) return;++ if (!(await acquireLock(LEASE_KEY, LEASE_SECONDS))) {+ return json(res, 200, { ok: true, skipped: true, reason: 'lease_held' });+ }+await ensureSchema();const runId = randomUUID();diff --git a/api/cron/x402-ring-leak-scan.js b/api/cron/x402-ring-leak-scan.jsindex 0e6accd44..c5f72f54c 100644--- a/api/cron/x402-ring-leak-scan.js+++ b/api/cron/x402-ring-leak-scan.js@@ -6,8 +6,9 @@// alarms within minutes if money leaves anyway — a compromised key, a bug, or a// path the assertions don't cover.//-// Every 10 min, for every role wallet and the next budget's worth of the-// registry (walked round-robin across runs, see RUN_BUDGET_MS):+// Every 10 min, for every role wallet, every registry wallet the platform's own+// ledger shows had activity, and the next budget's worth of the rest of the+// registry oldest-checked-first (see scanPlan / runScan / RUN_BUDGET_MS):// 1. getSignaturesForAddress(limit 100, until=<persisted cursor>) — only// signatures newer than the last scan. Cursor persisted per wallet so RPC// stays bounded and each tx is classified exactly once.@@ -38,7 +39,7 @@ import { env } from '../_lib/env.js';import { sendOpsAlert } from '../_lib/alerts.js';import { withDbRetry } from '../_lib/db-retry.js';import { sql } from '../_lib/db.js';-import { acquireLock, cacheGet, cacheSet } from '../_lib/cache.js';+import { acquireLock } from '../_lib/cache.js';import { ringAllowedAddresses, ringRoleWallets } from '../_lib/x402/ring-allowlist.js';import { requireCron } from '../_lib/cron-auth.js';@@ -55,17 +56,26 @@ const CANONICAL_USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';// Run shape. The registry holds every fresh-worker payer ever provisioned (2,006// enabled on 2026-10-09), and a wallet costs a cursor read plus an RPC call, so a// full pass took 600-900 s against a 300 s maxDuration. The economy tick also-// fires this route every minute on top of its own */10 schedule, and nothing-// stopped a second run while the first was still going: production carried about-// eight overlapping full scans at all times, each re-reading the same wallets and-// burning the RPC quota every other Solana read depends on. So a run now holds a-// lease that doubles as the native cadence, stops starting wallets inside a-// budget well under maxDuration, and the registry is walked round-robin from-// where the last run stopped. The role wallets, which hold the money, are read-// on every run.+// used to fire this route every minute on top of its own */10 schedule (removed+// from api/cron/economy-tick.js TARGETS 2026-10-11, see the comment there), and+// nothing stopped a second run while the first was still going: production+// carried about eight overlapping full scans at all times, each re-reading the+// same wallets and burning the RPC quota every other Solana read depends on.+//+// A run now holds a lease that doubles as the native cadence (acquireLock,+// never released: the TTL IS the cadence) and runs three tiers in order, each+// bounded by whatever is left of the budget (runScan): role wallets (the few+// that hold real balances), ledger-active registry wallets (the platform's own+// ledger (x402_ring_pool.last_used_at) shows claimed a payer since its last+// check, so a wallet with real activity is never more than one lease behind),+// then the rest of the registry oldest-checked_at-first. checked_at is stamped+// on EVERY attempted wallet, zero signatures or not (touchCursor), which is+// what makes the oldest-first order self-rotating: no cache offset to lose, no+// wallet skipped forever. Leak-detection guarantee this preserves: every+// enabled wallet is checked at least once per full rotation, and any wallet+// with ledger activity is checked on the very next run.const LEASE_KEY = 'cron:x402-ring-leak-scan:lease';const LEASE_SECONDS = 9 * 60;-const OFFSET_KEY = 'cron:x402-ring-leak-scan:offset';const RUN_BUDGET_MS = 200_000;const SCAN_CONCURRENCY = 4;@@ -74,14 +84,28 @@ const SCAN_CONCURRENCY = 4;/*** Normalize a parsed message's accountKeys to an array of pubkey strings.* jsonParsed encodes them as { pubkey, signer, writable }; legacy shapes as raw- * strings. Returns [] when unreadable.+ * strings. Found 2026-10-11: @solana/web3.js's own Connection.getParsedTransactions+ * returns that `pubkey` field as a live PublicKey instance, not a string, so a+ * naive `k.pubkey` is truthy but is not comparable to a wallet string with `===`+ * or `indexOf`. That silently zeroed out every wallet-identity match against+ * real mainnet responses: classifyWalletDebits's `walletIdx` was always -1 (so+ * it returned zero events for every real transaction) and the fee cross-check's+ * `fee.ours` was always false (so x402_ring_fee_observed never got a row). Must+ * resolve both plain strings and anything with a toBase58()/toString(). Returns+ * [] when unreadable.* @param {any} message* @returns {string[]}*/+function pubkeyToString(v) {+ if (typeof v === 'string') return v;+ if (v && typeof v.toBase58 === 'function') return v.toBase58();+ return v?.toString?.() || '';+}+export function accountKeyStrings(message) {const keys = message?.accountKeys;if (!Array.isArray(keys)) return [];- return keys.map((k) => (typeof k === 'string' ? k : (k?.pubkey || k?.toString?.() || '')));+ return keys.map((k) => (typeof k === 'string' ? k : pubkeyToString(k?.pubkey ?? k)));}/** Flatten top-level + inner instructions into one list of parsed instructions. */@@ -251,9 +275,14 @@ async function ensureSchema() {scanned_total bigint NOT NULL DEFAULT 0,leaks_total bigint NOT NULL DEFAULT 0,last_run_id uuid,- updated_at timestamptz NOT NULL DEFAULT now()+ updated_at timestamptz NOT NULL DEFAULT now(),+ checked_at timestamptz)`);+ // Fresh table above already has the column; existing deployments get it+ // here too, idempotently, mirroring the migration+ // (api/_lib/migrations/20261011230000_x402_ring_scan_checked_at.sql).+ await withDbRetry(() => sql`ALTER TABLE x402_ring_scan_cursor ADD COLUMN IF NOT EXISTS checked_at timestamptz`);} catch { /* migration owns it */ }try {await withDbRetry(() => sql`@@ -281,21 +310,43 @@ async function saveCursor(wallet, { lastSignature, lastSlot, scannedDelta, leakstry {await withDbRetry(() => sql`INSERT INTO x402_ring_scan_cursor- (wallet, last_signature, last_slot, scanned_total, leaks_total, last_run_id, updated_at)- VALUES (${wallet}, ${lastSignature}, ${lastSlot}, ${scannedDelta}, ${leaksDelta}, ${runId}, now())+ (wallet, last_signature, last_slot, scanned_total, leaks_total, last_run_id, updated_at, checked_at)+ VALUES (${wallet}, ${lastSignature}, ${lastSlot}, ${scannedDelta}, ${leaksDelta}, ${runId}, now(), now())ON CONFLICT (wallet) DO UPDATE SETlast_signature = COALESCE(EXCLUDED.last_signature, x402_ring_scan_cursor.last_signature),last_slot = COALESCE(EXCLUDED.last_slot, x402_ring_scan_cursor.last_slot),scanned_total = x402_ring_scan_cursor.scanned_total + ${scannedDelta},leaks_total = x402_ring_scan_cursor.leaks_total + ${leaksDelta},last_run_id = EXCLUDED.last_run_id,- updated_at = now()+ updated_at = now(),+ checked_at = now()`);} catch (err) {console.warn('[ring-leak-scan] cursor upsert failed', { wallet, message: err?.message });}}+/**+ * Stamp checked_at for a wallet with zero new signatures this run, without+ * touching last_signature/scanned_total/leaks_total. Without this, a+ * never-active wallet never advances checked_at and sorts to the front of the+ * oldest-checked_at-first rotation on every single run, starving every wallet+ * that actually has cursor activity.+ */+async function touchCursor(wallet, runId) {+ try {+ await withDbRetry(() => sql`+ INSERT INTO x402_ring_scan_cursor (wallet, last_run_id, updated_at, checked_at)+ VALUES (${wallet}, ${runId}, now(), now())+ ON CONFLICT (wallet) DO UPDATE SET+ last_run_id = EXCLUDED.last_run_id,+ checked_at = now()+ `);+ } catch (err) {+ console.warn('[ring-leak-scan] cursor touch failed', { wallet, message: err?.message });+ }+}+async function accrueObservedFee(dayToLamports) {for (const [day, { lamports, count }] of dayToLamports) {if (lamports <= 0 && count <= 0) continue;@@ -349,32 +400,64 @@ function dayOf(blockTime, nowMs) {// ── Wallets to scan ───────────────────────────────────────────────────────────-/** The ring wallets to scan: the role wallets that hold the money, and the registry. */+/**+ * The ring wallets to scan, in three tiers:+ * roles : the few role wallets that hold real balances (ringRoleWallets()).+ * ledgerActive : registry wallets the platform's OWN ledger shows moved money+ * since their last scan: x402_ring_pool.last_used_at (set by+ * claimNextPayer() every time the ring tick claims a payer, see+ * api/_lib/x402/pool.js) newer than x402_ring_scan_cursor.checked_at.+ * This is the closest real "wallet had activity" signal in the+ * schema; a wallet claimed by the pool is the only way a+ * registry wallet other than a role wallet moves funds today.+ * rotation : every other enabled registry wallet, oldest checked_at first+ * (NULLS FIRST, so a brand-new wallet is scanned before a+ * 22-year-future checked_at could ever starve it). One query,+ * since the ORDER BY already gives both the ledger-active join+ * key and the rotation order.+ */async function ringScanWallets() {const roles = Object.values(await ringRoleWallets()).filter(Boolean);- let registry = [];+ const registry = [];+ const ledgerActive = [];try {- const rows = await withDbRetry(() => sql`SELECT pubkey FROM x402_ring_wallets WHERE enabled = true ORDER BY pubkey`);- registry = rows.map((r) => r?.pubkey).filter(Boolean);+ const rows = await withDbRetry(() => sql`+ SELECT w.pubkey AS pubkey, p.last_used_at AS last_used_at, c.checked_at AS checked_at+ FROM x402_ring_wallets w+ LEFT JOIN x402_ring_pool p ON p.pubkey = w.pubkey+ LEFT JOIN x402_ring_scan_cursor c ON c.wallet = w.pubkey+ WHERE w.enabled = true+ ORDER BY c.checked_at ASC NULLS FIRST, w.pubkey+ `);+ for (const r of rows) {+ if (!r?.pubkey) continue;+ registry.push(r.pubkey);+ if (r.last_used_at && (!r.checked_at || new Date(r.last_used_at) > new Date(r.checked_at))) {+ ledgerActive.push(r.pubkey);+ }+ }} catch { /* role wallets alone still get scanned */ }- return { roles, registry };+ return { roles, ledgerActive, registry };}/**- * Order one run's work: every role wallet, then the registry rotated to start at- * `offset` so successive budget-bounded runs cover all of it in turn. Pure.+ * Order one run's work: role wallets, then ledger-active registry wallets (the+ * ones the platform's own ledger shows moved money since their last check),+ * then the rest of the registry (already oldest-checked_at-first from the query+ * above). Each tier is deduped against the ones before it so a wallet is never+ * scanned twice in the same run. Pure.* @param {string[]} roles- * @param {string[]} registry- * @param {number} offset- * @returns {{ roles: string[], rotation: string[], start: number }}+ * @param {string[]} ledgerActive+ * @param {string[]} registry oldest-checked_at-first, includes ledgerActive members+ * @returns {{ roles: string[], ledgerActive: string[], rotation: string[] }}*/-export function scanPlan(roles, registry, offset) {+export function scanPlan(roles, ledgerActive, registry) {const roleList = [...new Set((roles || []).filter(Boolean))];const roleSet = new Set(roleList);- const rest = [...new Set((registry || []).filter(Boolean))].filter((w) => !roleSet.has(w));- const n = Number.isFinite(Number(offset)) ? Math.trunc(Number(offset)) : 0;- const start = rest.length ? ((n % rest.length) + rest.length) % rest.length : 0;- return { roles: roleList, rotation: [...rest.slice(start), ...rest.slice(0, start)], start };+ const ledgerList = [...new Set((ledgerActive || []).filter(Boolean))].filter((w) => !roleSet.has(w));+ const ledgerSet = new Set(ledgerList);+ const rotation = [...new Set((registry || []).filter(Boolean))].filter((w) => !roleSet.has(w) && !ledgerSet.has(w));+ return { roles: roleList, ledgerActive: ledgerList, rotation };}/**@@ -405,6 +488,36 @@ export async function scanWithinBudget(queue, scanOne, { budgetMs, concurrency,return { results, started: next };}+/**+ * Run a full scanPlan() through scanOne, tier by tier (roles, then+ * ledger-active, then rotation), each getting whatever is left of `budgetMs`+ * after the tiers before it. `partial` is true the moment any tier stops short+ * of its queue, which is the signal a caller needs to know cursors were saved+ * for a prefix only. Pure apart from `scanOne`/`now`, so it is testable with a+ * fake clock exactly like scanWithinBudget above.+ * @param {{ roles: string[], ledgerActive: string[], rotation: string[] }} plan+ * @param {(wallet: string) => Promise<any>} scanOne+ * @param {{ budgetMs?: number, concurrency?: number, now?: () => number }} [opts]+ */+export async function runScan(plan, scanOne, { budgetMs = RUN_BUDGET_MS, concurrency = SCAN_CONCURRENCY, now = Date.now } = {}) {+ const startedAt = now();+ const remaining = () => Math.max(0, budgetMs - (now() - startedAt));++ const roleRun = await scanWithinBudget(plan.roles, scanOne, { budgetMs: remaining(), concurrency, now });+ const ledgerRun = await scanWithinBudget(plan.ledgerActive, scanOne, { budgetMs: remaining(), concurrency, now });+ const rotationRun = await scanWithinBudget(plan.rotation, scanOne, { budgetMs: remaining(), concurrency, now });++ const partial = roleRun.started < plan.roles.length+ || ledgerRun.started < plan.ledgerActive.length+ || rotationRun.started < plan.rotation.length;++ return {+ results: [...roleRun.results, ...ledgerRun.results, ...rotationRun.results],+ partial,+ counts: { roles: roleRun.started, ledgerActive: ledgerRun.started, rotation: rotationRun.started },+ };+}+// ── Per-wallet scan ───────────────────────────────────────────────────────────export async function scanWallet(conn, PublicKey, wallet, { allowed, usdcMint, runId, feeByDay }) {@@ -420,7 +533,10 @@ export async function scanWallet(conn, PublicKey, wallet, { allowed, usdcMint, rsummary.error = err?.message || 'sig_fetch_failed';return summary;}- if (sigInfos.length === 0) return summary;+ if (sigInfos.length === 0) {+ await touchCursor(wallet, runId);+ return summary;+ }summary.truncated = sigInfos.length >= SIG_SCAN_LIMIT && !!cursor?.last_signature;// getSignaturesForAddress returns newest→oldest.@@ -599,31 +715,22 @@ export default wrapCron(async (req, res) => {network: 'mainnet', commitment: 'confirmed',});- const [allowed, wallets, offset] = await Promise.all([+ const [allowed, wallets] = await Promise.all([ringAllowedAddresses(),ringScanWallets(),- cacheGet(OFFSET_KEY).catch(() => 0),]);const usdcMint = env.X402_ASSET_MINT_SOLANA;- const plan = scanPlan(wallets.roles, wallets.registry, Number(offset) || 0);+ const plan = scanPlan(wallets.roles, wallets.ledgerActive, wallets.registry);+ const totalPlanned = plan.roles.length + plan.ledgerActive.length + plan.rotation.length;- if (plan.roles.length + plan.rotation.length === 0) {+ if (totalPlanned === 0) {return json(res, 200, { ok: true, run_id: runId, skipped: true, reason: 'no_ring_wallets_configured' });}const feeByDay = new Map();const scanOne = (wallet) => scanWallet(conn, PublicKey, wallet, { allowed, usdcMint, runId, feeByDay });- const startedAt = Date.now();- const roleRun = await scanWithinBudget(plan.roles, scanOne, { budgetMs: RUN_BUDGET_MS, concurrency: SCAN_CONCURRENCY });- const rotationRun = await scanWithinBudget(plan.rotation, scanOne, {- budgetMs: Math.max(0, RUN_BUDGET_MS - (Date.now() - startedAt)),- concurrency: SCAN_CONCURRENCY,- });- if (plan.rotation.length) {- await cacheSet(OFFSET_KEY, (plan.start + rotationRun.started) % plan.rotation.length, 7 * 24 * 3600).catch(() => {});- }+ const { results, partial, counts } = await runScan(plan, scanOne, { budgetMs: RUN_BUDGET_MS, concurrency: SCAN_CONCURRENCY });- const results = [...roleRun.results, ...rotationRun.results];let leaks = 0;let delegations = 0;for (const s of results) {@@ -631,15 +738,23 @@ export default wrapCron(async (req, res) => {delegations += s.delegations || 0;}+ // Fed by whatever the budget let us scan: a partial run still accrues the+ // fees it actually observed instead of waiting for a full pass that may+ // never finish before the next lease.await accrueObservedFee(feeByDay);const feeCheck = await crossCheckFees(runId, nowMs);return json(res, 200, {ok: true,run_id: runId,- wallets: plan.roles.length + plan.rotation.length,+ wallets: totalPlanned,scanned_wallets: results.length,- deferred_wallets: plan.rotation.length - rotationRun.started,+ partial,+ deferred_wallets: totalPlanned - results.length,+ role_wallets: plan.roles.length,+ ledger_active_wallets: plan.ledgerActive.length,+ rotation_wallets: plan.rotation.length,+ counts,allowed_set_size: allowed.size,leaks,delegations,diff --git a/data/changelog.json b/data/changelog.jsonindex e284299c2..b05777785 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,12 @@{"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security, desktop (desktop entries become the desktop app's release notes). `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-10-11",+ "title": "The on-chain leak alarm now scans smarter instead of scanning everything",+ "summary": "The background monitor that watches every platform-controlled Solana wallet for a leak now checks the handful of wallets that hold real balances every run, any wallet the platform's own payment ledger shows just moved money, and the rest of the registry in a rotation, instead of walking the full wallet list on every single pass. That cuts the monitor's own Solana RPC usage sharply, which means faster balance reads and snappier agent pages across the platform, and it no longer runs two overlapping schedules at once. A wallet-identity bug found along the way is fixed too: on-chain transactions were being matched by the wrong field shape, which silently kept both the leak detector and its fee-accounting cross-check from recording anything real. Both now work correctly.",+ "tags": ["infra", "fix"]+ },{"date": "2026-10-11","title": "Share a finished Forge creation on X and it plays inline",diff --git a/docs/ops/production-log-triage.md b/docs/ops/production-log-triage.mdindex f3de1c106..c82f33dd5 100644--- a/docs/ops/production-log-triage.md+++ b/docs/ops/production-log-triage.md@@ -888,6 +888,27 @@ ws error: Unexpected server response: 301- **Resolve (owner, money):** top up or upgrade the exhausted plans (Helius,QuickNode, Alchemy). Nothing else clears a quota; the cooldowns simply expireand re-trip while traffic exceeds the free tiers.+- **Check for a scanner burning the quota before topping up.** Measured+ 2026-10-08: `/api/cron/x402-ring-leak-scan`+ ([api/cron/x402-ring-leak-scan.js](../../api/cron/x402-ring-leak-scan.js))+ walked its full 2,006-wallet registry sequentially on every run, with no+ budget and no single-flight lock, fired both by its own Cloud Scheduler+ `*/10` job and by `economy-tick.js` every 2 minutes. Result: about 8+ overlapping full scans at all times, roughly 46,000 `getSignaturesForAddress`+ calls an hour from one read-only monitor, run latency p50 765s against a+ 300s declared budget, and 504s on about 7% of runs. Recognize it with+ `gcloud logging read 'resource.type="cloud_run_revision"+ resource.labels.service_name="three-ws-api"+ httpRequest.requestUrl:"x402-ring-leak-scan"' --freshness=3h --limit=500+ --format='value(timestamp,httpRequest.status,httpRequest.latency,httpRequest.userAgent)'+ --project aerial-vehicle-466722-p5`: many overlapping entries with+ `userAgent` `threews-economy-tick/1.0` alongside `Google-Cloud-Scheduler`,+ and latencies in the hundreds of seconds. Fixed 2026-10-11: the handler now+ holds a lease (`acquireLock`), runs under a 200s wall-clock budget, scans+ role wallets plus ledger-active wallets plus an oldest-checked_at-first+ rotation instead of the whole registry every time, and was removed from+ `economy-tick.js`'s `TARGETS`. A healthy run now shows p50 under 60s with no+ `threews-economy-tick/1.0` caller in the log query above.- **Do NOT "fix" it by promoting the reserve.** `SOLANA_RPC_LAST_RESORT_URLS`exists to keep a metered endpoint in reserve; naming that same URL in`SOLANA_RPC_URL` or `QUICKNODE_RPC_URL` makes it the primary (the chaindiff --git a/prompts/finish/_context/production-100-OWNER-ACTIONS.md b/prompts/finish/_context/production-100-OWNER-ACTIONS.mdindex 6009a2f03..03fe09bc5 100644--- a/prompts/finish/_context/production-100-OWNER-ACTIONS.md+++ b/prompts/finish/_context/production-100-OWNER-ACTIONS.md@@ -9,7 +9,7 @@ it and, if that unblocks a work order, say which one in the owning pack's `produRows carry the date they were added so staleness is visible. Re-verify a row before actingon it; some resolve themselves as other work lands.-## Open rows (2026-10-11 (later): row 35 added for the agent mention-policy migration; 2026-10-11 04:16 UTC: rows 1 and 24 re-measured by the deep triage sweep; row 34 added for the evolve/main branch divergence; 2026-10-10: row 33 added for the xAI MCP e2e key; rows 1, 19 and 24 re-measured by the triage sweep; 2026-10-09: rows 1, 2 and 24 re-measured by the triage sweep, row 31 added for the GPU worker redeploy and row 32 for database table retention; row 30 added for the Grok Bot CLI setup rerun; 2026-10-08: row 26 added for the coin-gated MCP catalog regeneration; rows 1 and 2 re-measured by the triage sweep, row 24 added for the paid Solana RPC credits, row 25 added for the MCP connector OAuth deploy; 2026-09-30: row 23 added for the $THREE receiver wallets; 2026-09-29: row 19 re-measured after the agent-sniper deploy; 2026-09-09: row 19 added, and row 1 corrected because its outage premise no longer holds; rows 1, 2, 3, 9, 13, 15 and 16 re-measured 2026-09-04; the former row 18 was cleared that day and its number is not reused; the 2026-09-02 and 2026-08-09 passes are folded in below)+## Open rows (2026-10-11 (even later): row 24 re-measured again after order 400's ring-leak-scan tiering/lock fix shipped on `evolve`; 2026-10-11 (later): row 35 added for the agent mention-policy migration; 2026-10-11 04:16 UTC: rows 1 and 24 re-measured by the deep triage sweep; row 34 added for the evolve/main branch divergence; 2026-10-10: row 33 added for the xAI MCP e2e key; rows 1, 19 and 24 re-measured by the triage sweep; 2026-10-09: rows 1, 2 and 24 re-measured by the triage sweep, row 31 added for the GPU worker redeploy and row 32 for database table retention; row 30 added for the Grok Bot CLI setup rerun; 2026-10-08: row 26 added for the coin-gated MCP catalog regeneration; rows 1 and 2 re-measured by the triage sweep, row 24 added for the paid Solana RPC credits, row 25 added for the MCP connector OAuth deploy; 2026-09-30: row 23 added for the $THREE receiver wallets; 2026-09-29: row 19 re-measured after the agent-sniper deploy; 2026-09-09: row 19 added, and row 1 corrected because its outage premise no longer holds; rows 1, 2, 3, 9, 13, 15 and 16 re-measured 2026-09-04; the former row 18 was cleared that day and its number is not reused; the 2026-09-02 and 2026-08-09 passes are folded in below)| # | Action | Size | Unblocks | Detail lives in ||---|---|---|---|---|@@ -35,7 +35,7 @@ on it; some resolve themselves as other work lands.| 21 | **Decide whether to rotate the lane credentials read on 2026-09-09.** Resolving the LLM chain for the fact-check benchmark printed secret material into an agent session transcript: the `vercel-inference@aerial-vehicle-466722-p5` service-account **private key** (`GCP_SERVICE_ACCOUNT_JSON`, key id `93be907a...`), plus `GROQ_API_KEY`, all five OpenRouter keys, `NVIDIA_API_KEY` and `OPENAI_API_KEY`. `INTERNAL_API_KEY` was used but never printed. Nothing indicates misuse and all of them remain valid; the exposure surface is whoever can read that transcript. Rotate or accept, and note that the OpenAI key is dead anyway (row 6) and OpenRouter key #1 is already revoked. | decision (+ minutes if rotating) | Closing out the exposure | [PROGRESS.md](production-100-PROGRESS.md), 2026-09-09 entry || 22 | **Decide whether to arm the three trading growth programs** (added 2026-09-29). Built, tested and disarmed: the big-win X poster (`BIG_WIN_X_ENABLED`, posts to @trythreews), the first-rug softener (`RUG_SOFTENER_ENABLED`, pays $THREE, default cap $25 per claim and $100 per day) and the early-leader bonus (`EARLY_LEADER_ENABLED`, pays $THREE, default 20 slots at $50 and $250 per week). Each is armed on its own. Steps: (1) `npm run db:status`, then `npm run db:migrate` for `20260929120000_growth_program_payouts.sql` (payout programs only); (2) set `THREE_PRIZE_PAYOUT_KEY` (unset on production as of 2026-09-29; the programs deliberately refuse the club treasury fallback, which is the economy master wallet) to a dedicated wallet holding the $THREE to cover the caps (payout programs only); (3) deploy; (4) read the dry run at `/api/ops/growth-programs`; (5) `gcloud run services update three-ws-api --region us-central1 --update-env-vars <FLAG>=1`. Measured 2026-09-29 against production data: nothing would be posted or paid today (no live win cleared the 0.1 SOL size gate, no first trade met the softener bar, no leader has a profitable 30-day record with followers). | one yes per program | Roadmap 917 items 3.8, 12.15, 13.4 | [docs/growth-programs.md](../../docs/growth-programs.md) || 23 | **Name the two $THREE receiver wallets** (added 2026-09-30). `/api/healthz` reports `three_token_rail` down and signed-in `POST /api/token/quote` answers `503 treasury_unavailable`, so no $THREE-priced purchase can be priced (Forge paid tiers, spins, scarcity mints, token marketplace sales, copy-trading fees). The quote signing key is done (`three-quote-secret`, wired on `three-ws-api-00466-85g`); only `THREE_TREASURY_WALLET` and `THREE_REWARDS_WALLET` remain. No revision ever held them, so there is nothing to restore. Candidates: treasury `wwwwwDxFWRn7grgr3Esrsg5C6NvDoDHSA4gaCffccrU` (x402 receiver, already holds a $THREE account), rewards `WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW` (the economy master, which `REWARDS_DISTRIBUTOR_SECRET` signs as). The rewards candidate is also the buyback signer, so arming `THREE_BUYBACK_ENABLED` or `THREE_MICROBUY_ENABLED` would sweep the whole rewards pool into the treasury; decide that before arming either lane. Setting the two vars moves no funds by itself: `gcloud run services update three-ws-api --region us-central1 --update-env-vars THREE_TREASURY_WALLET=<treasury>,THREE_REWARDS_WALLET=<rewards>`. | two addresses | The whole $THREE purchase rail | [docs/money-map.md](../../docs/money-map.md#three-split-receivers-inbound-three) |-| 24 | **Top up the paid Solana RPC plans** (added 2026-10-08). Helius answers `429: max usage reached` on every call: 45,461 such lines on `three-ws-api` in the 24 hours to 2026-10-08 17:10 UTC, the oldest retained one from 2026-09-08. healthz reads `helius` degraded and `rpc_lanes` "all 2 paid lanes exhausted", so Solana traffic runs on throttled free nodes. That is the whole cause of `agent_index` reading down: 172 of the 176 erroring Solana cursors carry `solana rpc 429 @ public.rpc.solanavibestation.com`, the last free lane, and the rest are a free provider's own errors. No config change adds credits, and promoting the reserve lane is the documented wrong fix. Upgrade or top up the Helius plan (and the second paid lane), then confirm `helius` and `rpc_lanes` read ok on `curl -s https://three.ws/api/healthz`. **Re-measured 2026-10-09 03:05 UTC:** `rpc_lanes` still reads "all 2 paid lanes exhausted", and `agent_index` reads down at a 36m median Solana lag with 135 of 1,663 cursors erroring. One cause of the burn was ours and is fixed on `evolve` pending row 1's deploy: the ring leak scanner ran about eight overlapping copies at all times (213 runs in 6 hours, average 788 s, each walking 2,006 registry wallets), now one leased, 200 s-budgeted run per 10 minutes (`0abce6d69`). That cuts the platform's own RPC demand; it does not add credits, so this row stands. **Re-measured 2026-10-10 20:06 UTC, after row 1's leak-scanner fix is live in production:** `rpc_lanes` still reads "all 2 paid lanes exhausted; serving from 0 free lanes" (all 8 lanes cooling at once, both paid ones on a 6h cooldown), and `agent_index` reads a 1h7m median Solana lag with 172 of 1,665 cursors erroring (10.3%). The scanner fix alone was not enough to clear this; the lanes need the owner's top-up. **Re-measured 2026-10-11 04:16 UTC:** `rpc_lanes` still reads "all 2 paid lanes exhausted; serving from 0 free lanes" (8 lanes cooling, each back in about 8 minutes), but `agent_index` has improved to a 45m median Solana lag with 37 of 1,665 cursors erroring (2.2%, down from 10.3%). Cooldowns are now short enough that the fleet mostly catches up between them; the lanes themselves are still exhausted and still need the owner's top-up to stop cycling into cooldown at all. | billing | Solana agent index freshness, balance reads, every on-chain route's latency | [docs/ops/production-log-triage.md](../../docs/ops/production-log-triage.md), "Every paid Solana RPC lane exhausted at once" |+| 24 | **Top up the paid Solana RPC plans** (added 2026-10-08). Helius answers `429: max usage reached` on every call: 45,461 such lines on `three-ws-api` in the 24 hours to 2026-10-08 17:10 UTC, the oldest retained one from 2026-09-08. healthz reads `helius` degraded and `rpc_lanes` "all 2 paid lanes exhausted", so Solana traffic runs on throttled free nodes. That is the whole cause of `agent_index` reading down: 172 of the 176 erroring Solana cursors carry `solana rpc 429 @ public.rpc.solanavibestation.com`, the last free lane, and the rest are a free provider's own errors. No config change adds credits, and promoting the reserve lane is the documented wrong fix. Upgrade or top up the Helius plan (and the second paid lane), then confirm `helius` and `rpc_lanes` read ok on `curl -s https://three.ws/api/healthz`. **Re-measured 2026-10-09 03:05 UTC:** `rpc_lanes` still reads "all 2 paid lanes exhausted", and `agent_index` reads down at a 36m median Solana lag with 135 of 1,663 cursors erroring. One cause of the burn was ours and is fixed on `evolve` pending row 1's deploy: the ring leak scanner ran about eight overlapping copies at all times (213 runs in 6 hours, average 788 s, each walking 2,006 registry wallets), now one leased, 200 s-budgeted run per 10 minutes (`0abce6d69`). That cuts the platform's own RPC demand; it does not add credits, so this row stands. **Re-measured 2026-10-10 20:06 UTC, after row 1's leak-scanner fix is live in production:** `rpc_lanes` still reads "all 2 paid lanes exhausted; serving from 0 free lanes" (all 8 lanes cooling at once, both paid ones on a 6h cooldown), and `agent_index` reads a 1h7m median Solana lag with 172 of 1,665 cursors erroring (10.3%). The scanner fix alone was not enough to clear this; the lanes need the owner's top-up. **Re-measured 2026-10-11 04:16 UTC:** `rpc_lanes` still reads "all 2 paid lanes exhausted; serving from 0 free lanes" (8 lanes cooling, each back in about 8 minutes), but `agent_index` has improved to a 45m median Solana lag with 37 of 1,665 cursors erroring (2.2%, down from 10.3%). Cooldowns are now short enough that the fleet mostly catches up between them; the lanes themselves are still exhausted and still need the owner's top-up to stop cycling into cooldown at all. **Re-measured 2026-10-11 (later), order 400 shipped on `evolve`:** the 2026-10-09 fix only covered the lease and wall-clock budget; the scanner was still rescanning its whole 2,006-wallet registry on every budget-fitting run. It now scans three tiers per run (role wallets, then registry wallets the ring's own pool ledger shows claimed a payer since last check, then an oldest-`checked_at`-first rotation slice), was removed from `economy-tick.js`'s every-2-minute `TARGETS` (its own `*/10` Cloud Scheduler job already owns it), and `wallets-leak-scan` got the same single-flight lock. Call volume this cuts, measured against the 2026-10-08 baseline above (about 46,000 `getSignaturesForAddress` calls/hour, 1.1M/day from this one monitor): a never-active wallet now costs one call per full rotation instead of one per run. Separately, found and fixed while investigating why `x402_ring_fee_observed` had never recorded a row: `accountKeyStrings()` returned a live `PublicKey` object instead of its base58 string whenever the RPC client returned `accountKeys` as `{pubkey, signer, writable}` (the real shape from `@solana/web3.js`'s own parsed-transaction response), so every wallet-identity comparison silently failed on real mainnet data, every real transaction classified with zero leak/delegation events, the fee cross-check never accumulated anything. Fixed and covered by new tests; this also means leak/delegation detection itself starts actually firing on real traffic for the first time once this ships, not just faster and cheaper. Ship command: `npm run db:migrate` (applies the new `checked_at` column migration), then `npm run deploy:gcp:full`. Post-deploy check, 3 hours after: the log query above shows p50 under 60s and zero 504s on `x402-ring-leak-scan`, and no `threews-economy-tick/1.0` caller in it; `SELECT count(*) FROM x402_ring_fee_observed` is greater than 0. This row still stands: fixing the platform's own demand does not add credits, and the lanes stay exhausted until the owner tops them up. | billing | Solana agent index freshness, balance reads, every on-chain route's latency | [docs/ops/production-log-triage.md](../../docs/ops/production-log-triage.md), "Every paid Solana RPC lane exhausted at once" || 25 | **Deploy so cloud MCP connectors can sign in to four hosted servers** (added 2026-10-08 by the evolve loop, x-grok order 023). Production (`fe2a8b24f`, revision `three-ws-api-00479-d7z`) still points every OAuth 401 at the root protected-resource document naming `/api/mcp`, so a stock MCP SDK client (Grok Bot, claude.ai connectors) refuses to start sign-in on `/api/mcp-3d`, `/api/mcp-agent`, `/api/mcp-bazaar` and `/api/ibm-mcp`. The fix is on `main` (`7985f1cce`, `59bdf5707`) and the probe passes all seven servers against local code. The submit gate also needs the pending `20261008150000_revenue_direct_settle_backfill.sql` applied first (`npm run db:status`, then `npm run db:migrate`), which is another session's payout backfill, so read it before applying. Then `npm run deploy:gcp:full`, then `npm run probe:mcp-clients -- --json prompts/x-grok/_generated/connector-probe.json`, which must print `all 7 servers passed`. | one deploy | Grok Bot and every OAuth connector on four servers; closes x-grok order 023 | [docs/mcp.md](../../../docs/mcp.md#client-compatibility), [prompts/x-grok/_generated/connector-probe.json](../../x-grok/_generated/connector-probe.json) || 26 | **Approve committing the regenerated MCP catalog** (added 2026-10-08 by the evolve loop, x-grok order 024 and order 401). `npm test` is green on the evolve working tree (vitest 2194 files / 31,910 tests, Playwright 262 passed with `E2E_PORT=3107`), but three files stay uncommitted under the coin commit gate because their regenerated text names other crypto projects already named in committed source: `public/mcp-catalog.json` (fills the missing input schemas of `agora_quote_register` and `preview_agent_identity` and adds `pay_quote`; without it `tests/mcp-schema.test.js` fails 3 tests at HEAD), `tests/fixtures/mcp-golden-tools.json` (the `audit:mcp-golden` contract refresh) and a one-line dash fix in `packages/agora-mcp/src/tools/register.js`. They are held as an `evolve held:` stash. To approve, on `main`: `git stash list | grep 'evolve held'`, review with `git stash show -p <ref>`, then `git stash apply <ref>` and commit those three paths; or regenerate instead with `npm run build:mcp-catalog && node scripts/audit-mcp-golden.mjs --update` and commit `public/mcp-catalog.json tests/fixtures/mcp-golden-tools.json`. Then `E2E_PORT=3107 npm test` should exit 0 at HEAD and orders 024 and 401 can retire. | one yes | Orders 024 and 401 | [x-grok-PROGRESS.md](x-grok-PROGRESS.md), 2026-10-08 order 024 retry entry || 27 | **Apply the OAuth refresh-token index, then ship instant revocation with the next deploy** (added 2026-10-08 by the evolve loop, x-grok order 025, which is otherwise complete and retired). `cf30be269` makes every OAuth access token check its grant on each request, so Revoke in Settings, Connected apps cuts a cloud connector such as Grok Bot off on its next call instead of up to an hour later. That lookup filters `oauth_refresh_tokens` on `(user_id, client_id)` including revoked rows, which the existing partial index cannot serve; at 4,228 rows today it is fast without one, but the table gains a row per refresh. The code is correct without the index. Apply it with `node scripts/apply-migrations.mjs --apply --file 20261008190000_oauth_refresh_user_client_index.sql` (or `npm run db:status`, then `npm run db:migrate`, which also applies row 25's backfill, so read that one first). It is pending until then and `npm run db:check` blocks a deploy on it. The behavior itself ships with the deploy in row 25. | one command | Fast grant checks on every OAuth MCP call; the deploy gate | [docs/mcp.md](../../../docs/mcp.md#cloud-connectors-and-revocation) |diff --git a/public/changelog-recent.json b/public/changelog-recent.jsonindex bf64ddc4a..eabc7575a 100644--- a/public/changelog-recent.json+++ b/public/changelog-recent.json@@ -1,11 +1,11 @@{- "generated_at": "2026-10-11T08:54:58.088Z",+ "generated_at": "2026-10-11T10:13:45.276Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws","url": "https://three.ws"},- "total": 3856,+ "total": 3857,"complete": false,"full_feed": "/changelog.json","entries": [@@ -61,6 +61,17 @@"improvement"]},+ {+ "date": "2026-10-11",+ "type": "update",+ "title": "The on-chain leak alarm now scans smarter instead of scanning everything",+ "summary": "The background monitor that watches every platform-controlled Solana wallet for a leak now checks the handful of wallets that hold real balances every run, any wallet the platform's own payment ledger shows just moved money, and the rest of the registry in a rotation, instead of walking the full wallet list on every single pass. That cuts the monitor's own Solana RPC usage sharply, which means faster balance reads and snappier agent pages across the platform, and it no longer runs two overlapping schedules at once. A wallet-identity bug found along the way is fixed too: on-chain transactions were being matched by the wrong field shape, which silently kept both the leak detector and its fee-accounting cross-check from recording anything real. Both now work correctly.",+ "link": null,+ "tags": [+ "infra",+ "fix"+ ]+ },{"date": "2026-10-10","type": "launch",@@ -1547,17 +1558,6 @@"improvement","fix"]- },- {- "date": "2026-09-18",- "type": "update",- "title": "Paid x402 endpoints are answering again",- "summary": "For several hours on September 18, nearly every paid endpoint on three.ws, the x402 discovery document at /.well-known/x402, the payment facilitator and the MCP server answered with a server error instead of a price. A routine update to the library behind wallet sign-in changed what it needs at startup, and our code tripped over it the moment it loaded, before any request could be served. Agents and marketplace validators that probed us saw a broken seller. The sign-in code now supplies what the library expects, returning buyers can sign back in to what they already paid for exactly as before, and the deploy checks now refuse to ship when the tested dependencies differ from the ones the live site will run, which is how this got past us.",- "link": "/docs/x402",- "tags": [- "fix",- "infra"- ]}]}diff --git a/public/changelog.json b/public/changelog.jsonindex 21c8c45cb..1a9e61eb6 100644--- a/public/changelog.json+++ b/public/changelog.json@@ -1,5 +1,5 @@{- "generated_at": "2026-10-11T08:54:58.064Z",+ "generated_at": "2026-10-11T10:13:45.244Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws",@@ -58,6 +58,17 @@"improvement"]},+ {+ "date": "2026-10-11",+ "type": "update",+ "title": "The on-chain leak alarm now scans smarter instead of scanning everything",+ "summary": "The background monitor that watches every platform-controlled Solana wallet for a leak now checks the handful of wallets that hold real balances every run, any wallet the platform's own payment ledger shows just moved money, and the rest of the registry in a rotation, instead of walking the full wallet list on every single pass. That cuts the monitor's own Solana RPC usage sharply, which means faster balance reads and snappier agent pages across the platform, and it no longer runs two overlapping schedules at once. A wallet-identity bug found along the way is fixed too: on-chain transactions were being matched by the wrong field shape, which silently kept both the leak detector and its fee-accounting cross-check from recording anything real. Both now work correctly.",+ "link": null,+ "tags": [+ "infra",+ "fix"+ ]+ },{"date": "2026-10-10","type": "launch",diff --git a/public/changelog.xml b/public/changelog.xmlindex a636c6813..94fb182c4 100644--- a/public/changelog.xml+++ b/public/changelog.xml@@ -46,6 +46,14 @@<category>feature</category><description>A new public endpoint, /api/x/mention-bot/status, answers whether the @-mention reply bot is live, in dry run, or paused, how many handles it has replied on, how many replies it sent in the last 24 hours, and its median reply time. No mention text or author identity is included. The /grok page now shows this as a live section, and /api/healthz carries the same signal as a platform subsystem, so an operator sees a wedged reply queue or a rising error rate within the hour it starts, instead of the bot quietly going silent with no signature anywhere.</description></item>+ <item>+ <title>The on-chain leak alarm now scans smarter instead of scanning everything</title>+ <link>https://three.ws/changelog</link>+ <guid isPermaLink="false">2026-10-11:The on-chain leak alarm now scans smarter instead of scanning everything</guid>+ <pubDate>Sun, 11 Oct 2026 12:00:00 GMT</pubDate>+ <category>infra</category>+ <description>The background monitor that watches every platform-controlled Solana wallet for a leak now checks the handful of wallets that hold real balances every run, any wallet the platform's own payment ledger shows just moved money, and the rest of the registry in a rotation, instead of walking the full wallet list on every single pass. That cuts the monitor's own Solana RPC usage sharply, which means faster balance reads and snappier agent pages across the platform, and it no longer runs two overlapping schedules at once. A wallet-identity bug found along the way is fixed too: on-chain transactions were being matched by the wrong field shape, which silently kept both the leak detector and its fee-accounting cross-check from recording anything real. Both now work correctly.</description>+ </item><item><title>Docs · Grok Bot recipes</title><link>https://three.ws/docs/tutorials/grok-bot-recipes</link>diff --git a/public/features.json b/public/features.jsonindex 144d44718..5ec122578 100644--- a/public/features.json+++ b/public/features.json@@ -1,5 +1,5 @@{- "generated_at": "2026-10-11T08:54:58.053Z",+ "generated_at": "2026-10-11T10:13:45.228Z","generated_by": "scripts/build-page-index.mjs from data/pages.json","site": {"name": "three.ws",diff --git a/tests/x402-ring-leak-scan-budget.test.js b/tests/x402-ring-leak-scan-budget.test.jsnew file mode 100644index 000000000..34b39fdf2--- /dev/null+++ b/tests/x402-ring-leak-scan-budget.test.js@@ -0,0 +1,182 @@+// Ledger-tiered selection + checked_at rotation tests for the x402 ring leak+// scanner (api/cron/x402-ring-leak-scan.js). Companion to+// tests/x402-ring-leak-scan-run.test.js (lease + plain budget mechanics) and+// tests/x402-ring-leak-classify.test.js (pure classification).+//+// Order 400 (2026-10-08) measured the registry at 2,006 enabled wallets, each+// costing a cursor read plus an RPC call every single run regardless of+// whether it had ever moved a lamport. These tests pin the fix that scopes a+// run to what can actually have leaked: role wallets (hold real balances),+// then registry wallets the platform's OWN ledger (x402_ring_pool.last_used_at)+// shows claimed a payer since their last check, then the rest of the registry+// oldest-checked_at-first, and the checked_at stamp that makes that rotation+// self-correcting even for a wallet with zero signatures.+//+// Root cause of task 6 (x402_ring_fee_observed never recording a row), found+// 2026-10-11: @solana/web3.js's own Connection.getParsedTransactions returns+// message.accountKeys entries as { pubkey: PublicKey, signer, writable }+// where pubkey is a live PublicKey instance, not a string. accountKeyStrings+// used to return that instance unconverted, so every `=== wallet` or+// `indexOf(wallet)` comparison against a plain base58 string silently failed:+// classifyWalletDebits's walletIdx was always -1 (zero events on every real+// transaction) and the fee cross-check's fee.ours was always false (feeByDay+// never accumulated). The two describe blocks below pin the fix against that+// real response shape.++import { describe, it, expect, vi, beforeEach } from 'vitest';++const sqlCalls = [];+const sqlQueue = [];+vi.mock('../api/_lib/cache.js', () => ({+ acquireLock: vi.fn(async () => true),+}));+vi.mock('../api/_lib/db.js', () => ({+ sql: vi.fn(async (strings, ...values) => {+ sqlCalls.push({ text: strings.join('?'), values });+ return sqlQueue.length ? sqlQueue.shift() : [];+ }),+ isDbUnavailableError: () => false,+ isDbCapacityError: () => false,+}));+vi.mock('../api/_lib/alerts.js', () => ({ sendOpsAlert: vi.fn(async () => {}) }));++const { scanPlan, runScan, scanWallet, accountKeyStrings, classifyWalletDebits } = await import('../api/cron/x402-ring-leak-scan.js');++// Duck-typed PublicKey: has toBase58() like the real @solana/web3.js class,+// without pulling the dependency into a unit test.+class FakePubkey {+ constructor(b58) { this.b58 = b58; }+ toBase58() { return this.b58; }+ toString() { return this.b58; }+}++describe('scanPlan - three tiers, each deduped against the ones before it', () => {+ it('role wallets first, then ledger-active, then the rest of the registry', () => {+ const plan = scanPlan(+ ['ROLE_A', null, 'ROLE_B'],+ ['ROLE_A', 'L1', 'L2'], // ROLE_A already a role, dropped from ledgerActive+ ['L1', 'L2', 'R1', 'R2', 'R3'], // registry, oldest-checked_at-first from the query+ );+ expect(plan.roles).toEqual(['ROLE_A', 'ROLE_B']);+ expect(plan.ledgerActive).toEqual(['L1', 'L2']);+ expect(plan.rotation).toEqual(['R1', 'R2', 'R3']); // L1/L2 not repeated in rotation+ });++ it('never scans the same wallet twice across tiers, even with garbage input', () => {+ const plan = scanPlan(undefined, [null, 'L1', 'L1'], ['L1', 'L1', 'R1']);+ expect(plan.roles).toEqual([]);+ expect(plan.ledgerActive).toEqual(['L1']);+ expect(plan.rotation).toEqual(['R1']);+ });+});++describe('runScan - tiered budget with a fake clock', () => {+ it('scans every tier and reports partial:false when the whole plan finishes inside budget', async () => {+ const plan = { roles: ['ROLE_A'], ledgerActive: ['L1'], rotation: ['R1', 'R2'] };+ let t = 0;+ const now = () => t;+ const scanOne = async (w) => { t += 10; return { wallet: w }; };+ const { results, partial, counts } = await runScan(plan, scanOne, { budgetMs: 10_000, concurrency: 1, now });+ expect(results.map((r) => r.wallet)).toEqual(['ROLE_A', 'L1', 'R1', 'R2']);+ expect(partial).toBe(false);+ expect(counts).toEqual({ roles: 1, ledgerActive: 1, rotation: 2 });+ });++ it('a run that exhausts the budget mid-rotation returns partial:true with the finished prefix', async () => {+ const plan = { roles: ['ROLE_A'], ledgerActive: [], rotation: ['R1', 'R2', 'R3', 'R4'] };+ let t = 0;+ const now = () => t;+ // Role wallet costs 10ms; each rotation wallet costs 40ms. Budget 90ms:+ // role (10) + R1 (40) = 50, R2 starts at 50 (<90) and finishes at 90, R3+ // would start at 90 which is NOT < 90 → never started.+ const scanOne = async (w) => {+ t += w === 'ROLE_A' ? 10 : 40;+ return { wallet: w };+ };+ const { results, partial, counts } = await runScan(plan, scanOne, { budgetMs: 90, concurrency: 1, now });+ expect(results.map((r) => r.wallet)).toEqual(['ROLE_A', 'R1', 'R2']);+ expect(partial).toBe(true);+ expect(counts).toEqual({ roles: 1, ledgerActive: 0, rotation: 2 });+ });++ it('an exhausted budget still lets the role tier run in full before starving rotation', async () => {+ const plan = { roles: ['ROLE_A', 'ROLE_B'], ledgerActive: ['L1'], rotation: ['R1'] };+ let t = 0;+ const now = () => t;+ const scanOne = async (w) => { t += 50; return { wallet: w }; };+ // Budget exhausted entirely by the two role wallets (100ms used of 100ms).+ const { results, partial, counts } = await runScan(plan, scanOne, { budgetMs: 100, concurrency: 1, now });+ expect(results.map((r) => r.wallet)).toEqual(['ROLE_A', 'ROLE_B']);+ expect(partial).toBe(true);+ expect(counts).toEqual({ roles: 2, ledgerActive: 0, rotation: 0 });+ });+});++describe('scanWallet - checked_at is stamped even with zero new signatures', () => {+ class FakePublicKey { constructor(v) { this.v = v; } }+ beforeEach(() => {+ sqlCalls.length = 0;+ sqlQueue.length = 0;+ });++ it('touches checked_at on a wallet with no new signatures, without touching last_signature', async () => {+ sqlQueue.push([]); // loadCursor → no row+ const conn = {+ getSignaturesForAddress: vi.fn(async () => []), // nothing new+ getParsedTransactions: vi.fn(async () => []),+ };+ const summary = await scanWallet(conn, FakePublicKey, 'NEVER_ACTIVE', {+ allowed: new Set(), usdcMint: 'USDC_MINT', runId: 'run-touch', feeByDay: new Map(),+ });+ expect(summary.scanned).toBe(0);+ const touch = sqlCalls.find((c) => c.text.includes('checked_at') && c.values.includes('NEVER_ACTIVE'));+ expect(touch).toBeTruthy();+ // The touch never names a last_signature column write; it only carries+ // the wallet, the run id, and the now() timestamps.+ expect(touch.text).not.toMatch(/last_signature/);+ });+});++describe('accountKeyStrings - resolves the real web3.js ParsedMessageAccount shape', () => {+ it('unwraps a { pubkey: PublicKey } entry to its base58 string, not the instance', () => {+ const keys = accountKeyStrings({+ accountKeys: [+ { pubkey: new FakePubkey('WALLET_A'), signer: true, writable: true },+ { pubkey: new FakePubkey('WALLET_B'), signer: false, writable: false },+ ],+ });+ expect(keys).toEqual(['WALLET_A', 'WALLET_B']);+ });++ it('still resolves plain strings and { pubkey: string } entries the same as before', () => {+ expect(accountKeyStrings({ accountKeys: ['PLAIN', { pubkey: 'ALSO_PLAIN' }] })).toEqual(['PLAIN', 'ALSO_PLAIN']);+ });+});++describe('classifyWalletDebits - finds the wallet when accountKeys carry PublicKey instances', () => {+ it('resolves walletIdx (and so classifies events) against a { pubkey: PublicKey } account list', () => {+ const wallet = 'RING_WALLET';+ const counterparty = 'OUTSIDE_WALLET';+ const tx = {+ transaction: {+ signatures: ['sig1'],+ message: {+ accountKeys: [+ { pubkey: new FakePubkey(wallet), signer: true, writable: true },+ { pubkey: new FakePubkey(counterparty), signer: false, writable: true },+ ],+ instructions: [{+ program: 'system',+ parsed: { type: 'transfer', info: { source: wallet, destination: counterparty, lamports: 5_000_000 } },+ }],+ },+ },+ meta: { fee: 5000, err: null, innerInstructions: [] },+ };+ const { unreadable, fee, events } = classifyWalletDebits(tx, { wallet, allowed: new Set(), usdcMint: 'USDC_MINT' });+ expect(unreadable).toBe(false);+ expect(fee.ours).toBe(true); // wallet is accountKeys[0] → the fee payer+ expect(events).toHaveLength(1);+ expect(events[0]).toMatchObject({ type: 'leak', counterparty });+ });+});diff --git a/tests/x402-ring-leak-scan-run.test.js b/tests/x402-ring-leak-scan-run.test.jsindex c0a0c7895..d1cdf34dc 100644--- a/tests/x402-ring-leak-scan-run.test.js+++ b/tests/x402-ring-leak-scan-run.test.js@@ -4,16 +4,16 @@// over them took 600 to 900 s against a 300 s maxDuration, and the economy tick// re-fired the route every minute with nothing stopping a second run, so about// eight full scans overlapped at all times and burned the Solana RPC quota.-// These pin the three guards that replaced that: a lease that skips a re-fire,-// a budget that stops STARTING wallets, and a round-robin walk of the registry.+// These pin the two guards that replaced that: a lease that skips a re-fire and+// a budget that stops STARTING wallets. scanPlan's three-tier wallet selection+// (role / ledger-active / checked_at rotation) and runScan's tiered budgeting+// are covered in tests/x402-ring-leak-scan-budget.test.js.import { describe, it, expect, vi, beforeEach } from 'vitest';const lockHeld = { value: false };vi.mock('../api/_lib/cache.js', () => ({acquireLock: vi.fn(async () => !lockHeld.value),- cacheGet: vi.fn(async () => 0),- cacheSet: vi.fn(async () => {}),}));vi.mock('../api/_lib/db.js', () => ({sql: vi.fn(async () => []),@@ -23,26 +23,7 @@ vi.mock('../api/_lib/db.js', () => ({}));vi.mock('../api/_lib/alerts.js', () => ({ sendOpsAlert: vi.fn(async () => {}) }));-const { scanPlan, scanWithinBudget, default: handler } = await import('../api/cron/x402-ring-leak-scan.js');--describe('scanPlan', () => {- it('puts every role wallet first and never repeats one in the rotation', () => {- const plan = scanPlan(['ROLE_A', null, 'ROLE_B'], ['R1', 'ROLE_A', 'R2', 'R3'], 0);- expect(plan.roles).toEqual(['ROLE_A', 'ROLE_B']);- expect(plan.rotation).toEqual(['R1', 'R2', 'R3']);- });-- it('starts the registry where the last run stopped and wraps around', () => {- expect(scanPlan([], ['R1', 'R2', 'R3', 'R4'], 2).rotation).toEqual(['R3', 'R4', 'R1', 'R2']);- expect(scanPlan([], ['R1', 'R2', 'R3'], 7).start).toBe(1);- });-- it('treats a missing or garbage offset as the start', () => {- expect(scanPlan([], ['R1', 'R2'], undefined).rotation).toEqual(['R1', 'R2']);- expect(scanPlan([], ['R1', 'R2'], 'nope').rotation).toEqual(['R1', 'R2']);- expect(scanPlan([], [], 5)).toEqual({ roles: [], rotation: [], start: 0 });- });-});+const { scanWithinBudget, default: handler } = await import('../api/cron/x402-ring-leak-scan.js');describe('scanWithinBudget', () => {it('stops starting wallets at the budget and reports how far it got', async () => {