Add SSE keep-alive and prepare invocations 1.0.0 - #48481
Add SSE keep-alive and prepare invocations 1.0.0#48481Shiva S (Shivakishore14) wants to merge 3 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Long-duration hosted validation completed successfully:
The stream delivered |
There was a problem hiding this comment.
Pull request overview
Adds configurable keep-alive comments to idle SSE invocation streams while preserving event ordering and cleanup.
Changes:
- Adds SSE keep-alive stream wrapping.
- Limits injection to
text/event-stream. - Adds integration and lifecycle tests plus release notes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
_sse.py |
Implements keep-alive injection. |
_invocation.py |
Applies keep-alives to SSE responses. |
test_sse_keep_alive.py |
Tests timing, errors, cleanup, and media filtering. |
CHANGELOG.md |
Documents the fix. |
| yield item | ||
| return | ||
|
|
||
| queue: asyncio.Queue[Any] = asyncio.Queue() |
There was a problem hiding this comment.
Fixed in 8d81498. The producer is now request-driven: one persistent task owns and advances the source (preserving contextvars), but it only calls anext(source) when the consumer requests the next chunk. This restores backpressure without reintroducing cross-task context issues. Added test_with_keep_alive_preserves_source_backpressure to verify a paused consumer does not advance the source.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
Adds configurable SSE keep-alive comments to idle
POST /invocationsevent streams. WhenSSE_KEEPALIVE_INTERVALis configured, the host emits: keep-alivecomments without reordering source events, while preserving streaming context, error propagation, and cancellation cleanup.Keep-alive injection is limited to
text/event-stream; otherStreamingResponsemedia types such as NDJSON remain unchanged.The issue was reproduced in Azure hosted agents: silent streams consistently reset near 269-270 seconds. A fixed image successfully completed the same 270-second idle stream and delivered the final event and
[DONE]sentinel.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
Testing:
uv run --group dev pytest -q tests/test_sse_keep_alive.py tests/test_invoke.py— 17 passed