Architecture · Decision record 0005
ADR 0005: Run execution, event storage and streaming before durable jobs
On this page
- Status: Accepted
- Date: 2026-11-24
Context#
M1 needs real runs that stream to the browser and survive a page reload. Durable execution with Inngest is scheduled for M3. The project runs at $0 on Vercel Hobby and Neon's free tier, and must also run locally with no accounts and no Docker.
Decision#
- Execution (M1–M2):
POST /validates the input, creates the run and itsapi/ runs run.createdevent, returns the run id immediately, and continues the run in the same server process with Next.jsafter(). A run is bounded by its budget and the function's maximum duration. M3 replaces this with Inngest steps without changing the event contract. - Storage: every event is written with
appendRunEventbefore it is published; the database is the only source of truth. Locally the app uses an embedded PGlite database persisted under.data/with the real migrations applied at start-up, sopnpm devworks with no accounts. Deployed, it uses Neon through the non-owner app login role. - Streaming:
GET /is a Server-Sent Events route that replays events afterapi/ runs/ :id/ events Last-Event-ID(or?after=), then polls for new events every 250 ms until the run is terminal or the client disconnects. Polling, not LISTEN/NOTIFY, because serverless functions cannot hold a database listener open and polling costs nothing at demo scale. - Guest workspaces: first visit creates an anonymous guest user and a demo workspace (7-day retention), identified by a signed, HTTP-only cookie (
DELEGATE_SESSION_SECRET). The guest policy (packages/defaults) applies.policy - Browser state is a client-side
foldRunover the streamed events, so a reload rebuilds exactly the same view.
Consequences#
- A process crash mid-run leaves a run in a non-terminal state; M1 marks such runs
failedon next read after a timeout. True resume comes with M3. - Polling adds up to 250 ms latency per event; acceptable against the 2-second time-to-first-event target.
- PGlite locally and Neon in production run the same migrations; differences (real concurrency, roles created outside migrations) are covered in
packages/.db/ README.md