Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

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

lith: match Netlify background-function semantics for -background handlers

Netlify background functions return 202 immediately and keep running
asynchronously, letting callers (e.g. keep-prepare -> keep-prepare-background)
await the launch without blocking on the full pipeline.

lith's handleFunction was awaiting the handler to completion, so the client's
POST /api/keep-prepare hung for minutes while keep-prepare-background baked
the thumbnail, uploaded to IPFS, etc. Detect the -background suffix and fire
the handler as fire-and-forget after sending 202.

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

+21
+21
lith/server.mjs
··· 269 269 return res.status(404).send("Function not found: " + name); 270 270 } 271 271 272 + // Netlify-style background functions: filename ends in `-background`. The 273 + // Netlify runtime responds 202 immediately and keeps the handler running 274 + // asynchronously. lith must do the same or callers that `await` the 275 + // invocation (e.g. keep-prepare → keep-prepare-background) hang until the 276 + // full pipeline completes, blocking the client request. 277 + if (name.endsWith("-background")) { 278 + const event = toEvent(req); 279 + const context = { clientContext: {} }; 280 + const t0 = Date.now(); 281 + res.status(202).send(""); 282 + handler(event, context) 283 + .then((result) => { 284 + recordCall(name, Date.now() - t0, result?.statusCode || 202, req.path, req.method, null); 285 + }) 286 + .catch((err) => { 287 + recordCall(name, Date.now() - t0, 500, req.path, req.method, err?.message); 288 + console.error(`fn/${name} background error:`, err); 289 + }); 290 + return; 291 + } 292 + 272 293 // Check response cache (GET only, with matching query string) 273 294 const ttl = CACHE_TTLS[name]; 274 295 if (ttl && req.method === "GET") {