Skip to content

fix(serve): bound delegated stream buffering - #276

Closed
Afloat16 wants to merge 1 commit into
Edge0-AI:mainfrom
Afloat16:fix/delegate-stream-backpressure
Closed

Afloat16 wants to merge 1 commit into
Edge0-AI:mainfrom
Afloat16:fix/delegate-stream-backpressure

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

What & why

A delegated generation worker reads upstream data into an unbounded deque while the HTTP response writer sends to the client. When that client pauses, the worker can consume the entire upstream stream and retain it in the proxy. A real TCP regression demonstrates the base buffering an unread 64 MiB stream in under a second.

Pause the producer when queued SSE data reaches 256 KiB (plus at most one receive chunk) and resume it when the writer removes data. Cancellation wakes waiting producers before stopping the upstream HTTP client. Non-streaming replies append directly to their final body buffer, so they do not wait behind the streaming queue budget or retain a second deque copy.

Area

  • Engine, CLI or server (edge0-infer/)

How was it tested?

Base: bc2dc409d420097b4e864d511901180d7c2c6bac; Linux, GCC 14.2, CPU preset.

  • Rebuilt the unchanged native proxy and confirmed the new real TCP test fails: the upstream finishes all 64 MiB while the downstream reads only response headers.
  • The fixed proxy keeps the producer blocked during a four-second downstream pause. After resuming, a SHA-256 comparison verifies every response byte. The service receives SIGTERM while backpressured and drains the complete response before stopping.
  • A second paused 64 MiB request disconnects instead of draining. The upstream observes cancellation within five seconds, and the same proxy then forwards a 2 MiB non-streaming JSON reply byte for byte.
  • Existing proxy, live_progress, dialects, interrupted_responses, and lifecycle integration functions pass. These include normal streams, all three protocols, accounting, transport failures, SIGINT/SIGTERM, abrupt child exit and cleanup.
  • Full CPU build passes. L0/L1: 97 passed, 3 Vulkan tests skipped, 4 baseline failures: moe_test_app_generation (std::tmpfile unavailable), moe_test_platform_memory (existing Linux expectation), and existing extreme-float serialization in moe_test_ordered_json / moe_test_template_tools.
  • Python syntax compilation and git diff --check pass. The bound concerns the relay queue; this is not a claim about total process RSS, kernel socket buffers, or inference throughput.

Checklist

  • Added a failure-first actual TCP regression, including shutdown and cancellation.
  • Ran the affected native HTTP integration and lifecycle tests.
  • Full L0/L1 is green (four unchanged baseline failures listed above).
  • All supported platforms tested (Linux tested locally).

@Afloat16

Copy link
Copy Markdown
Contributor Author

Superseded by #291, the consolidated delegated-serving PR requested in #289. The original change and regression coverage are preserved, and the original commit remains in the consolidated branch's history.

@Afloat16 Afloat16 closed this Nov 17, 2026
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.

1 participant