Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

Send session:started immediately, don't block on /user fetch

The /user Netlify function takes 8+ seconds on cold starts, blocking
session:started until after the 120-frame safety net fires. Now
session:started is sent right after getUser() succeeds, and the /user
lookup runs in the background for handle enrichment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+33 -32
+33 -32
system/public/aesthetic.computer/boot.mjs
··· 1533 1533 } 1534 1534 1535 1535 if (isAuthenticated && !pickedUpSession) { 1536 - // TODO: How long does this await actually take? 23.07.11.18.55 1537 1536 window.acAuthTiming.getUserStart = performance.now(); 1538 1537 let userProfile = await auth0Client.getUser(); 1539 1538 window.acAuthTiming.getUserEnd = performance.now(); 1540 1539 bootLog(`auth0 getUser (${Math.round(window.acAuthTiming.getUserEnd - window.acAuthTiming.getUserStart)}ms)`); 1541 - window.acAuthTiming.userExistsFetchStart = performance.now(); 1542 - // Timeout the /user fetch to prevent indefinite hangs on cold starts 1543 - const userFetchController = new AbortController(); 1544 - const userFetchTimeout = setTimeout(() => userFetchController.abort(), 8000); 1545 - let u = {}; 1546 - try { 1547 - const userExists = await fetch( 1548 - `/user?from=${encodeURIComponent(userProfile.email)}&tenant=aesthetic&withHandle=true`, 1549 - { signal: userFetchController.signal }, 1550 - ); 1551 - u = await userExists.json(); 1552 - } catch (err) { 1553 - console.warn("🔐 /user fetch failed or timed out:", err.name); 1554 - } finally { 1555 - clearTimeout(userFetchTimeout); 1556 - } 1557 - window.acAuthTiming.userExistsFetchEnd = performance.now(); 1558 - bootLog(`userExists fetch (${Math.round(window.acAuthTiming.userExistsFetchEnd - window.acAuthTiming.userExistsFetchStart)}ms)`); 1559 - if (!u.sub || !userProfile.email_verified) { 1560 - try { 1561 - await window.auth0Client.getTokenSilently({ cacheMode: "off" }); 1562 - userProfile = await auth0Client.getUser(); 1563 - } catch (err) { 1564 - console.warn("🧔 Could not retrieve user from network."); 1565 - } 1566 - } 1567 - // Merge handle from user lookup into the profile 1568 - if (u.handle) { 1569 - userProfile.handle = u.handle; 1570 - } 1571 - window.acUSER = userProfile; // Will get passed to the first message by the piece runner. 1540 + 1541 + // Send session:started IMMEDIATELY — don't block on /user fetch. 1542 + // The disk's own handle() function will fetch the handle separately. 1543 + window.acUSER = userProfile; 1572 1544 window.acAuthTiming.sessionStartedSent = performance.now(); 1573 1545 _authSessionSent = true; 1574 1546 window.acDISK_SEND({ 1575 1547 type: "session:started", 1576 1548 content: { user: window.acUSER }, 1577 1549 }); 1550 + 1551 + // Background: fetch handle from /user and refresh token if needed. 1552 + // This runs after the disk already has auth — it just enriches data. 1553 + (async () => { 1554 + try { 1555 + const controller = new AbortController(); 1556 + const timeout = setTimeout(() => controller.abort(), 8000); 1557 + const res = await fetch( 1558 + `/user?from=${encodeURIComponent(userProfile.email)}&tenant=aesthetic&withHandle=true`, 1559 + { signal: controller.signal }, 1560 + ); 1561 + clearTimeout(timeout); 1562 + const u = await res.json(); 1563 + bootLog(`userExists fetch (background, ${Math.round(performance.now() - window.acAuthTiming.sessionStartedSent)}ms)`); 1564 + if (u.handle && !window.acUSER.handle) { 1565 + window.acUSER.handle = u.handle; 1566 + } 1567 + // If user not in DB or email not verified, refresh token for new signups 1568 + if (!u.sub || !userProfile.email_verified) { 1569 + try { 1570 + await window.auth0Client.getTokenSilently({ cacheMode: "off" }); 1571 + } catch (err) { 1572 + console.warn("🧔 Could not retrieve user from network."); 1573 + } 1574 + } 1575 + } catch (err) { 1576 + console.warn("🔐 /user background fetch failed:", err.name); 1577 + } 1578 + })(); 1578 1579 } else if (!pickedUpSession) { 1579 1580 // console.log("🗝️ Not authenticated."); 1580 1581 window.acAuthTiming.sessionStartedSent = performance.now();