Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The tests do not cover a later chunk invocation raising, leaving exception propagation and restoration or removal of input unverified.
1 open issue
What changed in this PR
This PR prevents chunk aggregation from leaving the caller’s input argument overwritten, preserving arguments used by callers such as ConversationSummaryPlugin.
Changes:
- Restore the original
input, or remove the temporary key, in afinallyblock. - Document the restoration behavior and add regression tests for successful calls with and without an existing
input.
| File | Description |
|---|---|
python/tests/unit/text/test_function_extension.py |
Tests restoration of existing input and removal of temporary input. |
python/semantic_kernel/text/function_extension.py |
Preserves the caller’s input after aggregation, including when an invocation raises. |
Review effort: Balanced
|
|
||
| results.append(str(result)) | ||
| results.append(str(result)) | ||
| finally: |
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Problem
aggregate_chunked_resultswrites every chunk into the borrowedargumentsasinputand neverrestores it, so the caller gets its arguments back mutated:
inputis replaced by the last chunk, so the original value is lost;inputkey that was never there.ConversationSummaryPlugin.summarize_conversationpasses its ownKernelArgumentsstraight into thishelper and returns it (documented as "KernelArguments with the summarized conversation result in key
self.return_key"), so in practice the summarization plugin silently replaces the caller's$inputwith the last chunk of the transcript while the caller only asked for
arguments["summary"].Fix
Record whether
inputwas present, and restore the previous value (or drop the key) in afinallyblock, so the caller's arguments are exactly as passed in even when a chunk invocation raises.
Only the aggregated text is returned.
Tests
New test
test_aggregate_results_does_not_mutate_caller_argumentsinpython/tests/unit/text/test_function_extension.pyasserts both directions: an existinginputis restored and a bare
KernelArguments()stays empty. The existingtest_aggregate_resultsstillcovers the aggregation output itself.
Measured counts (Python 3.13, offline):
pytest tests/unit/text/test_function_extension.py-> 2 passedpytest tests/unit/text tests/unit/core_plugins tests/unit/prompt_template-> 736 passed, 3 skipped