Error with new Rails gem "agent_ruby"

I am migrating to the new ruby gem “agent_ruby” for my rails app.

Failure Logs

I have the following error when loading the dashboard:

NameError (uninitialized constant ForestAdminRails::ForestController::OpenIDConnect):

Causes:

ForestAdminAgent::Error (Cannot retrieve the data from the Forest server. An error occured in Forest API)

NoMethodError (undefined method ‘’ for nil)

forest_admin_rails (1.0.0.pre.beta.102) app/controllers/forest_admin_rails/forest_controller.rb:42:in ‘ForestAdminRails::ForestController#exception_handler’

Context

  • Project name: lalanguefrancaise
  • Team name: lalanguefrancaise
  • Environment name: development
  • Database type: postgresql
  • Recent changes made on your end if any: NA

Forest initializer:

ForestAdminRails.configure do |config|
  config.auth_secret = 'xxx'
  config.env_secret = 'FOREST_ENV_SECRET'
end

Forest create_agent.rb:

module ForestAdminRails
  class CreateAgent
    def self.setup!
      database_configuration = Rails.configuration.database_configuration
      datasource = ForestAdminDatasourceActiveRecord::Datasource.new(database_configuration[Rails.env])

      @create_agent = ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
      customize
      @create_agent.build
    end
…
1 Like

Hello @nico_lrx

Appreciate you testing the Ruby agent beta! :raising_hands:
It looks like the error you’re encountering is due to a missing openid_connect gem, which is required internally by the agent for authentication purposes.

To check whether this gem is properly installed in your project, you can run the following command

bundle show openid_connect

If the gem is not found, it’s likely because only forest_admin_rails was added to your Gemfile. However, this gem doesn’t include all required dependencies by itself.

To install the full Ruby agent properly, please make sure to add all the following gems:

gem "forest_admin_rails", "~> 1.0.0.pre.beta"
gem "forest_admin_agent", "~> 1.0.0.pre.beta"
gem "forest_admin_datasource_toolkit", "~> 1.0.0.pre.beta"
gem "forest_admin_datasource_active_record", "~> 1.0.0.pre.beta"
gem "forest_admin_datasource_customizer", "~> 1.0.0.pre.beta"

You can also follow our full installation guide here:

Hope that helps, feel free to reach out if you hit another issue!

openid_connect is installed:
/Users/xxx/.rvm/gems/ruby-3.4.4/gems/openid_connect-2.3.1

I have the same gem:

Gemfile.lock:

forest_admin_agent (1.0.0.pre.beta.102)
  activesupport (>= 6.1)
  deepsort (~> 0.4.5)
  dry-container (~> 0.11)
  faraday (~> 2.7)
  filecache (~> 1.0)
  ipaddress (~> 0.8.3)
  jsonapi-serializers (~> 1.0)
  jwt (~> 2.7)
  ld-eventsource (~> 2.2)
  mono_logger (~> 1.1)
  openid_connect (~> 2.2)
  rack-cors (~> 2.0)
  rake (~> 13.0)
  zeitwerk (~> 2.3)
forest_admin_datasource_active_record (1.0.0.pre.beta.102)
  activerecord (>= 6.1)
  activesupport (>= 6.1)
  zeitwerk (~> 2.3)
forest_admin_datasource_customizer (1.0.0.pre.beta.102)
  activesupport (>= 6.1)
  marcel (~> 1.0, >= 1.0.4)
  zeitwerk (~> 2.3)
forest_admin_datasource_toolkit (1.0.0.pre.beta.102)
  activesupport (>= 6.1)
  zeitwerk (~> 2.3)
forest_admin_rails (1.0.0.pre.beta.102)
  dry-configurable (~> 1.1)
  rails (>= 6.1)
  zeitwerk (~> 2.3)

Since the gem was correctly installed, the issue came from how the OpenIDConnect constant is loaded. In some setups (depending on the loading order and environment), it may not be automatically available when the controller is loaded.

