Production logs (2 months) show ~28 event_log inserts dying with
TypeError: fetch failed. Root cause: the MCP server emits telemetry
fire-and-forget and returns the JSON-RPC response immediately, so the
insert races Vercel function suspension; supabase-js surfaces the dead
fetch as a network error which was logged at error level.
Two-part fix:
- persistEvent (event-log-handler.ts) retries the insert once after
250ms when the error message contains "fetch failed" (network class
only; constraint violations and other Postgres errors are never
retried). On final failure, telemetry event types (mcp.*, agent.*)
log at warn; business events (journal_entry.*, invoice.*, etc.,
which feed webhook delivery) stay at error.
- The mcp-server telemetry emit sites (tool_called, tools_list_called,
resource_read, next_hint_followed, skill_loaded, workflow_started,
agent.feedback) now schedule the emit via after() from next/server,
which keeps the function alive past the response until the emit
settles. Falls back to plain fire-and-forget when no request scope
exists (direct handler invocation in tests).
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>