New — Sohay now answers WooCommerce product, policy & cart questions. See how →

Answers cut off behind a CDN or proxy

Replies that stop mid-sentence, or arrive all at once after a long pause, usually mean something is buffering the stream.

Answers arrive truncated, stop mid-sentence, or sit blank for twenty seconds and then appear complete. All three are the same problem: something between your server and the visitor is buffering a response that is meant to stream.

Why streaming is fragile

Sohay streams replies word by word, using Server-Sent Events, so the visitor sees an answer forming rather than a spinner.

That requires every hop to pass bytes through as they arrive. Most infrastructure is built to do the opposite — collect a whole response, then send it — which is right for a web page and wrong for a stream.

What Sohay already does

The plugin sets the headers that ask intermediaries not to buffer:

  • Cache-Control: no-cache
  • X-Accel-Buffering: no — the header nginx honours
  • and it clears PHP’s own output buffers

On a plain host that is enough. Some CDNs ignore it.

Fixing it at the CDN

Two settings, both on the chat REST route:

  1. Bypass the cache for it. A streaming endpoint should never be cached, and a CDN that is caching it will also be buffering it.
  2. Disable transformations on the response — minification, HTML post-processing, script injection. Anything that rewrites a body has to hold the whole body first.

On Cloudflare that is a cache rule plus turning off the relevant speed optimisations for that path. Other CDNs have equivalents under different names.

If it is not the CDN

Other things that buffer, in rough order of likelihood:

  • Server-level page caching on the host — some managed WordPress hosts buffer at the edge before any CDN is involved.
  • A security or firewall plugin inspecting responses.
  • An output_buffering value set in PHP at the server level.
  • mod_deflate or gzip compression applied to the streaming response.

The quickest way to tell which layer is responsible: try the chat with the CDN bypassed, on the origin directly. If it streams there, the problem is in front of your server. If it does not, it is on it.

Checking the errors

Sohay → Diagnostics shows the last 100 log entries, and a stream that failed rather than one that was merely slow will usually have left something there.

A related symptom

If answers are fine but some visitors are turned away entirely, that is more likely a rate limit than a buffering problem — and behind a proxy, one that is misfiring because every visitor looks like the same IP. See Daily token caps and rate limits, which covers the proxy-aware setting and its security caveat.

Mithun B.
Mithun B.

More articles by Mithun B..

View all posts

Give your website an assistant that answers from your content

Grounded answers, a team inbox, and store-aware tools — free on WordPress.org.

Add Sohay — Free

Free plugin · You bring your OpenAI key · Works with any theme