We’ve fixed this on our side by explicitly requiring the gem at the top of the forest_controller.rb file.

The patch has been released in version v1.0.0-beta.104 — you can update to that version to resolve the issue.

Thanks again for reporting this! :folded_hands:

Thanks @matthv. I upgraded the gem but now I get the following errors when trying to load the dashboard:

../gems/ruby-3.4.4/gems/forest_admin_rails-1.0.0.pre.beta.104/app/controllers/forest_admin_rails/forest_controller.rb:54:in ‘ForestAdminRails::ForestController#exception_handler’: undefined method ‘name’ for an instance of ForestAdminAgent::Error (NoMethodError)

name: exception.name,

../gems/ruby-3.4.4/gems/forest_admin_agent-1.0.0.pre.beta.104/lib/forest_admin_agent/services/ip_whitelist.rb:96:in ‘ForestAdminAgent::Services::IpWhitelist#fetch_rules’: Cannot retrieve the data from the Forest server. An error occured in Forest API (ForestAdminAgent::Error)

It looks like we’re hitting a similar issue as before, this time with how the ForestAdminAgent::Error class is used. A patch is currently in progress to address this.

The issue related to IpWhitelist is usually caused by a misconfiguration of the ‘FOREST_ENV_SECRET’ variable, could you please double check the value present inside of your config.env_secret and also share with me the last 4 chars of your secret ?
you should have executed the command using the FOREST_ENV_SECRET defined inside your previous agent
rails g forest_admin_rails:install [FOREST_ENV_SECRET]

I double-checked and the FOREST_ENV_SECRET variable matches the one in my dashboard, in the development environment. Here are the last 4 chars: 59cb

Thanks.

We’ve just released version v1.0.0-beta.106 of the agent, which includes additional logs to help debug issues related to the IP whitelist feature.

I’ve checked on our side, and so far we we didn’t receive any call containing your env secret.

Would you mind updating to the latest version and trying again (in debug mode)? That should help us move forward more easily.

I upgraded but still get the error about the IP whitelist feature:

DEBUG – : {error: “undefined method ‘’ for nil”, status: 404, response: “{"errors":[{"status":404,"detail":"Not found error","name":"NotFoundError"}]}”}

D, [2025-06-13T11:39:29.920638 #4644] DEBUG – : /Users/xxx/.rvm/gems/ruby-3.4.4/gems/forest_admin_agent-1.0.0.pre.beta.106/lib/forest_admin_agent/services/ip_whitelist.rb:101:in ‘ForestAdminAgent::Services::IpWhitelist#fetch_rules’: Cannot retrieve the data from the Forest server. An error occured in Forest API (ForestAdminAgent::Error)

/.rvm/gems/ruby-3.4.4/gems/forest_admin_agent-1.0.0.pre.beta.106/lib/forest_admin_agent/services/ip_whitelist.rb:91:in ‘ForestAdminAgent::Services::IpWhitelist#fetch_rules’: undefined method ‘[]’ for nil (NoMethodError)

ip_whitelist_data = body[‘data’][‘attributes’]

Note that I haven’t configured any ip_whitelist in the dashboard. I just have the following config in config/application.rb (I tried to remove it but same errors):

# ForestAdmin CORS configuration
    null_regex = Regexp.new(/\Anull\z/)
    config.middleware.insert_before 0, Rack::Cors do
      allow do
        hostnames = [null_regex, 'localhost:4200', 'app.forestadmin.com', 'localhost:3001']
        hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']
        origins hostnames
        resource '*',
          headers: :any,
          methods: :any,
          expose: ['Content-Disposition'],
          credentials: true
      end
    end

The 404 response is unexpected, the IP whitelist endpoint should normally be reachable.

To help us investigate, could you open your Rails console and run ForestAdminRails.config?

Then, please send me the result in a private message.