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(irl): answer malformed ids and broken rollups honestly across the IRL surfaces
nirholas06597cb090c5
diff --git a/api/_lib/irl-analytics.js b/api/_lib/irl-analytics.jsindex 3a59ca182..b36cd47fc 100644--- a/api/_lib/irl-analytics.js+++ b/api/_lib/irl-analytics.js@@ -176,23 +176,28 @@ export async function getIrlAnalyticsSummary() {GROUP BY mode ORDER BY n DESC`;+ // The series gets an explicit column alias, `AS d(day)`, and every reference is+ // qualified. Without it the bare `day` in each join condition is ambiguous between+ // the series column and the sub-select's own `day`, and Postgres refuses the whole+ // query with `column reference "day" is ambiguous`, which the caller then reported+ // as an empty summary rather than as the broken query it was.const dailySeries = await sql`SELECT- day::date AS day,+ d.day::date AS day,coalesce(p.n, 0)::int AS pins_placed,coalesce(n.n, 0)::int AS nearby_fetches- FROM generate_series(current_date - interval '29 days', current_date, interval '1 day') AS day+ FROM generate_series(current_date - interval '29 days', current_date, interval '1 day') AS d(day)LEFT JOIN (SELECT date_trunc('day', created_at) AS day, count(*) AS nFROM irl_events WHERE event_type = 'pin_created' AND created_at > now() - interval '30 days'GROUP BY 1- ) p ON p.day = day+ ) p ON p.day = d.dayLEFT JOIN (SELECT date_trunc('day', created_at) AS day, count(*) AS nFROM irl_events WHERE event_type = 'nearby_fetch' AND created_at > now() - interval '30 days'GROUP BY 1- ) n ON n.day = day- ORDER BY day ASC+ ) n ON n.day = d.day+ ORDER BY d.day ASC`;return {diff --git a/api/irl/analytics.js b/api/irl/analytics.jsindex 8f42a0edf..dbdc5bafd 100644--- a/api/irl/analytics.js+++ b/api/irl/analytics.js@@ -28,7 +28,14 @@ export default wrap(async (req, res) => {return json(res, 200, summary);} catch (err) {// Table absent (pre-deploy) or DB hiccup — report an honest empty summary- // rather than 500ing the dashboard.+ // rather than 500ing the dashboard. LOG it: this degrade is indistinguishable+ // from "no usage yet" in the response, so an unlogged failure hides a broken+ // query behind a plausible-looking wall of zeros (exactly how an ambiguous+ // column reference in the daily-series query survived unnoticed).+ console.error('[irl/analytics] summary unavailable, serving empty rollup', {+ endpoint: 'GET /api/irl/analytics',+ reason: err?.message || String(err),+ });return json(res, 200, {windows: {},placement_modes_30d: {},diff --git a/api/irl/drops.js b/api/irl/drops.jsindex 18cf321fc..b6f03e64f 100644--- a/api/irl/drops.js+++ b/api/irl/drops.js@@ -62,6 +62,15 @@ function parsePath(req) {return { url, id: parts[3] || null, action: parts[4] || null, query: url.searchParams };}+// `irl_drops.id` is a UUID column, so a drop id that isn't a UUID can never name a+// row: Postgres rejects the cast with `invalid input syntax for type uuid` and the+// read 500s before any handler logic runs. Validate the path segment at the boundary+// so `/api/irl/drops/not-a-uuid` is a clean 400 on every verb.+const DROP_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;+function isValidDropId(id) {+ return typeof id === 'string' && DROP_UUID_RE.test(id);+}+// Presence proof: the same fix token the nearby read enforces, bound to the// caller's claimed point. Returns { ok } or { ok:false, reason }.async function checkPresence(req, lat, lng) {@@ -75,6 +84,7 @@ export default wrap(async (req, res) => {if (req.method === 'OPTIONS') return res.end();const { id, action, query } = parsePath(req);+ if (id && !isValidDropId(id)) return error(res, 400, 'bad_request', 'invalid drop id');const session = await getSessionUser(req).catch(() => null);const userId = session?.id ?? null;const deviceToken = readDeviceToken(req);diff --git a/api/irl/interactions.js b/api/irl/interactions.jsindex b0642b147..73090bf73 100644--- a/api/irl/interactions.js+++ b/api/irl/interactions.js@@ -208,6 +208,12 @@ export default wrap(async (req, res) => {const body = req.body ?? {};const pinId = body.pinId;if (!pinId) return json(res, 400, { error: 'pinId required' });+ // `irl_pins.id` / `irl_interactions.pin_id` are UUID columns, so a non-UUID id+ // is a malformed request, not a row that happens not to exist. Validate at the+ // boundary: without this the pin lookup below hands the text straight to+ // Postgres, which raises `invalid input syntax for type uuid` and 500s the+ // request. Same strict guard the sibling moderation + privacy paths use.+ if (!isUuid(pinId)) return json(res, 400, { error: 'invalid pinId' });const type = TYPES.has(body.type) ? body.type : 'view';const message = typeof body.message === 'string'@@ -423,6 +429,9 @@ export default wrap(async (req, res) => {// ── GET — public count for a single pin ───────────────────────────────────if (req.method === 'GET' && req.query.pinId) {+ // Same boundary guard as the POST path: `pin_id` is a UUID column, so a+ // garbage id must be a 400, never a Postgres cast error surfacing as a 500.+ if (!isUuid(req.query.pinId)) return json(res, 400, { error: 'invalid pinId' });const [agg] = await sql`SELECTCOUNT(*)::int AS total,diff --git a/api/irl/report.js b/api/irl/report.jsindex 73a1c6cc3..c1e992ec8 100644--- a/api/irl/report.js+++ b/api/irl/report.js@@ -33,6 +33,7 @@ import { sql } from '../_lib/db.js';import { getSessionUser } from '../_lib/auth.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { sendOpsAlert } from '../_lib/alerts.js';+import { readDeviceToken } from '../_lib/irl-auth.js';// Distinct reporters required before a pin is queued out of public view.const REPORT_HIDE_THRESHOLD = 3;@@ -115,8 +116,13 @@ export default wrap(async (req, res) => {const reasonStored = detail ? `${reason}: ${detail}` : reason;const session = await getSessionUser(req).catch(() => null);- const deviceToken = (typeof body.deviceToken === 'string' && body.deviceToken.length)- ? body.deviceToken : null;+ // H2 transport: the device credential arrives in the `x-irl-device` HEADER, with+ // the body as the documented fallback. Reading only `body.deviceToken` (as this+ // path used to) silently broke both protections that depend on knowing WHICH+ // device is reporting for a header-only client: the owner could self-report their+ // own pin as an "independent" reporter, and the per-device dedup collapsed to the+ // much coarser per-IP fallback. readDeviceToken null-guards empty/whitespace.+ const deviceToken = readDeviceToken(req);// The pin must exist and still be live. A 404 here is honest — you can't report// a pin that isn't there (already expired, deleted, or never existed).diff --git a/api/irl/world-lines.js b/api/irl/world-lines.jsindex c88b7508e..935bb350d 100644--- a/api/irl/world-lines.js+++ b/api/irl/world-lines.js@@ -88,8 +88,7 @@ async function ensureTables() {// this table is a hard dependency, not an optional one. Provision it through the// definition that owns it (api/irl/pins.js) rather than a second copy of the DDL:// on a database where no pin has ever been placed, `nearby` and the single-quest- // read otherwise 500 with a raw `relation "irl_pins" does not exist`. Imported- // lazily so the pins handler's module graph only loads when a World Line is used.+ // read otherwise 500 with a raw `relation "irl_pins" does not exist`.await ensurePinsSchema();await sql`CREATE TABLE IF NOT EXISTS irl_world_lines (