25c4e2442c
Two related fixes after re-testing on the deploy preview: 1. SEGMENT_BUDGET_MS: 54_000 -> 40_000. Empirically, Netlify Edge Function responses get cut anywhere between ~49 s and ~60 s wall-clock — significantly more variance than the docs imply. With a 54 s budget, our segment_end write + controller.close() sometimes lands AFTER the platform has already killed the response (curl: 'HTTP/2 stream 1 was not closed cleanly before end of the underlying stream'). 40 s gives ~10 s of headroom on the low end of the observed range while still keeping segment overhead reasonable (~1 segment per 40 s of brief). 2. HEARTBEAT_MS: 10_000 -> 5_000. Tighter keep-alive so the connection stays warm even during long model-thinking gaps where the agent isn't emitting events. 3. Drop the 'await upstream.cancel()' between backfill and tail. The upstream fetch's body is already cleaned up by segmentAbort.abort() (or will be by the runtime once we drop our reference). On Deno Edge, awaiting cancel() on an already-aborted body can hang, which prevents segment_end from being written. Co-Authored-By: alex <alex@semipublic.co>