Skip to content

Require openai in coplan.rb so OpenAI constant is loaded#123

Merged
HamptonMakes merged 1 commit into
mainfrom
hampton/require-openai
Jun 2, 2026
Merged

Require openai in coplan.rb so OpenAI constant is loaded#123
HamptonMakes merged 1 commit into
mainfrom
hampton/require-openai

Conversation

@HamptonMakes
Copy link
Copy Markdown
Collaborator

Problem

The freshly bumped coplan-engine is crashing in coplan-square production with:

NameError: uninitialized constant CoPlan::AiProviders::OpenAi::OpenAI
        client = OpenAI::Client.new(access_token: api_key)

triggered by SummarizePlanJob (the new AI summary feature from #118).

Root cause

ruby-openai is declared as a dependency in engine/coplan.gemspec (spec.add_dependency "ruby-openai"), which installs the gem but does not auto-require it. Host apps using Bundler.require only auto-require gems listed directly in their own Gemfile — transitive gemspec deps must be required explicitly by the consuming gem.

In dev, this often works by accident (other code paths or dev gems can pull openai in), but in coplan-square production the constant is never loaded, so the first OpenAI::Client.new call blows up.

Fix

Add require "openai" to engine/lib/coplan.rb alongside the other top-level requires (commonmarker, diffy).

Validation

  • bundle exec rspec spec/services/ai_spec.rb spec/jobs/summarize_plan_job_spec.rb ✅ (15 examples, 0 failures)

Once this merges I'll re-bump coplan-square to pick it up.

ruby-openai is a transitive dependency through coplan-engine's gemspec, so
host apps (coplan-square) don't auto-require it via Bundler.require. Without
this require, SummarizePlanJob fails with:

  NameError: uninitialized constant CoPlan::AiProviders::OpenAi::OpenAI

because the OpenAI::Client constant is never loaded in the host process.

Amp-Thread-ID: https://ampcode.com/threads/T-019e898e-809a-7332-8e3e-a51658bf36f3
Co-authored-by: Amp <amp@ampcode.com>
@HamptonMakes HamptonMakes merged commit bc68564 into main Jun 2, 2026
5 checks passed
@HamptonMakes HamptonMakes deleted the hampton/require-openai branch June 2, 2026 21:36
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.

1 participant