[BUG] ReleaseRequest raises when Faraday response has no request options
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with lib/ruby_llm/transport/release_request.rb, where the issue identifies the nil request-options access, then inspect the Connection#instrument_request rescue path. Reproduce with the provided plain Ruby script and add regression coverage for an env without request options and for the original error surviving cleanup. Done when cleanup returns the response and preserves the original error in the rescue path.
Written by the indexing model from the issue text.
Description
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?
RubyLLM::Transport::ReleaseRequest.release assumes that every Faraday::Env has request options. When env.request is nil, cleanup raises NoMethodError instead of returning the response.
This also masks the original error when Transport::Connection#instrument_request rescues a RubyLLM::Error and calls ReleaseRequest.release(error.response). I encountered it while a custom Responses protocol was raising a RubyLLM::ServerError subclass for a terminal response.failed event, with a Faraday response attached for status/body evidence.
How to reproduce
With the versions below installed, save this as repro.rb and run it with plain ruby repro.rb outside Bundler:
gem 'faraday', '2.15.1'
gem 'ruby_llm', '2.2.2'
require 'ruby_llm'
require 'faraday'
response = Faraday::Response.new(
status: 500,
body: 'provider error',
response_headers: {}
)
RubyLLM::Transport::ReleaseRequest.release(response)
No provider credentials, network requests or WebMock are required. The response has a Faraday::Env, but response.env.request is nil.
Expected behavior
Cleanup should tolerate missing request options, still clear the request body/headers, and return the response. When invoked during error handling, it should leave the original provider/protocol error intact.
What actually happened
NoMethodError: undefined method 'on_data=' for nil
The exception comes from env.request.on_data = nil in transport/release_request.rb. The following env.request.context = nil has the same assumption. In the streaming error path, callers therefore receive this cleanup exception instead of the original RubyLLM::Error.
Suggested fix
I would keep the body/header cleanup unconditional and guard only the request-options cleanup:
env.request_body = nil
env.request_headers = Faraday::Utils::Headers.new
if (request = env.request)
request.on_data = nil
request.context = nil
end
response
This retains the credential/body cleanup when no request options exist. Regression tests could cover an env without request options and one with streaming callbacks/context, then exercise the Connection#instrument_request rescue path to verify that it re-raises the original error after cleanup.
Environment
- Ruby: 4.0.7
- RubyLLM: 2.2.2
- Faraday: 2.15.1
- Provider: none required for the reproduction; originally observed with the OpenAI Responses protocol
- OS: macOS, ARM64
- Dominant language
- Ruby
- Stars
- 4.5k
- Forks
- 537
- Avg merge
- 7h 30m
- Merged PRs (30d)
- 378
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from crmne/ruby_llm
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
crmne/ruby_llm#1682 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 22/100
crmne/ruby_llm#1674 · 1 comment ·
Maintainers usually reply within 1 day
-
[BUG] FileStore::Directory follows links to folders inside its own folderPossibly taken @yorzi claimed this 1 day ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 30/100
crmne/ruby_llm#1673 · 1 comment ·
Maintainers usually reply within 1 day
-
[BUG] FileStore::Directory#list returns nothing when a file vanishes mid-listingPossibly taken @yorzi claimed this 1 day ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 32/100
Maintainers usually reply within 1 day
-
Body logging is tied to the logger's debug level, and streaming debug lines ignore the context loggerPossibly taken @josh-sanders claimed this 1 day ago. Openbug
Difficulty 3/5 Half a day Newbie friendliness 55/100
crmne/ruby_llm#1669 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Bug Ruby
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-ruby#3211 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
internetee/registry#2984 ·
Maintainers usually reply within 6 days
-
interest-zsv
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
hitobito/hitobito_zsv#6 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ecosyste-ms/issues#862 ·
Maintainers usually reply within 1 day
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPossibly taken @mimosa claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day