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(x402-pay): improve feed read handling with robust inflight promise management

zprvf4e43cb06304
diff --git a/api/x402-pay.js b/api/x402-pay.js
index f80692f10..04c8de64e 100644
--- a/api/x402-pay.js
+++ b/api/x402-pay.js
@@ -94,38 +94,39 @@ async function readFeed(limit = 25) {
if (feedReadCache && Date.now() - feedReadCache.at < FEED_CACHE_TTL_MS) {
return feedReadCache.rows.slice(0, limit);
}
- if (feedReadInflight) {
- const rows = await feedReadInflight;
- return rows.slice(0, limit);
- }
- feedReadInflight = (async () => {
- try {
- const raw = await r.lrange(FEED_KEY, 0, FEED_MAX - 1);
- const rows = raw
- .map((row) => {
- if (typeof row === 'string') {
- try {
- return JSON.parse(row);
- } catch (parseErr) {
- log.warn('feed_row_parse_failed', { message: parseErr?.message });
- return null;
+ // The inflight promise must never reject: both the originating call and any
+ // coalesced waiters await it, and an unhandled rejection on a Redis outage
+ // (e.g. WRONGPASS) would otherwise surface as a 500 instead of degrading to
+ // the in-memory feed. Catch inside and fall back here.
+ if (!feedReadInflight) {
+ feedReadInflight = (async () => {
+ try {
+ const raw = await r.lrange(FEED_KEY, 0, FEED_MAX - 1);
+ const rows = raw
+ .map((row) => {
+ if (typeof row === 'string') {
+ try {
+ return JSON.parse(row);
+ } catch (parseErr) {
+ log.warn('feed_row_parse_failed', { message: parseErr?.message });
+ return null;
+ }
}
- }
- return row;
- })
- .filter(Boolean);
- feedReadCache = { at: Date.now(), rows };
- return rows;
- } finally {
- feedReadInflight = null;
- }
- })();
- try {
- const rows = await feedReadInflight;
- return rows.slice(0, limit);
- } catch (err) {
- log.warn('feed_read_failed', { message: err?.message });
+ return row;
+ })
+ .filter(Boolean);
+ feedReadCache = { at: Date.now(), rows };
+ return rows;
+ } catch (err) {
+ log.warn('feed_read_failed', { message: err?.message });
+ return memFeed.slice();
+ } finally {
+ feedReadInflight = null;
+ }
+ })();
}
+ const rows = await feedReadInflight;
+ return rows.slice(0, limit);
}
return memFeed.slice(0, limit);
}