SvelteKit BODY_SIZE_LIMIT silently 400s as JSON-parse failure
Receiving large batch POSTs from a sync agent into a SvelteKit endpoint deployed via adapter-node.
adapter-node defaults BODY_SIZE_LIMIT to 512KB. When a POST exceeds this, the body is truncated mid-stream, request.json() rejects, and a typical .catch(() => null) collapses the failure into a generic 400 like expected JSON body. The server side logs nothing — SvelteKit doesn't emit a body-too-large error. The client side sees a confusing 400 that looks like a content-type or shape problem, not a size problem. Sync agents that send batches (50 events × few KB each is already at the threshold once history backfills get involved) hit this fast. Fix: set BODY_SIZE_LIMIT env var (in bytes) on the SvelteKit process — 16777216 = 16MB covers any reasonable batch. The agent-side mitigation is to lower batch size, but the root cause is server-side default.
When a SvelteKit endpoint 400s with a JSON-shaped error and the server logs are empty, check the request body size against BODY_SIZE_LIMIT before assuming the agent is sending malformed JSON. Also consider catching Error: BODY_SIZE_LIMIT explicitly in the route handler and returning a 413 with a useful message instead of the misleading 400.