fix: return stream ID when closing streamed activity - #593
fix: return stream ID when closing streamed activity#593Alex Bitar (AlxBit) wants to merge 2 commits into
Conversation
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
🟡 Changes recommended
The new assert self._id is not None is unsafe for library runtime behavior (can be stripped with -O and lead to invalid id updates), and should be replaced with an explicit guard.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes HttpStream.close() to return the original streamed activity ID when the final streaming request gets an empty/placeholder response from Teams, aligning the SDK behavior with Teams’ streaming contract.
Changes:
- Overwrites the final
SentActivity.idwith the stream’s retained_idbefore emitting the close event and caching the result. - Adds a regression test to ensure
close()(andon_closehandlers) receive the original stream ID when the final response has the placeholder ID. - Strengthens an existing close/flush synchronization test to assert the returned
SentActivity.idis the retained activity id.
File summaries
| File | Description |
|---|---|
| packages/apps/src/microsoft_teams/apps/http_stream.py | Ensures close() returns a stable stream activity ID even when the final API response is represented with a placeholder ID. |
| packages/apps/tests/test_http_stream.py | Adds/updates tests to validate close() retains the initial stream ID and propagates it to close handlers. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
b670036 to
01307ec
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new close() logic currently overwrites the returned activity ID unconditionally when _id is set, which can clobber a real final-response ID and should be gated to placeholder-only responses.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
| # Teams only returns the stream id on the first streaming request. Subsequent | ||
| # responses, including the final streamed message, are empty and the API client | ||
| # represents those with a placeholder id. The stream id captured from the first | ||
| # chunk is the stable id for the finalized activity. | ||
| if self._id is not None: | ||
| res = res.model_copy(update={"id": self._id}) |
Fixes #592
Summary
ctx.stream.close()now returns the original stream activity ID instead ofDO_NOT_USE_PLACEHOLDER_IDwhen Teams returns an empty response for the finalstreaming request.
The stream already retains the ID returned by the initial streaming request.
This change uses that retained ID for the final
SentActivity, including thevalue emitted to
on_closehandlers and cached for repeatedclose()calls.Tests
Added regression coverage for a final streaming response with no ID.
Verified that
close()and the close event handler both receive the originalstream ID.
Run: