Skip to content

fix: improve error logging for chat stream failures#220

Merged
dsammaruga merged 2 commits intoarduino:mainfrom
beanrepo:fix-stream-error-logs-llms
May 6, 2026
Merged

fix: improve error logging for chat stream failures#220
dsammaruga merged 2 commits intoarduino:mainfrom
beanrepo:fix-stream-error-logs-llms

Conversation

@beanrepo
Copy link
Copy Markdown
Contributor

@beanrepo beanrepo commented May 5, 2026

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 its try/except block.

Changes:

  • Updated src/arduino/app_bricks/cloud_llm/cloud_llm.py

    • CloudLLM.chat_stream() now uses yield from so stream iteration is covered by the logging/error handling block.
    • Added _handle_stream_error() as the common stream error handling hook.
  • Updated src/arduino/app_bricks/llm/local_llm.py

    • LargeLanguageModel.chat_stream() now delegates to super().chat_stream(...), sharing the same streaming/logging path as CloudLLM.
    • Kept local LLM-specific behavior isolated: filtering <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.py
    • tests/arduino/app_bricks/llm/test_local_llm_stream_logging.py

Validation

  • 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.py
  • python3 -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

Copy link
Copy Markdown
Contributor

@lucaronca lucaronca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with an optional comment 👍🏻

Comment thread src/arduino/app_bricks/cloud_llm/cloud_llm.py
@dsammaruga dsammaruga merged commit c328f20 into arduino:main May 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants