Public
Likesqlite-fetch-failed-repro
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
When making SQLite calls via https://esm.town/v/std/sqlite after a long-running operation (like an AI call), the request fails with:
Error: {"statusCode":500,"error":"Internal Server Error","message":"fetch failed"}
The SQLite "fetch failed" error occurs when:
- An HTTP request starts
- A long-running operation happens (AI call taking 30-120+ seconds)
- THEN a SQLite call is attempted
- The SQLite call fails, possibly due to connection/context becoming stale
- Platform: Val Town
- SQLite Library:
https://esm.town/v/std/sqlite - Original val:
dcm31/github-leads-wizard
- Open this val's HTTP endpoint: Click here to open
- Select a delay time (30 seconds simulates typical AI call time)
- Click "Run Test"
- Wait for results
- If you see ❌ FAILED with "fetch failed" in the error column, the bug is reproduced!
The SQLite INSERT should succeed regardless of how long the request has been running.
After a delay (simulating AI processing), the SQLite call fails with:
{"statusCode":500,"error":"Internal Server Error","message":"fetch failed"}
at createResError (https://esm.town/v/std/sqlite?v=6:81:10)
at Object.execute (https://esm.town/v/std/sqlite?v=6:47:11)
at eventLoopTick (ext:core/01_core.js:179:7)
at async createSession (https://esm.town/v/dcm31/github-leads-wizard@103-main/db.ts:40:3)
at async Array.<anonymous> (https://esm.town/v/dcm31/github-leads-wizard@103-main/main.ts:140:23)
In the github-leads-wizard val:
- User submits a company to analyze via
/api/start generatePrompt()calls AI (takes 30-120+ seconds)createSession()is called which does an SQLite INSERT- The INSERT fails with the fetch error
- This blocks the email results flow
For programmatic testing:
curl -X POST https://dcm31--32c77ddefb9811f0be9942dde27851f2.web.val.run/api/test \ -H "Content-Type: application/json" \ -d '{"delay": 30000}'
- This appears to happen consistently after long delays
- May be related to Val Town's request timeout or SQLite connection management
- The original code worked when AI calls were faster