Skip to content

Deliver server SSE tokens during inference with backpressure and cancellation #519

Description

@sauravpanda

Suggested priority: P1 — observable streaming behavior.

At a8cb07c, stream_response runs generation to completion while accumulating SSE strings in a Vec, then constructs the response body. Although the payload uses SSE formatting, the client cannot receive generated tokens while inference is running. Generation also executes synchronously in the async handler. The 30-second timeout only covers acquiring the model lock.

Scope and acceptance criteria

  • Run inference on a dedicated worker or suitable blocking executor.
  • Return a response stream fed by a bounded channel; apply backpressure instead of dropping tokens or accumulating the full response.
  • Cancel generation when the client disconnects, and release model ownership promptly.
  • Preserve event ordering, assistant role, generated content, and the final [DONE] event.
  • Report length exhaustion separately from EOS/stop completion; keep non-streaming finish reasons consistent.
  • Add a deterministic integration test proving a content event is observable before generation completes.
  • Test a slow consumer, a disconnected client, and concurrent health requests during inference.

Evidence: buffered generation and response construction, hardcoded finish reason.

Follow-up to closed #98: real generation is wired in, but incremental delivery is still missing. The edge engine also returns a complete vector of SSE chunks; document that behavior and consider a callback/iterator interface for hosts that need live streaming.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingperformancePerformance optimization

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions