fix: improve error logging for chat stream failures#220
Merged
dsammaruga merged 2 commits intoarduino:mainfrom May 6, 2026
Merged
fix: improve error logging for chat stream failures#220dsammaruga merged 2 commits intoarduino:mainfrom
dsammaruga merged 2 commits intoarduino:mainfrom
Conversation
lucaronca
approved these changes
May 6, 2026
Contributor
lucaronca
left a comment
There was a problem hiding this comment.
Approved with an optional comment 👍🏻
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.
This PR fixes a streaming error logging issue in the LLM chat flow. Errors raised while consuming streamed chat responses were being propagated to the app layer and shown in the frontend error box, but they were not always emitted in the Python logs.
Technical Details
The root cause was that
CloudLLM.chat_stream()returned the internal generator directly, so exceptions raised during generator iteration happened outside itstry/exceptblock.Changes:
Updated
src/arduino/app_bricks/cloud_llm/cloud_llm.pyCloudLLM.chat_stream()now usesyield fromso stream iteration is covered by the logging/error handling block._handle_stream_error()as the common stream error handling hook.Updated
src/arduino/app_bricks/llm/local_llm.pyLargeLanguageModel.chat_stream()now delegates tosuper().chat_stream(...), sharing the same streaming/logging path asCloudLLM.<think>chunks and handling OpenAI-compatible API errors via_handle_api_error().Added brick-scoped regression tests:
tests/arduino/app_bricks/cloud_llm/test_cloud_llm_stream_logging.pytests/arduino/app_bricks/llm/test_local_llm_stream_logging.pyValidation
python3 -m pytest tests/arduino/app_bricks/cloud_llm/test_cloud_llm_stream_logging.py tests/arduino/app_bricks/llm/test_local_llm_stream_logging.pypython3 -m ruff check src/arduino/app_bricks/cloud_llm/cloud_llm.py src/arduino/app_bricks/llm/local_llm.py tests/arduino/app_bricks/cloud_llm/test_cloud_llm_stream_logging.py tests/arduino/app_bricks/llm/test_local_llm_stream_logging.py