Skip to content

Fix ActiveStorage::Blob re-upload if used in with: param#683

Merged
crmne merged 2 commits into
crmne:mainfrom
bubiche:active_storage_blob_reupload_fix
Mar 17, 2026
Merged

Fix ActiveStorage::Blob re-upload if used in with: param#683
crmne merged 2 commits into
crmne:mainfrom
bubiche:active_storage_blob_reupload_fix

Conversation

@bubiche

@bubiche bubiche commented Mar 17, 2026

Copy link
Copy Markdown

What this does

Fixes #665

When an ActiveStorage::Blob is passed to ask or create_user_message via with:, it is downloaded and re-uploaded as a new blob. This is because the blob gets wrapped in a RubyLLM::Attachment during content building, so it goes to the else branch in prepare_for_active_storage and convert_to_active_storage_format is called, which always creates a new IO hash.

=> Fix by updating convert_to_active_storage_format to detect ActiveStorage objects and return it directly so it can be reused.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

@crmne crmne merged commit 61bccb4 into crmne:main Mar 17, 2026
21 checks passed
@codecov

codecov Bot commented Mar 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.75%. Comparing base (4034c05) to head (77932ea).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/ruby_llm/active_record/chat_methods.rb 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #683      +/-   ##
==========================================
+ Coverage   81.63%   81.75%   +0.12%     
==========================================
  Files         117      117              
  Lines        5522     5526       +4     
  Branches     1441     1444       +3     
==========================================
+ Hits         4508     4518      +10     
+ Misses       1014     1008       -6     

☔ 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.

[BUG] ActiveStorage::Blob gets re-uploaded when passed into a message with Rails integration

3 participants