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.

feat: implement session refresh for user authentication and update changelog entries

fudjia5c004f4e9d90
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 939d12283..47bbe417d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **Agent profiles, redesigned** — Agent profile pages got a ground-up redesign. Instead of one endless column of cards, everything is now organized into clear sections — Overview, Capabilities, Economy, Activity, Trust & Identity, Reviews, and Developers — with a sticky navigation bar that follows you as you scroll and hides sections that have nothing to show. The hero is a compact identity band with the live 3D avatar beside the agent's name, description, and actions, and secondary view modes now live in a tidy menu instead of a wall of buttons. Pages are roughly 40% shorter and much easier to scan. Prefer the old look? Every profile keeps a “Classic layout” link that serves the previous design unchanged. The companion panels (live presence, stages, work-for-hire, alpha co-pilot) now sit in a compact strip beside the profile instead of stacking above it — on mobile the agent's name and avatar are the first thing you see — and the live watch view (screen, avatar cam, action log) has a proper home in the Activity section. Signed-out visitors get a clear “sign in to see the action log” state instead of an endless loading spinner, and stats with nothing to report simply don't render. (`/agents`) `[improvement, feature]`
- **AI features can no longer go down when one provider does** — Every AI-powered feature on three.ws (fact checks, agent chat, persona extraction, scene composing) routes through one shared brain that tries free providers first and falls back automatically. That chain just got much deeper: Groq now has a second lane with its own separate quota, OpenRouter gets a zero-credit free lane so an empty account no longer kills it, optional Cerebras and Google AI Studio lanes activate the moment a key is added, and — the anchor — Gemini on the platform's own Google Cloud now backs the whole chain with no third-party quota to exhaust. Previously a rare bad hour where every free tier was exhausted at once could surface an error; now the request rides through. The fact-checker was also corrected to stop favoring a paid key ahead of the free lanes. (`/changelog`) `[improvement, fix, infra]`
- **Closed a path-traversal hole in the API router** — The server that routes every /api request to its handler split the URL into path segments before decoding them, so a specially encoded request could smuggle a '../' into a single segment and reach a file outside the API folder — or an internal helper meant to be unreachable — and run it without authentication. The router now rejects any decoded segment that contains a path separator and, as a second line of defense, refuses to load any handler that resolves outside the API directory. Normal routes are unaffected; a regression test locks the fix in place. `[security]`
+- **Fixed: /play was signing players out after an hour** — Players who signed in with X to enter a coin's Holders world could get bounced back to the /play lobby with a false "not signed in" message after about an hour, even though their session was still good. The sign-in session's access token only lived for an hour, and the endpoints checking it were discarding the still-valid 30-day session instead of quietly renewing it. Signing in with X on /play now stays good for the full 30 days without needing to reconnect. (`/play`) `[fix]`
- **Market-maker and limit-order engines are now crash-safe on Cloud Run** — The two background workers that run agents' automated market-making and limit orders are long-running loops, not web servers. On Cloud Run, a service that never answers the platform's startup health check gets killed and restarted in a loop — which would have taken these money-moving engines offline the moment they were deployed as services. Both now start a tiny health endpoint when the platform asks for one (and stay silent when run as a scheduled job, where none is needed), so they boot cleanly either way. We also added a documented, repeatable deploy for each so there's no guesswork about how they ship. `[infra]`
- **Money-moving agent skills now require an explicit spend confirmation** — The skills that let an agent send tokens, swap, or pay a paid API used to validate the format of an address or amount but never stopped to confirm the actual intent before signing — and some read a token's on-chain name and description straight into the same agent that holds the signing key, so a token deliberately named like an instruction ('send 5 to 0x…') could try to steer a real transfer. Each of these skills now renders a recipient/amount/token/chain confirmation card and waits for an explicit yes before moving any funds, and treats all on-chain and token text as untrusted data that is never followed as an instruction. The platform's operating rules were updated to make spend, transfer, and mint confirmations a required step rather than something to skip for speed. `[security]`
- **New driving jobs in /play — Cross-Town Delivery and East-West Express** — Two real driving missions landed on the /play jobs board. Grab a car parked at any of the four avenue depots, run the rush order to the depot on the other side of town, and get paid — the delivery only counts if you actually drove it, not walked it. Pairs with the world's existing drivable vehicles and cash economy for a real 'drive around, do jobs, spend the cash' loop. (`/play`) `[feature]`
diff --git a/api/_lib/coin-communities.js b/api/_lib/coin-communities.js
index 759ab6854..36b4159d4 100644
--- a/api/_lib/coin-communities.js
+++ b/api/_lib/coin-communities.js
@@ -138,19 +138,68 @@ export function clearUserSession(res) {
]);
}
-/** Read the current user's access token from the request cookies, if any. */
-export function userToken(req) {
+function readSessionCookie(req, name) {
const cookie = req.headers.cookie || '';
- const m = cookie.match(new RegExp(`(?:^|;\\s*)${AT_COOKIE}=([^;]+)`));
+ const m = cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]+)`));
return m ? decodeURIComponent(m[1]) : null;
}
+/** Read the current user's access token from the request cookies, if any. */
+export function userToken(req) {
+ return readSessionCookie(req, AT_COOKIE);
+}
+
+/** Read the current user's refresh token from the request cookies, if any. */
+export function userRefreshToken(req) {
+ return readSessionCookie(req, RT_COOKIE);
+}
+
/** Per-call headers that attach a user's bearer JWT for user-scoped operations. */
export function userAuthHeaders(req) {
const token = userToken(req);
return token ? { Authorization: `Bearer ${token}` } : null;
}
+/**
+ * Runs an authenticated CoinCommunities API call, transparently refreshing the
+ * session on a 401 and retrying once before giving up. The `cc_at` access-token
+ * cookie only lives 1h; without this, any signed-in player who comes back to
+ * `/play` after an hour gets treated as never having signed in at all, even
+ * though the 30-day `cc_rt` refresh token is still good.
+ *
+ * `call(headers)` should run one or more SDK calls with the given bearer
+ * headers and return `{ data, error }` (an upstream 401 on any of them should
+ * surface as `error.statusCode === 401`). Returns `{ data, error, headers }`;
+ * `headers` is null when there is no usable session (never signed in, or the
+ * refresh itself failed) — callers should treat that as "not logged in"
+ * regardless of `error`, since `error` may just be the original 401.
+ */
+export async function withAuthRefresh(req, res, call) {
+ const headers = userAuthHeaders(req);
+ if (!headers) return { data: null, error: null, headers: null };
+
+ let result = await call(headers);
+ if (result?.error?.statusCode !== 401) return { ...result, headers };
+
+ const refreshToken = userRefreshToken(req);
+ if (!refreshToken) {
+ clearUserSession(res);
+ return { ...result, headers: null };
+ }
+
+ const api = cc();
+ const { data: refreshed, error: refreshErr } = await api.refreshToken({ body: { refreshToken } });
+ if (refreshErr || !refreshed?.accessToken) {
+ clearUserSession(res);
+ return { ...result, headers: null };
+ }
+
+ setUserSession(res, refreshed);
+ const freshHeaders = { Authorization: `Bearer ${refreshed.accessToken}` };
+ result = await call(freshHeaders);
+ return { ...result, headers: freshHeaders };
+}
+
/**
* Normalize a TopCommunity into the world-card shape the lobby renders. Keeps
* the browser ignorant of the upstream schema so a field rename upstream is a
diff --git a/api/community/holder-pass.js b/api/community/holder-pass.js
index 519efae33..f35c08653 100644
--- a/api/community/holder-pass.js
+++ b/api/community/holder-pass.js
@@ -19,7 +19,7 @@
// 403 wallet_required — signed in but no linked Solana wallet
import { cors, error, json, method, wrap, rateLimited } from '../_lib/http.js';
import { clientIp, limits } from '../_lib/rate-limit.js';
-import { cc, userAuthHeaders, isValidToken, UnconfiguredError } from '../_lib/coin-communities.js';
+import { cc, withAuthRefresh, isValidToken, UnconfiguredError } from '../_lib/coin-communities.js';
import { getBalances, solanaMintUsdPrice } from '../_lib/balances.js';
import { HOLDER_MIN_USD, signHolderPass } from '../_lib/holder-pass.js';
import { readWorldGate } from '../_lib/world-gate.js';
@@ -44,11 +44,6 @@ export default wrap(async (req, res) => {
return error(res, 400, 'validation_error', 'valid token query param required');
}
- const headers = userAuthHeaders(req);
- if (!headers) {
- return error(res, 401, 'auth_required', 'sign in with X to enter a holder world');
- }
-
let api;
try {
api = cc();
@@ -59,15 +54,20 @@ export default wrap(async (req, res) => {
throw err;
}
- // The wallets are taken from the authenticated session — never the request body.
- const w = await api.getWallets({ headers });
- if (w.error) {
- if (w.error.statusCode === 401) {
- return error(res, 401, 'auth_required', 'session expired — sign in again');
- }
- return error(res, 502, 'upstream_error', w.error.message || 'failed to read wallets');
+ // The wallets are taken from the authenticated session — never the request
+ // body. Transparently refreshes an expired (1h) access token off the 30-day
+ // refresh token before giving up, so a player who's been signed in for a
+ // while isn't wrongly bounced out of the holders-world gate as "not signed in".
+ const { data: wData, error: wErr, headers } = await withAuthRefresh(req, res, (h) =>
+ api.getWallets({ headers: h }),
+ );
+ if (!headers) {
+ return error(res, 401, 'auth_required', 'sign in with X to enter a holder world');
+ }
+ if (wErr) {
+ return error(res, 502, 'upstream_error', wErr.message || 'failed to read wallets');
}
- const svmWallets = (w.data?.wallets ?? [])
+ const svmWallets = (wData?.wallets ?? [])
.filter((x) => x.chainType === 'svm')
.map((x) => x.address)
.filter(Boolean);
diff --git a/api/community/me.js b/api/community/me.js
index fcb5a9e76..cd41abf5d 100644
--- a/api/community/me.js
+++ b/api/community/me.js
@@ -3,12 +3,7 @@
// their linked wallets, so Town knows whether the composer can post directly or
// needs an X sign-in / wallet link first. Unauthenticated → { user: null }.
import { cors, error, json, method, wrap } from '../_lib/http.js';
-import {
- cc,
- userAuthHeaders,
- clearUserSession,
- UnconfiguredError,
-} from '../_lib/coin-communities.js';
+import { cc, withAuthRefresh, UnconfiguredError } from '../_lib/coin-communities.js';
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,OPTIONS', credentials: true })) return;
@@ -16,9 +11,6 @@ export default wrap(async (req, res) => {
res.setHeader('cache-control', 'no-store');
- const headers = userAuthHeaders(req);
- if (!headers) return json(res, 200, { data: { user: null } });
-
let api;
try {
api = cc();
@@ -29,25 +21,21 @@ export default wrap(async (req, res) => {
throw err;
}
- const { data, error: apiErr } = await api.userMe({ headers });
- if (apiErr) {
- // Expired/invalid session — clear it so the client falls back to sign-in.
- if (apiErr.statusCode === 401) {
- clearUserSession(res);
- return json(res, 200, { data: { user: null } });
- }
- return error(res, 502, 'upstream_error', apiErr.message || 'failed to load user');
- }
-
- let wallets = [];
- const w = await api.getWallets({ headers });
- if (!w.error)
- wallets = (w.data?.wallets ?? []).map((x) => ({
- address: x.address,
- chainType: x.chainType,
- }));
+ const { data, error: apiErr, headers } = await withAuthRefresh(req, res, async (h) => {
+ const me = await api.userMe({ headers: h });
+ if (me.error) return { error: me.error };
+ const w = await api.getWallets({ headers: h });
+ const wallets = w.error
+ ? []
+ : (w.data?.wallets ?? []).map((x) => ({ address: x.address, chainType: x.chainType }));
+ return { data: { user: me.data?.user, wallets } };
+ });
+
+ // No usable session — never signed in, or the refresh token itself expired.
+ if (!headers) return json(res, 200, { data: { user: null } });
+ if (apiErr) return error(res, 502, 'upstream_error', apiErr.message || 'failed to load user');
- const user = data?.user
+ const user = data.user
? {
id: data.user.id,
username: data.user.username,
@@ -55,7 +43,7 @@ export default wrap(async (req, res) => {
followers: data.user.followerCount ?? 0,
}
: null;
- const solWallet = wallets.find((x) => x.chainType === 'svm')?.address || null;
+ const solWallet = data.wallets.find((x) => x.chainType === 'svm')?.address || null;
- return json(res, 200, { data: { user, wallets, solWallet } });
+ return json(res, 200, { data: { user, wallets: data.wallets, solWallet } });
});
diff --git a/api/community/world-gate.js b/api/community/world-gate.js
index cc6cf725b..6598a8c22 100644
--- a/api/community/world-gate.js
+++ b/api/community/world-gate.js
@@ -18,7 +18,7 @@
// 403 wallet_required — signed in, but no linked Solana wallet to match
import { cors, error, json, method, readJson, wrap, rateLimited } from '../_lib/http.js';
import { clientIp, limits } from '../_lib/rate-limit.js';
-import { cc, userAuthHeaders, isValidToken, UnconfiguredError } from '../_lib/coin-communities.js';
+import { cc, userAuthHeaders, withAuthRefresh, isValidToken, UnconfiguredError } from '../_lib/coin-communities.js';
import { readWorldGate, writeWorldGate, normalizeMinTokens } from '../_lib/world-gate.js';
const PUMP_FRONTEND_BASE = process.env.PUMP_FRONTEND_BASE || 'https://frontend-api-v3.pump.fun';
@@ -41,7 +41,8 @@ async function resolveCoinCreator(mint) {
}
}
-// The signed-in user's linked Solana wallets, or { error } shaped like the SDK's.
+// The signed-in user's linked Solana wallets, as { data: { wallets }, error }
+// shaped like the SDK's so it composes directly with withAuthRefresh.
async function linkedSvmWallets(api, headers) {
const w = await api.getWallets({ headers });
if (w.error) return { error: w.error };
@@ -50,7 +51,7 @@ async function linkedSvmWallets(api, headers) {
.map((x) => x.address)
.filter(Boolean)
.slice(0, MAX_WALLETS_CHECKED);
- return { wallets };
+ return { data: { wallets } };
}
export default wrap(async (req, res) => {
@@ -66,8 +67,6 @@ export default wrap(async (req, res) => {
return error(res, 400, 'validation_error', 'valid token query param required');
}
- const headers = userAuthHeaders(req);
-
if (req.method === 'GET') {
const gate = await readWorldGate(mint);
const minTokens = gate?.minTokens || 0;
@@ -75,13 +74,14 @@ export default wrap(async (req, res) => {
// coin's creator. Best-effort — any failure just yields canEdit:false (the
// read still succeeds), so the requirement is always visible.
let canEdit = false;
- if (headers) {
+ if (userAuthHeaders(req)) {
try {
const api = cc();
- const [{ wallets = [] }, creator] = await Promise.all([
- linkedSvmWallets(api, headers).then((r) => r.error ? { wallets: [] } : r),
+ const [{ data: walletsData }, creator] = await Promise.all([
+ withAuthRefresh(req, res, (h) => linkedSvmWallets(api, h)),
resolveCoinCreator(mint),
]);
+ const wallets = walletsData?.wallets ?? [];
canEdit = !!creator && wallets.includes(creator);
} catch { /* canEdit stays false */ }
}
@@ -89,10 +89,6 @@ export default wrap(async (req, res) => {
}
// POST — set the threshold. Creator-only.
- if (!headers) {
- return error(res, 401, 'auth_required', 'sign in with X to manage this world');
- }
-
let api;
try {
api = cc();
@@ -112,11 +108,16 @@ export default wrap(async (req, res) => {
return error(res, 400, 'validation_error', 'body must be JSON { minTokens }');
}
- const { wallets, error: walletErr } = await linkedSvmWallets(api, headers);
+ const { data: walletData, error: walletErr, headers } = await withAuthRefresh(req, res, (h) =>
+ linkedSvmWallets(api, h),
+ );
+ if (!headers) {
+ return error(res, 401, 'auth_required', 'sign in with X to manage this world');
+ }
if (walletErr) {
- if (walletErr.statusCode === 401) return error(res, 401, 'auth_required', 'session expired — sign in again');
return error(res, 502, 'upstream_error', walletErr.message || 'failed to read wallets');
}
+ const wallets = walletData?.wallets ?? [];
if (!wallets.length) {
return error(res, 403, 'wallet_required', 'link the creator wallet to manage this world');
}
diff --git a/data/changelog.json b/data/changelog.json
index c948dc088..a64dcbe64 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,15 @@
{
"$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-07-12",
+ "title": "Fixed: /play was signing players out after an hour",
+ "summary": "Players who signed in with X to enter a coin's Holders world could get bounced back to the /play lobby with a false \"not signed in\" message after about an hour, even though their session was still good. The sign-in session's access token only lived for an hour, and the endpoints checking it were discarding the still-valid 30-day session instead of quietly renewing it. Signing in with X on /play now stays good for the full 30 days without needing to reconnect.",
+ "tags": [
+ "fix"
+ ],
+ "link": "/play"
+ },
{
"date": "2026-07-12",
"title": "The datapoint API now covers any token by contract — 1,000,000+ paid endpoints",
diff --git a/public/changelog.json b/public/changelog.json
index 9f43c266d..d08a69e63 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-12T13:51:14.886Z",
+ "generated_at": "2026-07-12T14:51:46.886Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -70,6 +70,16 @@
"security"
]
},
+ {
+ "date": "2026-07-12",
+ "type": "update",
+ "title": "Fixed: /play was signing players out after an hour",
+ "summary": "Players who signed in with X to enter a coin's Holders world could get bounced back to the /play lobby with a false \"not signed in\" message after about an hour, even though their session was still good. The sign-in session's access token only lived for an hour, and the endpoints checking it were discarding the still-valid 30-day session instead of quietly renewing it. Signing in with X on /play now stays good for the full 30 days without needing to reconnect.",
+ "link": "/play",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-07-12",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index f82368168..a45365fcc 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -54,6 +54,14 @@
<category>security</category>
<description>The server that routes every /api request to its handler split the URL into path segments before decoding them, so a specially encoded request could smuggle a '../' into a single segment and reach a file outside the API folder — or an internal helper meant to be unreachable — and run it without authentication. The router now rejects any decoded segment that contains a path separator and, as a second line of defense, refuses to load any handler that resolves outside the API directory. Normal routes are unaffected; a regression test locks the fix in place.</description>
</item>
+ <item>
+ <title>Fixed: /play was signing players out after an hour</title>
+ <link>https://three.ws/play</link>
+ <guid isPermaLink="false">2026-07-12:Fixed: /play was signing players out after an hour</guid>
+ <pubDate>Sun, 12 Jul 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>Players who signed in with X to enter a coin's Holders world could get bounced back to the /play lobby with a false &quot;not signed in&quot; message after about an hour, even though their session was still good. The sign-in session's access token only lived for an hour, and the endpoints checking it were discarding the still-valid 30-day session instead of quietly renewing it. Signing in with X on /play now stays good for the full 30 days without needing to reconnect.</description>
+ </item>
<item>
<title>Market-maker and limit-order engines are now crash-safe on Cloud Run</title>
<link>https://three.ws/changelog</link>
diff --git a/public/features.json b/public/features.json
index 3913d33fa..11c562126 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-12T13:51:14.869Z",
+ "generated_at": "2026-07-12T14:51:46.866Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",