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
feat: Solana RPC connection and fallback improvements
nirholas441ec27438ef
diff --git a/api/_lib/solana/connection.js b/api/_lib/solana/connection.jsindex 59663c42a..0dee8036f 100644--- a/api/_lib/solana/connection.js+++ b/api/_lib/solana/connection.js@@ -181,6 +181,14 @@ export function shouldRotate(status) {// Retrying after Nms") never fires. Cooldowns live in the process-wide map, so a// quota-dead provider is skipped on the very next call (and next cron tick), not// re-probed every time.+//+// Log severity tracks actionability, not event count. A single provider getting+// parked while the call transparently lands on the next one is the failover doing+// its job — the request still succeeds (HTTP 200), so it logs at INFO. Emitting it+// at WARN flooded Vercel's `level:warning` view with non-actionable failover+// chatter (the source of the recurring "[solana-rpc] … 429 — cooling" warnings).+// The genuinely actionable condition — every provider in the chain failing within+// one request, so the caller gets nothing back — is the only WARN.export function makeRotatingFetch(endpoints) {return async function rotatingFetch(_info, init) {let lastErr = null;@@ -200,7 +208,9 @@ export function makeRotatingFetch(endpoints) {const alreadyCooling = isEndpointCooling(url);const ms = markEndpointCooldown(url, resp.status, bodyText);if (!alreadyCooling) {- console.warn(+ // INFO, not WARN: the request continues to the next provider and+ // still succeeds. This is the redundancy working, not a fault.+ console.log(`[solana-rpc] ${maskUrl(url)} ${resp.status} — cooling ${Math.round(ms / 60_000)}m, failing over`,);}@@ -224,6 +234,12 @@ export function makeRotatingFetch(endpoints) {.sort((a, b) => (_endpointCooldown.get(a) || 0) - (_endpointCooldown.get(b) || 0))[0];return fetch(soonest, init);}+ // Reached the end with every attempted provider failing in this one request —+ // the caller gets an error, not data. THIS is worth a warning: the whole+ // failover chain is down, not just one lane.+ console.warn(+ `[solana-rpc] all ${endpoints.length} endpoints failed this request — ${lastErr?.message || 'unknown error'}`,+ );throw lastErr || new Error('all solana rpc endpoints failed');};}diff --git a/api/_lib/solana/rpc-fallback.js b/api/_lib/solana/rpc-fallback.jsindex 60ec396f4..468a545f6 100644--- a/api/_lib/solana/rpc-fallback.js+++ b/api/_lib/solana/rpc-fallback.js@@ -144,7 +144,11 @@ export class RpcFallback {const alreadyCooling = isEndpointCooling(this.currentUrl);const ms = markEndpointCooldown(this.currentUrl, status, String((err && err.message) || err));if (!alreadyCooling) {- console.warn(+ // INFO, not WARN: withFallback() keeps trying the remaining+ // endpoints and the call still resolves. Only an exhausted chain+ // (the throw below) is actionable — so this stays out of the+ // `level:warning` view to avoid non-actionable failover chatter.+ console.log('[rpc-fallback] %s %s — cooling %dm, rotating',maskUrl(this.currentUrl),status,@@ -157,6 +161,10 @@ export class RpcFallback {}}}+ // Every endpoint failed or is cooling — the caller gets nothing. This is the+ // actionable condition (the whole failover chain is down), so it warns where+ // the per-endpoint rotations above only log.+ console.warn(`[rpc-fallback] all ${this.urls.length} endpoints exhausted`);throw new Error('All RPC endpoints exhausted');}diff --git a/package-lock.json b/package-lock.jsonindex 1b4044e5b..f966c2f60 100644--- a/package-lock.json+++ b/package-lock.json@@ -54633,6 +54633,9 @@"license": "Apache-2.0","dependencies": {"@coral-xyz/anchor": "^0.32.1",+ "@noble/ciphers": "^1.3.0",+ "@noble/curves": "^2.2.0",+ "@noble/hashes": "^1.8.0","@solana/spl-token": "^0.4.9","@solana/web3.js": "^1.98.0","@tetsuo-ai/protocol": "^0.2.0",diff --git a/tasks/set-admin-code-env.md b/tasks/set-admin-code-env.mdindex 27f34daf4..251d4157f 100644--- a/tasks/set-admin-code-env.md+++ b/tasks/set-admin-code-env.md@@ -11,68 +11,73 @@ Every 5 minutes the world-health cron fires and logs:`ADMIN_CODE` gates write access to the Hyperfy world at world.three.ws. Without it, any visitorcan build/edit the world — this is a security gap.+> **Root cause (verified 2026-06-21):** the `protected` flag that both health checks read comes+> from **`world.three.ws/status`** — i.e. the **Cloud Run Hyperfy service** — not from any Vercel+> env var. `api/cron/world-health.js` and `api/_lib/forge-health.js` both branch on+> `status.protected === true`; neither reads `process.env.ADMIN_CODE`. **Setting `ADMIN_CODE` in+> Vercel does NOT close the gap and does NOT stop the warning.** The fix is on **Google Cloud**:+> set the admin code on the Cloud Run service so its `/status` reports `protected:true`. Live+> `/status` currently returns `{"protected":false, ...}` — the gap is open.+## What to do-### 1. Generate a strong code+### 1. Authenticate to Google Cloud++The Hyperfy world is Cloud Run service `hyperfy-world` in project `aerial-vehicle-466722-p5`+(region `us-central1`). You need Cloud Run + Secret Manager + Cloud Build access:```bash-node -e "console.log(require('crypto').randomBytes(24).toString('base64url'))"+gcloud auth login+gcloud config set project aerial-vehicle-466722-p5```-Copy the output (something like `Kx9mR2_nP4qT7vL1wJ3sY8eA6dB5cF0i`).--### 2. Set it in Vercel+### 2. Run the hardening script-Use the REST API (the CLI `env add` command writes empty strings under the Vercel plugin wrapper):+[`deploy/world/apply-hardening.sh`](../deploy/world/apply-hardening.sh) is the canonical fix. It+creates the `hyperfy-admin-code` secret (printing the generated code once — store it), grants the+runtime SA `secretAccessor`, rebuilds the image, and `gcloud run services replace`s the service+with `ADMIN_CODE` mounted:```bash-curl -X POST "https://api.vercel.com/v10/projects/prj_IWZmEnqR1pCZRCRuvhCFCDcOx5Wc/env" \- -H "Authorization: Bearer <VERCEL_TOKEN>" \- -H "Content-Type: application/json" \- -d '{- "key": "ADMIN_CODE",- "value": "<YOUR_GENERATED_CODE>",- "type": "encrypted",- "target": ["production", "preview"]- }'+bash deploy/world/apply-hardening.sh```-Or: Vercel Dashboard → Project (3dagent / prj_IWZmEnqR1pCZRCRuvhCFCDcOx5Wc) → Settings →-Environment Variables → Add → key: `ADMIN_CODE`, value: the generated code, target: Production + Preview → Save.--### 3. Set the same code in the Hyperfy world config+The code is auto-generated inside the script; no need to generate one by hand. In-world, builders+then claim rights with the chat command `/admin <code>`.-The world at world.three.ws is a Cloud Run deployment. The `ADMIN_CODE` env var needs to be set-there too so Hyperfy enforces it. See `workers/deploy/apply-hardening.sh` and-`world-three.ws-hyperfy.md` in memory for the Cloud Run update procedure.+### 3. Verify-If Cloud Run access isn't available right now, at minimum setting it in Vercel stops the-warning logs from `/api/cron/world-health`.+The script waits for the new revision and curls `/status`. Confirm it prints+`OK — world is protected`. Independently:-### 4. Redeploy--Trigger a Vercel redeploy after saving the env var:```bash-curl -X POST "https://api.vercel.com/v13/deployments" \- -H "Authorization: Bearer <VERCEL_TOKEN>" \- -H "Content-Type: application/json" \- -d '{"name":"3dagent","gitSource":{"type":"github","repoId":"<REPO_ID>","ref":"main"}}'+curl -fsS https://world.three.ws/status # expect "protected":true```-Or just push an empty commit to trigger the deploy hook.+After the next world-health cron tick (≤15 min) the `[world-health] degraded` warning stops and+the check reports `status: "ok"`.++### (Optional) Vercel `ADMIN_CODE`-### 5. Verify+Only set `ADMIN_CODE` in Vercel if a Vercel-side feature is later wired to read it — as of+2026-06-21 nothing on the Vercel side does, so this step is not required to fix the gap. If you+do, use the REST API (the CLI `env add` writes empty strings under the plugin wrapper):-After the deploy, wait for the next world-health cron tick (≤5 minutes) and confirm the-warning log is gone. The health check should report `ok` instead of `degraded`.+```bash+curl -X POST "https://api.vercel.com/v10/projects/prj_IWZmEnqR1pCZRCRuvhCFCDcOx5Wc/env" \+ -H "Authorization: Bearer <VERCEL_TOKEN>" -H "Content-Type: application/json" \+ -d '{"key":"ADMIN_CODE","value":"<CODE>","type":"encrypted","target":["production","preview"]}'+```## Relevant files-- `api/cron/world-health.js` — the cron that emits the warning-- `workers/deploy/apply-hardening.sh` — sets ADMIN_CODE on the Cloud Run Hyperfy world+- `api/cron/world-health.js` — the cron that emits the warning (reads `world.three.ws/status`)+- `api/_lib/forge-health.js` — second consumer; also branches on `status.protected`+- `deploy/world/apply-hardening.sh` — sets ADMIN_CODE on the Cloud Run Hyperfy world (the real fix)## Acceptance criteria+- `https://world.three.ws/status` reports `"protected":true`- `[world-health] degraded` no longer appears in Vercel logs- The health check returns `status: "ok"` (or at least no longer mentions ADMIN_CODE)