Skip to content

Emit SSE keep-alive frames from the invocations server#46898

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/investigate-sse-keep-alive-issue
Open

Emit SSE keep-alive frames from the invocations server#46898
Copilot wants to merge 3 commits into
mainfrom
copilot/investigate-sse-keep-alive-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

  • Investigate cspell failure on test_sse_keepalive.py
  • Rename keep_aliveskeepalive_lines to remove the unknown word alives

@ankitbko ankitbko marked this pull request as ready for review May 14, 2026 20:31
Copilot AI review requested due to automatic review settings May 14, 2026 20:31
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label May 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_stream as the outermost body-iterator wrap in _wrap_streaming_response, gated on text/event-stream media type and a positive sse_keepalive_interval.
  • Refactor the otel_span is None early-return into an if 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()
@ankitbko ankitbko enabled auto-merge (squash) May 15, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants