Python: Fix _add_text_reasoning_content to preserve id during coalescing#4862
Python: Fix _add_text_reasoning_content to preserve id during coalescing#4862giles17 wants to merge 4 commits intomicrosoft:mainfrom
_add_text_reasoning_content to preserve id during coalescing#4862Conversation
…oft#4852) Preserve the id field (rs_* identifier) when coalescing text_reasoning Content objects by passing id=self.id or other.id to the Content constructor. This fixes the encrypted reasoning round-trip where the missing id prevented _prepare_content_for_openai from including it in the serialized reasoning item. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
giles17
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 96%
✓ Correctness
This diff removes one blank line between two test functions (going from two blank lines to one), which is a trivial whitespace change with no correctness impact. The test logic itself is unchanged and correct.
✓ Security Reliability
This diff removes a single blank line between two test functions (line 1528). There are no code logic changes, no security implications, and no reliability concerns. The underlying fix (preserving
idduring text_reasoning coalescing at line 1393 of_types.py) was already landed in a prior commit and is not part of this diff. The new tests adequately cover the id-preservation behavior.
✓ Test Coverage
The diff only removes a single blank line (cosmetic whitespace change). The actual substantive tests —
test_text_reasoning_content_add_preserves_id,test_text_reasoning_content_add_id_fallback_to_other, andtest_text_reasoning_content_add_preserves_id_with_encrypted_content— already exist in the file and properly cover the bug fix (id=self.id or other.idin_add_text_reasoning_content). The tests cover: (1) id preserved when both chunks carry it, (2) fallback to other's id when self has none, and (3) round-trip with encrypted_content. Assertions are meaningful (checking specific field values, not just no-exception). No test coverage gaps found.
✓ Design Approach
The diff is a trivial whitespace change — removal of a single blank line between two test functions (
test_text_reasoning_content_iadd_coverageandtest_text_reasoning_content_add_preserves_id). The surrounding test code itself is not changed by this diff. The new tests (test_text_reasoning_content_add_preserves_id,test_text_reasoning_content_add_id_fallback_to_other,test_text_reasoning_content_add_preserves_id_with_encrypted_content) look correct and well-targeted for the fix described in the chat context. No design-level concerns arise from removing a blank line.
Suggestions
- Consider adding a test where neither
selfnorotherhas anidto verify the result'sidisNone— though this is a minor edge case and not blocking.
Automated review by giles17's agents
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Fixes Content coalescing for text_reasoning chunks so the id (e.g., rs_*) is preserved, enabling encrypted reasoning round-trips to work correctly after streaming coalesces multiple chunks.
Changes:
- Preserve
Content.idwhen merging (__add__)text_reasoningcontent. - Add unit tests covering
idpreservation,idfallback, and interaction withencrypted_contentadditional properties.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_types.py | Updates text_reasoning merge logic to carry forward id when coalescing chunks. |
| python/packages/core/tests/core/test_types.py | Adds tests validating id preservation/fallback and encrypted reasoning round-trip expectations. |
…ft#4852) Detect when both operands have different non-empty ids during text_reasoning Content coalescing and raise AdditionItemMismatch instead of silently keeping one. This prevents mis-associating encrypted_content during round-trips. Also adds tests for conflicting ids and the neither-has-id edge case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…dd_text_reasoning_content drops id during coalescing, breaking encrypted reasoning round-trip
giles17
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 96% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by giles17's agents
Motivation and Context
When text_reasoning Content chunks are coalesced (e.g., during streaming), the
idfield was silently dropped. This broke encrypted reasoning round-trips, since theid(likers_abc123) is required to associate the coalesced content back with its encrypted payload.Fixes #4852
Description
The root cause was that
_add_text_reasoning_contentinContentconstructed the merged result without passing through theidfield. The fix addsid=self.id or other.idto the coalescedContentconstructor call, preserving the identifier from whichever operand carries it. Tests cover the standard case, the fallback when only one operand has anid, and the combination ofidwithencrypted_contentadditional properties.Contribution Checklist