• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
dcm31

dcm31

sqlite-fetch-failed-repro

Minimal repro for SQLite "fetch failed" 500 error
Public
Like
sqlite-fetch-failed-repro
Home
Code
3
README.md
H
main.ts
repro-guide.md
Environment variables
Branches
1
Pull requests
Remixes
History
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.
Sign up now
Code
/
Code
/
Search
README.md

SQLite "fetch failed" 500 Error - Minimal Reproduction

The Bug

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"}

Hypothesis

The SQLite "fetch failed" error occurs when:

  1. An HTTP request starts
  2. A long-running operation happens (AI call taking 30-120+ seconds)
  3. THEN a SQLite call is attempted
  4. The SQLite call fails, possibly due to connection/context becoming stale

Environment

  • Platform: Val Town
  • SQLite Library: https://esm.town/v/std/sqlite
  • Original val: dcm31/github-leads-wizard

Steps to Reproduce

  1. Open this val's HTTP endpoint: Click here to open
  2. Select a delay time (30 seconds simulates typical AI call time)
  3. Click "Run Test"
  4. Wait for results
  5. If you see ❌ FAILED with "fetch failed" in the error column, the bug is reproduced!

Expected Behavior

The SQLite INSERT should succeed regardless of how long the request has been running.

Actual Behavior

After a delay (simulating AI processing), the SQLite call fails with:

{"statusCode":500,"error":"Internal Server Error","message":"fetch failed"}

Original Stack Trace

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)

Original Context

In the github-leads-wizard val:

  1. User submits a company to analyze via /api/start
  2. generatePrompt() calls AI (takes 30-120+ seconds)
  3. createSession() is called which does an SQLite INSERT
  4. The INSERT fails with the fetch error
  5. This blocks the email results flow

API Endpoint

For programmatic testing:

curl -X POST https://dcm31--32c77ddefb9811f0be9942dde27851f2.web.val.run/api/test \ -H "Content-Type: application/json" \ -d '{"delay": 30000}'

Notes

  • 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
Code
README.md
H
main.ts
repro-guide.md
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.