Emit SSE keep-alive frames from the invocations server#46898
Open
Copilot wants to merge 3 commits into
Open
Conversation
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/bbcab784-0e85-4a7e-a4ad-64e15c50f26e Co-authored-by: ankitbko <3169316+ankitbko@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
ankitbko
May 14, 2026 20:05
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Wires SSE keep-alive frame injection into the invocations server's streaming response path, bringing parity with the responses server and preventing idle SSE connections from being dropped by intermediaries.
Changes:
- Apply
AgentServerHost.sse_keepalive_streamas the outermost body-iterator wrap in_wrap_streaming_response, gated ontext/event-streammedia type and a positivesse_keepalive_interval. - Refactor the
otel_span is Noneearly-return into anif otel_span is not None:block so keep-alive runs regardless of tracing state. - Add tests covering env-var disabled, env-var enabled (frames interleaved), and NDJSON (no frames).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sdk/agentserver/azure-ai-agentserver-invocations/azure/ai/agentserver/invocations/_invocation.py | Adds keep-alive wrap layer and restructures tracing wrap to be optional. |
| sdk/agentserver/azure-ai-agentserver-invocations/tests/test_sse_keepalive.py | New tests for keep-alive behavior across SSE/NDJSON and env-var states. |
| sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md | Documents the new behavior under 1.0.0b4 (Unreleased). |
Comment on lines
+87
to
+93
| async def test_sse_keepalive_interleaves_frames_when_env_var_set(monkeypatch): | ||
| """When SSE_KEEPALIVE_INTERVAL is set, ``: keep-alive`` frames appear | ||
| during gaps between handler events.""" | ||
| monkeypatch.setenv("SSE_KEEPALIVE_INTERVAL", "1") | ||
| # Construct the host AFTER setting the env var so AgentConfig.from_env() | ||
| # picks up the value. | ||
| app = _make_slow_sse_agent(delay_seconds=2.5, event_count=2) |
Comment on lines
+57
to
+58
| def _parse_lines(text: str) -> list[str]: | ||
| return text.splitlines() |
RaviPidaparthi
approved these changes
May 15, 2026
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/97517d60-af55-4954-859e-150a27a2c48d Co-authored-by: ankitbko <3169316+ankitbko@users.noreply.github.com>
vangarp
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
keep_alives→keepalive_linesto remove the unknown wordalives