Skip to content

Add SSE keep-alive and prepare invocations 1.0.0 - #48481

Draft
Shiva S (Shivakishore14) wants to merge 3 commits into
Azure:mainfrom
Shivakishore14:sshiva/invocations-sse-keepalive
Draft

Add SSE keep-alive and prepare invocations 1.0.0#48481
Shiva S (Shivakishore14) wants to merge 3 commits into
Azure:mainfrom
Shivakishore14:sshiva/invocations-sse-keepalive

Conversation

@Shivakishore14

Copy link
Copy Markdown
Member

Description

Adds configurable SSE keep-alive comments to idle POST /invocations event streams. When SSE_KEEPALIVE_INTERVAL is configured, the host emits : keep-alive comments without reordering source events, while preserving streaming context, error propagation, and cancellation cleanup.

Keep-alive injection is limited to text/event-stream; other StreamingResponse media 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:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Testing:

  • uv run --group dev pytest -q tests/test_sse_keep_alive.py tests/test_invoke.py — 17 passed
  • Azure hosted-agent idle stream at 270 seconds — 7/7 yacflow assertions passed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
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.

@Shivakishore14

Copy link
Copy Markdown
Member Author

Long-duration hosted validation completed successfully:

  • Idle interval: 1,800 seconds (30 minutes)
  • Result: 7/7 yacflow assertions passed
  • Total duration: 31m 52.5s
  • Image: cr5bu5pbkxrzvny.azurecr.io/sample-agent-python:invocations-sse-keepalive-30m-ce15c6d521
  • Digest: sha256:19afb8f4f40b0b2f4004b1a89bd9a3c075f8ab53b98a8403ae3698b7deba5f57

The stream delivered started, finished, and [DONE] after the full silent interval.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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>
@Shivakishore14 Shiva S (Shivakishore14) changed the title Add SSE keep-alive to invocations streams Add SSE keep-alive and prepare invocations 1.0.0 Aug 7, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants