Skip to content

Fix Anthropic streaming crash on non-hash SSE payloads#657

Merged
crmne merged 1 commit into
mainfrom
fix/656-anthropic-streaming-non-hash
Mar 5, 2026
Merged

Fix Anthropic streaming crash on non-hash SSE payloads#657
crmne merged 1 commit into
mainfrom
fix/656-anthropic-streaming-non-hash

Conversation

@crmne

@crmne crmne commented Mar 5, 2026

Copy link
Copy Markdown
Owner

What this does

Prevents streaming parsers from passing non-Hash SSE payloads into provider build_chunk methods.

handle_data can parse valid JSON scalars (like true) from data: frames. Those values are truthy and previously passed if data, which crashes provider chunk builders that assume a Hash and call dig.

This change narrows the guard in handle_stream to data.is_a?(Hash).

Why this is minimal

  • One-line runtime behavior change in shared streaming handler
  • No provider-specific branching
  • Keeps existing behavior for all normal Hash event payloads

Tests

  • Added spec/ruby_llm/streaming_spec.rb
  • Verifies non-Hash SSE payloads are ignored without raising
  • Verifies Hash SSE payloads still flow to build_chunk

Fixes #656

@crmne crmne merged commit 67c4148 into main Mar 5, 2026
21 checks passed
@crmne crmne deleted the fix/656-anthropic-streaming-non-hash branch March 5, 2026 09:44
@codecov

codecov Bot commented Mar 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.38%. Comparing base (afe7d04) to head (c98a4a7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #657   +/-   ##
=======================================
  Coverage   81.38%   81.38%           
=======================================
  Files         116      116           
  Lines        5430     5430           
  Branches     1428     1428           
=======================================
  Hits         4419     4419           
  Misses       1011     1011           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

NoMethodError: undefined method 'dig' for true in Anthropic streaming

1 participant