Skip to content

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.

fix(walk): validate control payloads, include the end day, and resolve walker handles

nirholas94163f247e90
diff --git a/api/walk/analytics.js b/api/walk/analytics.js
index 3811538b4..4394d36b0 100644
--- a/api/walk/analytics.js
+++ b/api/walk/analytics.js
@@ -164,7 +164,7 @@ export default wrap(async (req, res) => {
from walk_events
where avatar_id = ${avatarId}
and created_at >= ${`${from}T00:00:00Z`}
- and created_at < ${`${to}T23:59:59.999Z`}
+ and created_at < ${`${to}T00:00:00Z`}::timestamptz + interval '1 day'
group by event_name
order by count desc
`;
diff --git a/api/walk/control/[action].js b/api/walk/control/[action].js
index 7648fe616..ce4172b04 100644
--- a/api/walk/control/[action].js
+++ b/api/walk/control/[action].js
@@ -121,17 +121,28 @@ const envSchema = z
})
.strict();
-// Live state reported by the walk client when it polls. All optional — a client
-// that hasn't located the avatar yet polls without it.
-const pollStateSchema = z
- .object({
- x: z.number().finite().optional().nullable(),
- z: z.number().finite().optional().nullable(),
- facing: z.number().finite().optional().nullable(),
- motion: z.enum(['idle', 'walk', 'run']).optional().nullable(),
- env: z.string().trim().max(64).optional().nullable(),
- })
- .strict();
+// Live state reported by the walk client when it polls. Every field is validated
+// on its own and a field that fails is simply dropped: an all-or-nothing parse
+// meant one unexpected value (a motion name a newer client reports, a NaN from a
+// half-initialised frame) silently discarded the position in the same poll, and
+// /state then served a stale avatar with no error anywhere to explain it.
+const pollFieldSchemas = {
+ x: z.number().finite(),
+ z: z.number().finite(),
+ facing: z.number().finite(),
+ motion: z.enum(['idle', 'walk', 'run']),
+ env: z.string().trim().min(1).max(64),
+};
+
+function parsePollState(raw) {
+ const state = {};
+ for (const [key, schema] of Object.entries(pollFieldSchemas)) {
+ if (raw[key] === undefined) continue;
+ const parsed = schema.safeParse(raw[key]);
+ if (parsed.success) state[key] = parsed.data;
+ }
+ return state;
+}
// ── auth helpers ─────────────────────────────────────────────────────────────
@@ -309,10 +320,9 @@ async function handleCreate(req, res) {
}
async function handleMove(req, res, url) {
- const raw = await readJson(req);
- const body = parse(moveSchema, raw);
const session = await requireSession(req, res, url);
if (!session) return;
+ const body = parse(moveSchema, await readJson(req));
if (body.sessionId !== session.id) {
return error(res, 403, 'session_mismatch', 'control token does not authorize this session');
}
@@ -329,10 +339,9 @@ async function handleMove(req, res, url) {
}
async function handleGesture(req, res, url) {
- const raw = await readJson(req);
- const body = parse(gestureSchema, raw);
const session = await requireSession(req, res, url);
if (!session) return;
+ const body = parse(gestureSchema, await readJson(req));
if (body.sessionId !== session.id) {
return error(res, 403, 'session_mismatch', 'control token does not authorize this session');
}
@@ -346,10 +355,9 @@ async function handleGesture(req, res, url) {
}
async function handleSay(req, res, url) {
- const raw = await readJson(req);
- const body = parse(saySchema, raw);
const session = await requireSession(req, res, url);
if (!session) return;
+ const body = parse(saySchema, await readJson(req));
if (body.sessionId !== session.id) {
return error(res, 403, 'session_mismatch', 'control token does not authorize this session');
}
@@ -357,10 +365,9 @@ async function handleSay(req, res, url) {
}
async function handleEnv(req, res, url) {
- const raw = await readJson(req);
- const body = parse(envSchema, raw);
const session = await requireSession(req, res, url);
if (!session) return;
+ const body = parse(envSchema, await readJson(req));
if (body.sessionId !== session.id) {
return error(res, 403, 'session_mismatch', 'control token does not authorize this session');
}
@@ -389,8 +396,7 @@ async function handlePoll(req, res, url) {
motion: url.searchParams.get('motion') || undefined,
env: url.searchParams.get('cenv') || undefined,
};
- const stateParsed = pollStateSchema.safeParse(stateRaw);
- const state = stateParsed.success ? stateParsed.data : {};
+ const state = parsePollState(stateRaw);
// Claim every undelivered command for this session in fifo order, stamping
// delivered_at in the same statement so they are never handed out twice.
diff --git a/api/walk/leaderboard.js b/api/walk/leaderboard.js
index f45a495e6..be7f07665 100644
--- a/api/walk/leaderboard.js
+++ b/api/walk/leaderboard.js
@@ -208,17 +208,24 @@ export default wrap(async (req, res) => {
me = toRow(w, rankByKey.get(meKey));
me.onPage = rows.some((r) => r.key === meKey);
} else if (meKey) {
- // Walker has an identity but no qualifying metrics in this window yet.
+ // Walker has an identity but no qualifying metrics in this window yet. Same
+ // row shape as a ranked entry (the page renders both through one template),
+ // just with a null rank and zeroed figures.
+ const prof = walker.userId ? profiles.get(walker.userId) : null;
me = {
rank: null,
key: meKey,
userId: walker.userId,
anonId: walker.userId ? null : walker.anonId,
- handle: walker.userId
- ? profiles.get(walker.userId)?.username
- ? `@${profiles.get(walker.userId).username}`
- : profiles.get(walker.userId)?.display_name || 'you'
+ username: prof?.username || null,
+ handle: prof
+ ? prof.username
+ ? `@${prof.username}`
+ : prof.display_name || 'you'
: anonHandle(walker.anonId),
+ profileUrl: prof?.username ? `/u/${prof.username}` : null,
+ avatarId: prof?.avatar_id || null,
+ avatar: thumbnailUrl(prof?.thumbnail_key),
value: 0,
deltaFromYesterday: 0,
onPage: false,
diff --git a/api/walk/pilot.js b/api/walk/pilot.js
index 90ccde4ea..c8e45fc49 100644
--- a/api/walk/pilot.js
+++ b/api/walk/pilot.js
@@ -206,7 +206,10 @@ export default wrap(async (req, res) => {
try {
const bearer = extractBearer(req);
const user = bearer ? await authenticateBearer(bearer) : await getSessionUser(req);
- userId = user?.id || user?.sub || null;
+ // authenticateBearer returns { userId }, getSessionUser returns { id } —
+ // read both, or an API-key caller plans anonymously and their LLM spend is
+ // neither attributed nor held to their daily cap.
+ userId = user?.userId || user?.id || user?.sub || null;
} catch {
userId = null;
}