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(db): treat a WebSocket pool ErrorEvent as database-unavailable, not a code bug
nirholasfedc79916e74
diff --git a/api/_lib/db.js b/api/_lib/db.jsindex 3047c5c91..8dfcaef42 100644--- a/api/_lib/db.js+++ b/api/_lib/db.js@@ -179,6 +179,16 @@ export function sqlValues(rows) {// DB-unavailable alert per hour is enough.export function isDbUnavailableError(err) {if (!err) return false;+ // The WebSocket Pool (used by the scripts that share code with crons, e.g.+ // scripts/sniper-evolve.mjs) does NOT reject with an Error at all when its+ // socket fails to come up: it rejects with a DOM-style ErrorEvent whose only+ // own property is `stack`, whose `name` and `message` are both empty, and+ // whose String() is "[object ErrorEvent]". Every message-based branch below+ // therefore reads it as a code bug and 500s it. It is the opposite: a socket+ // that never opened is the purest form of "the request never reached+ // Postgres". Matched structurally, since there is no text to match on.+ if (typeof ErrorEvent !== 'undefined' && err instanceof ErrorEvent) return true;+ if (err.type === 'error' && 'error' in err && !(err instanceof Error)) return true;// esbuild minifies class names (e.g. NeonDbError → Pt in the bundle), so// err.constructor.name is unreliable in production. Use err.name instead —// NeonDbError explicitly sets `this.name = 'NeonDbError'` via a class field,diff --git a/api/cron/intel-learn.js b/api/cron/intel-learn.jsindex 421bf5665..b89ea0240 100644--- a/api/cron/intel-learn.js+++ b/api/cron/intel-learn.js@@ -50,6 +50,7 @@ export default wrapCron(async (req, res) => {return json(res, 200, {ok: true,labeled,+ relabeled,trained: train.trained,sample_size: train.sample_size,weights: train.weights || null,diff --git a/tests/coin-intel.test.js b/tests/coin-intel.test.jsindex 6c32add49..9ee107fba 100644--- a/tests/coin-intel.test.js+++ b/tests/coin-intel.test.js@@ -6,7 +6,7 @@ import {} from '../workers/agent-sniper/intel/signals.js';import { heuristicClassify, _internals as classifyInternals } from '../workers/agent-sniper/intel/classify.js';import { scoreIntel } from '../workers/agent-sniper/scorer.js';-import { correlation, deriveOutcome, learnedScore } from '../workers/agent-sniper/intel/learn.js';+import { applyGraduationTruth, correlation, deriveOutcome, learnedScore } from '../workers/agent-sniper/intel/learn.js';const SOL = _internals.LAMPORTS_PER_SOL;@@ -264,6 +264,45 @@ describe('deriveOutcome', () => {});});+describe('applyGraduationTruth', () => {+ it('leaves the derived outcome alone when we indexed no graduation', () => {+ const derived = deriveOutcome({ usd_market_cap: 20000, market_cap: 100 }, 100);+ expect(applyGraduationTruth(derived, null)).toEqual(derived);+ expect(applyGraduationTruth(derived, undefined)).toEqual(derived);+ });++ it('rescues a coin the pump.fun lookup could not answer for', () => {+ // The exact production hole: fetchCoin returns null on a 429, deriveOutcome+ // can only say 'unknown', and our own graduation index knows better.+ const o = applyGraduationTruth(deriveOutcome(null, 100), { ath_market_cap: 250000, market_cap_usd: 90000 });+ expect(o.outcome).toBe('graduated');+ expect(o.graduated).toBe(true);+ expect(o.ath_market_cap_usd).toBe(250000);+ expect(o.last_market_cap_usd).toBe(90000);+ });++ it('never flags a graduated coin as rugged', () => {+ // A stale sub-$3k bonding-curve mark makes deriveOutcome call it rugged.+ const derived = deriveOutcome({ usd_market_cap: 1000, market_cap: 5 }, 100);+ expect(derived.rugged).toBe(true);+ expect(applyGraduationTruth(derived, { ath_market_cap: 300000 }).rugged).toBe(false);+ });++ it('keeps the live market caps when the lookup did answer', () => {+ const derived = deriveOutcome({ complete: true, usd_market_cap: 90000, market_cap: 400 }, 50);+ const o = applyGraduationTruth(derived, { ath_market_cap: 1, market_cap_usd: 2 });+ expect(o.last_market_cap_usd).toBe(90000);+ expect(o.ath_market_cap_usd).toBe(90000);+ });++ it('ignores non-numeric caps on the graduation row', () => {+ const o = applyGraduationTruth(deriveOutcome(null, 100), { ath_market_cap: null, market_cap_usd: undefined });+ expect(o.outcome).toBe('graduated');+ expect(o.ath_market_cap_usd).toBeNull();+ expect(o.last_market_cap_usd).toBeNull();+ });+});+describe('learnedScore', () => {it('returns null without weights', () => {expect(learnedScore({ organic_score: 0.5 }, null)).toBeNull();