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(agent-index): keep crawling past an on-chain string Postgres cannot store
nirholasbaa3a926f29d
diff --git a/api/_lib/onchain-events.js b/api/_lib/onchain-events.jsindex 825885764..4cc6fddcd 100644--- a/api/_lib/onchain-events.js+++ b/api/_lib/onchain-events.js@@ -33,9 +33,58 @@ const CLASS_SET = new Set(EVENT_CLASSES);const MAX_TEXT = 256;+// Deepest payload nesting the sanitizer walks. On-chain payloads are shallow+// objects the crawlers build themselves, so this is a cycle guard, not a limit+// any real event approaches.+const MAX_PAYLOAD_DEPTH = 8;++/**+ * Strip the two code points Postgres refuses to store, from a string that came+ * off a chain and is therefore arbitrary bytes decoded as UTF-8.+ *+ * A NUL (U+0000) inside a jsonb value fails the whole INSERT with+ * `unsupported Unicode escape sequence`, and a lone surrogate fails it with an+ * invalid-escape error of its own. Because recordEvents is awaited BEFORE the+ * crawl cursor advances, one such byte in one log wedges that chain forever:+ * every tick re-reads the same block range, hits the same log, throws, and+ * leaves the cursor where it was. Measured on 2026-08-28: Base mainnet had been+ * frozen 310 hours, Ethereum 97 and Gnosis 371, all three with+ * `unsupported Unicode escape sequence` sitting in erc8004_crawl_cursor.last_error.+ *+ * The event is worth more than the unstorable byte, so drop the byte and keep+ * the row rather than rejecting history the chain really contains.+ * @param {string} s+ * @returns {string}+ */+export function sanitizeText(s) {+ return String(s)+ .replace(/\u0000/g, '')+ .replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, '\uFFFD');+}++/**+ * Apply sanitizeText to every string in a payload, keys included: a metadata+ * key is as much on-chain bytes as its value is.+ * @param {unknown} v+ * @param {number} [depth]+ * @returns {unknown}+ */+export function sanitizePayload(v, depth = 0) {+ if (typeof v === 'string') return sanitizeText(v);+ if (!v || typeof v !== 'object') return v;+ // Past the guard the subtree is dropped rather than passed through: handing+ // back an unwalked object would put unsanitized on-chain strings straight+ // into jsonb, which is the exact failure this function exists to prevent.+ if (depth >= MAX_PAYLOAD_DEPTH) return null;+ if (Array.isArray(v)) return v.map((item) => sanitizePayload(item, depth + 1));+ const out = {};+ for (const [k, val] of Object.entries(v)) out[sanitizeText(k)] = sanitizePayload(val, depth + 1);+ return out;+}+const clip = (v) => {if (v == null) return null;- const s = String(v).trim();+ const s = sanitizeText(v).trim();if (!s) return null;return s.length > MAX_TEXT ? s.slice(0, MAX_TEXT) : s;};@@ -94,7 +143,7 @@ export function normalizeEvent(e) {occurredAt,actor: clip(e.actor),counterparty: clip(e.counterparty),- payload: e.payload && typeof e.payload === 'object' ? e.payload : {},+ payload: e.payload && typeof e.payload === 'object' ? sanitizePayload(e.payload) : {},};}diff --git a/data/changelog.json b/data/changelog.jsonindex ce76736fa..dc8a97e10 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,14 @@{"$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. `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-08-28",+ "title": "Agent history on Base, Ethereum and Gnosis is moving again",+ "summary": "The cross-chain agent index had stopped advancing on three networks. A single unprintable byte inside an on-chain metadata string was rejected by the database, and because the index only records its position after a successful write, every following run re-read the same block and hit the same byte. Base had been frozen for 13 days, Gnosis for 15 and Ethereum for 4. Those bytes are now stripped on the way in, so the event is kept and the crawl moves past it. Registrations, ownership transfers, metadata edits and reputation attestations on those chains flow into agent profiles again.",+ "tags": [+ "fix"+ ]+ },{"date": "2026-08-27","title": "Every outside service the site talks to now has a time limit and a plan B",diff --git a/tests/agent-index.test.js b/tests/agent-index.test.jsindex a640b804d..07072e1dd 100644--- a/tests/agent-index.test.js+++ b/tests/agent-index.test.js@@ -17,7 +17,14 @@ import {SOLANA_SWEEP_BATCH,SOLANA_SWEEP_PERIOD_MIN,} from '../api/_lib/solana-agent-events.js';-import { normalizeEvent, toDate, agentRef, EVENT_CLASSES } from '../api/_lib/onchain-events.js';+import {+ normalizeEvent,+ toDate,+ agentRef,+ EVENT_CLASSES,+ sanitizeText,+ sanitizePayload,+} from '../api/_lib/onchain-events.js';import { sweepCycleMin } from '../api/_lib/ops/index-lag.js';import { nextChunkSize, backoffChunkSize, isRangeRejection } from '../api/cron/[name].js';import { splitCapabilities } from '../api/explore-item.js';@@ -286,6 +293,53 @@ describe('normalizeEvent', () => {it('rejects an unknown event class', () => {expect(normalizeEvent({ ...good, eventClass: 'airdrop' })).toBe(null);});++ // Measured on 2026-08-28: Base mainnet's crawl cursor had been frozen 310+ // hours, Ethereum's 97 and Gnosis's 371, every one of them holding+ // `unsupported Unicode escape sequence` in last_error. A NUL byte inside an+ // on-chain metadata string failed the jsonb INSERT, recordEvents is awaited+ // before the cursor advances, so the next tick re-read the same range and+ // hit the same byte forever.+ it('keeps an event whose on-chain strings carry bytes jsonb cannot store', () => {+ const NUL = String.fromCharCode(0);+ const row = normalizeEvent({+ ...good,+ chain: 'evm',+ chainId: 8453,+ eventClass: 'metadata',+ eventName: `MetadataSet${NUL}`,+ actor: `0xabc${NUL}`,+ payload: { [`ur${NUL}i`]: `ipfs://q${NUL}m`, tags: [`a${NUL}b`] },+ });+ expect(row).not.toBe(null);+ expect(row.eventName).toBe('MetadataSet');+ expect(row.actor).toBe('0xabc');+ expect(row.payload).toEqual({ uri: 'ipfs://qm', tags: ['ab'] });+ expect(JSON.stringify(row.payload)).not.toContain('\\u0000');+ });+});++describe('sanitizeText', () => {+ it('drops NUL and replaces a lone surrogate, leaving real text alone', () => {+ expect(sanitizeText(`a${String.fromCharCode(0)}b`)).toBe('ab');+ expect(sanitizeText(`a${String.fromCharCode(0xd800)}b`)).toBe('a\uFFFDb');+ expect(sanitizeText('a\u{1F600}b')).toBe('a\u{1F600}b');+ });+});++describe('sanitizePayload', () => {+ it('walks arrays and nested objects, keys included', () => {+ const NUL = String.fromCharCode(0);+ expect(sanitizePayload({ [`k${NUL}`]: [{ v: `x${NUL}y` }] })).toEqual({ k: [{ v: 'xy' }] });+ });++ it('drops a subtree past the depth guard rather than passing it through raw', () => {+ // Returning the unwalked object would hand unsanitized on-chain strings+ // straight to jsonb, which is the failure this function exists to stop.+ let deep = { v: `x${String.fromCharCode(0)}y` };+ for (let i = 0; i < 12; i += 1) deep = { n: deep };+ expect(JSON.stringify(sanitizePayload(deep))).not.toContain('\\u0000');+ });});describe('toDate', () => {