Skip to content

fix(server): remove unnecessary stream() wrapper from prompt_async endpoint - #16181

Closed
InstaxAI wants to merge 2 commits into
anomalyco:devfrom
InstaxAI:fix/prompt-async-remove-stream-wrapper
Closed

InstaxAI wants to merge 2 commits into
anomalyco:devfrom
InstaxAI:fix/prompt-async-remove-stream-wrapper

Conversation

@InstaxAI

@InstaxAI InstaxAI commented Mar 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #16180

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The prompt_async endpoint uses Hono's stream() to wrap a fire-and-forget SessionPrompt.prompt() call. The stream callback never calls stream.write() — it just fires off the prompt and exits. This opens a chunked transfer-encoding response that writes zero bytes before closing.

Behind Cloudflare (100s first-byte timeout, non-configurable on Free/Pro) this causes 524 timeout errors. The frontend then shows "Send failed" and reverts the input, but the prompt was already accepted server-side.

The fix replaces stream() with a direct c.body(null, 204). Since prompt_async is designed to return immediately (fire-and-forget), it doesn't need streaming — an atomic 204 response completes in milliseconds and isn't susceptible to proxy timeouts.

The synchronous prompt endpoint (which legitimately uses stream() to write response data via stream.write()) is unaffected.

How did you verify your code works?

  1. Confirmed the bug in production: Cloudflare tunnel logs show stream canceled by remote with error code 0 and Incoming request ended abruptly: context canceled on the prompt_async path
  2. Verified code: the stream() callback in prompt_async never calls stream.write(), confirming the wrapper serves no purpose
  3. Compared with the prompt endpoint which correctly uses stream.write(JSON.stringify(msg)) — that one is a legitimate streaming use case
  4. The stream import remains needed by the prompt endpoint

Screenshots / recordings

N/A — server-side fix, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

apple and others added 2 commits March 5, 2026 22:03
…dpoint

The prompt_async endpoint wraps a fire-and-forget SessionPrompt.prompt()
call in hono's stream() helper, which opens a streaming HTTP response that
never writes any data before closing. This causes Cloudflare (and other
reverse proxies with idle/first-byte timeouts) to return 524 timeout errors,
even though the prompt was successfully accepted by the server.

Replace with a direct 204 No Content response, which completes atomically
and is not susceptible to proxy timeout issues.
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this May 5, 2026
@cogni-ai-ee

Copy link
Copy Markdown

Please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prompt_async endpoint returns 524 timeout behind Cloudflare due to unnecessary stream() wrapper

2 participants