-
Notifications
You must be signed in to change notification settings - Fork 25
fix(apps): resolve streaming error handling for 2-minute timeout & content stream not allowed #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Athosone
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
Athosone:fix/http-stream-rate-limit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−10
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
402286b
fix(apps): rate-limit HttpStream to 1 req/s streaming limit
Athosone bd1e0a3
fix(apps): pace retries and final close() send through the limiter
Athosone fa6ae49
fix(apps): address review — plumb stream options, pace-don't-drop def…
Athosone bd8eedb
fix(apps): always coalesce informative updates, add informative/text …
Athosone 0fe5331
refactor(apps): skip re-sending unchanged text, simplify flush bookke…
Athosone 0099f06
Merge branch 'main' into fix/http-stream-rate-limit
Athosone dbb885a
Merge branch 'main' into fix/http-stream-rate-limit
Athosone c7f1ac5
Merge branch 'main' into fix/http-stream-rate-limit
Athosone 8d5e26b
Revert HttpStream rate-limit changes from PR #453
lilyydu 3c1c34c
fix stream timeout 403 error
lilyydu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,14 +27,25 @@ class ActivitySender: | |
| Separate from transport concerns (HTTP, WebSocket, etc.) | ||
| """ | ||
|
|
||
| def __init__(self, client: Client): | ||
| def __init__( | ||
| self, | ||
| client: Client, | ||
| stream_min_send_interval: float = 1.0, | ||
| stream_coalesce_informative_updates: bool = False, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's stream_coalesce_informative_updates should be true always. let's not expose this. |
||
| ): | ||
| """ | ||
| Initialize ActivitySender. | ||
|
|
||
| Args: | ||
| client: HTTP client with token provider configured | ||
| stream_min_send_interval: Minimum seconds between sends on streams created by | ||
| create_stream() (Teams limits streaming to 1 req/s). Set 0 to disable pacing. | ||
| stream_coalesce_informative_updates: When True, a burst of informative updates in one | ||
| flush collapses to the latest one instead of pacing out every update. | ||
| """ | ||
| self._client = client | ||
| self._stream_min_send_interval = stream_min_send_interval | ||
| self._stream_coalesce_informative_updates = stream_coalesce_informative_updates | ||
|
|
||
| async def send(self, activity: ActivityParams, ref: ConversationReference) -> SentActivity: | ||
| """ | ||
|
|
@@ -92,4 +103,9 @@ def create_stream(self, ref: ConversationReference) -> StreamerProtocol: | |
| """ | ||
| # Create API client for this conversation's service URL | ||
| api = ApiClient(ref.service_url, self._client) | ||
| return HttpStream(api, ref) | ||
| return HttpStream( | ||
| api, | ||
| ref, | ||
| min_send_interval=self._stream_min_send_interval, | ||
| coalesce_informative_updates=self._stream_coalesce_informative_updates, | ||
| ) | ||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| import asyncio | ||
| from time import monotonic | ||
| from typing import Awaitable, Callable | ||
|
|
||
|
|
||
| def make_limiter(interval: float) -> Callable[[], Awaitable[None]]: | ||
| """Fixed-interval gate (a token bucket of size 1): consecutive | ||
| acquisitions are spaced at least `interval` seconds apart. | ||
|
|
||
| The slot is reserved (read then write of `next_slot`) with no await in | ||
| between, so reservations are race-free under single-threaded asyncio. The | ||
| first call never waits, and `interval=0` disables pacing. | ||
| """ | ||
| if interval < 0: | ||
| raise ValueError("interval must be >= 0") | ||
|
|
||
| next_slot = monotonic() | ||
|
|
||
| async def acquire() -> None: | ||
| nonlocal next_slot | ||
| now = monotonic() | ||
| slot = max(now, next_slot) | ||
| next_slot = slot + interval | ||
| wait = slot - now | ||
| if wait > 0: | ||
| await asyncio.sleep(wait) | ||
|
|
||
| return acquire |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also don't think we need this.