fix: initialize task variable in RemoteAgent to prevent UnboundLocalError#2805
Merged
Conversation
Fixes ag2ai#2223 Initialize `task` to None before the event processing loop in `RemoteAgent.a_generate_remote_reply()`, matching the pattern used in `_ask_streaming()` and `_ask_polling()` methods. This prevents potential UnboundLocalError if the task variable is referenced in error handlers or debugging code when all events in the stream are Message types (no Task events). Changes: - Initialize `task: Task | None = None` before the async for loop - Add test for message-only flow scenario The fix is defensive programming that aligns with existing code patterns and prevents subtle bugs in error scenarios.
MessageOnlyClient did not conform to ClientFactory protocol (not callable, no async context manager). Use the existing MockClient factory which already produces message-only responses, and follow the test patterns established in test_client.py.
Collaborator
|
@kimjune01 Hi, thanks for pr! Can you sign CLA? |
Lancetnik
approved these changes
May 12, 2026
vvlrff
approved these changes
May 13, 2026
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 54 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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.
Summary
task: Task | None = Nonebefore the event loop inRemoteAgent.a_generate_remote_replyUnboundLocalErrorwhen the message-only flow skips theelseblock that assignstask_ask_streaming/_ask_pollingpatterns elsewhere in the codebaseFixes #2223
Test plan
test_task_initialization.pywithMockClientto verify message-only flow completes without errortest_client.pytests passMessageOnlyClientthat did not conform toClientFactoryprotocol) with properMockClient