Skip to content

[BUG] Attachment to ask are not saved to disk during a transaction (rails integration) #720

@mkamensky

Description

@mkamensky

Basic checks

  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code

What's broken?

I am trying to use chat.ask, with chat a rails model, inside a transaction, where the arguments to ask include an attachment. I end up with an ActiveStorage::FileNotFoundError coming from

tempfile = download_attachment(attachment)

The reason appears to be that ActiveStorage does not save the attachment until after the transaction is over, which happens after the above mentioned loading takes place. This is similar to rails/rails#41661 and rails/rails#43663.

How to reproduce

  1. Configure RubyLLM with Rails integration
  2. Create a Chat model and run ask with an attachment within a transaction
  3. Experience ActiveStorage::FileNotFoundError

Expected behavior

Proceed with the query as outside a transaction

What actually happened

Receive an exception

Environment

  • Ruby version: 4.0.2
  • RubyLLM version: 1.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions