pi: asynchronous exit summaries 0 ▲ ¬ just serendipity 🍀 2 hours ago · Tech · hide · 0 comments ♠ Problem statement: ctrl+d in pi took several seconds to quit. The culprit was pi-memory’s session_shutdown handler. It sent one last LLM request to summarize the session, wrote its answer to the daily log, then ran qmd update. Pi awaits all shutdown handlers, correctly, so quitting waited for everything: pi.on("session_shutdown", async (event, ctx) => { const result = await generateExitSummary(ctx); fs.writeFileSync(filePath, entry, "utf-8"); await runQmdUpdateNow(); }); Making that promise fire-and-forget would not work: Pi exits immediately after shutdown, and either the in-flight request keeps Node alive or gets killed before it can write anything. Instead, I made the shutdown path write a durable job, synchronously: const job: ExitSummaryJob = { version: 1, id: randomUUID(), createdAt: new Date().toISOString(), date: todayStr(), reason, sessionId: shortSessionId(ctx.sessionManager.getSessionId()), conversationText: truncated.text, truncated: truncated.truncated, totalChars:… No comments yet. Log in to reply on the Fediverse. Comments will appear here.