Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jjmata
Copy link
Collaborator

@jjmata jjmata commented Oct 21, 2025

Summary

  • remove propagation of user email domains from the assistant responder
  • attach product, environment, host, and version metadata to OpenAI chat calls instead
  • adjust OpenAI provider tests to cover the new metadata payload

Testing

  • bin/rails test test/models/assistant_test.rb test/models/provider/openai_test.rb

https://chatgpt.com/codex/tasks/task_e_68f7d10cdf0c8332bebca5b236ae892f

Summary by CodeRabbit

  • New Features
    • Chat requests to OpenAI now include system metadata (product name, environment, hostname, and version information) to provide enhanced context for API operations.

@jjmata jjmata added the codex Touched by OpenAI Codex somehow label Oct 21, 2025 — with ChatGPT Codex Connector
@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2025

Walkthrough

The OpenAI provider now includes runtime metadata in chat requests. A new build_metadata private method collects product name, environment, hostname, and version information, which is then augmented into the request parameters and sent to the OpenAI client.

Changes

Cohort / File(s) Summary
OpenAI Provider Metadata Integration
app/models/provider/openai.rb, test/models/provider/openai_test.rb
Added require "socket" for hostname retrieval. Introduced build_metadata private method that collects product name, environment, hostname, semver, and release_tag. Refactored chat_response to construct a parameters hash, augment it with metadata when available, and pass the complete payload to the client. Corresponding test verifies the metadata hash structure and fields are correctly included in chat requests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes introduce new logic for metadata collection and refactor the request-building flow, requiring verification of correct field mapping and integration. The test comprehensively validates the new behavior. Complexity is moderate due to the introduction of a new private method and parameter construction pattern, though the underlying logic is relatively straightforward.

Poem

🐰 With socket in paw and metadata bright,
We gather the details—hostname, version, site!
The OpenAI requests now wear their true name,
Product and env in each call—oh, what a game! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Replace user metadata with runtime context for OpenAI requests" accurately describes the primary change in this pull request. According to the PR objectives, the main modifications are removing user email domain metadata and adding runtime context metadata (product name, environment, hostname, and version) to OpenAI chat requests. The title is concise, clear, and specific—it tells a teammate scanning the history exactly what changed and why. It captures the essence of the trade-off being made without requiring unnecessary detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-user-email-domain-to-openai-api-call

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea7ce13 and f4d13b8.

📒 Files selected for processing (2)
  • app/models/provider/openai.rb (3 hunks)
  • test/models/provider/openai_test.rb (1 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
app/models/**/*.rb

📄 CodeRabbit inference engine (.cursor/rules/project-design.mdc)

Domain models should not call Provider::Registry directly; use a Provided concern within the model’s namespace to select providers and expose convenience methods

Use ActiveRecord validations for forms and complex domain constraints.

app/models/**/*.rb: Place business logic in POROs and model classes under app/models
Models should answer questions about themselves (e.g., prefer account.balance_series over service objects)
Implement complex validations and business logic with ActiveRecord validations
Model-level validations may mirror DB constraints but are not strictly required

Files:

  • app/models/provider/openai.rb
app/models/provider/**/*.rb

📄 CodeRabbit inference engine (.cursor/rules/project-design.mdc)

Concrete provider classes must be under the Provider:: namespace, inherit from Provider, wrap calls with with_provider_response, and raise on invalid/unavailable data

Files:

  • app/models/provider/openai.rb
app/**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Place Rails application Ruby code (models, controllers, services, jobs, mailers, components) under app/

Files:

  • app/models/provider/openai.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby style: 2-space indentation; snake_case for methods/variables; CamelCase for classes/modules

Files:

  • app/models/provider/openai.rb
  • test/models/provider/openai_test.rb
**/*.{rb,js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{rb,js,jsx,ts,tsx}: Make changes atomic, testable, and explain their impact briefly in code suggestions.
Respect existing tests and add tests when changing critical logic.

Files:

  • app/models/provider/openai.rb
  • test/models/provider/openai_test.rb
**/app/**/*.{rb,erb,js,css}

📄 CodeRabbit inference engine (CLAUDE.md)

Push Rails to its limits before adding new dependencies; a strong technical/business reason is required for new dependencies.

Files:

  • app/models/provider/openai.rb
**/app/models/**/*.rb

📄 CodeRabbit inference engine (CLAUDE.md)

Business logic should primarily reside in models; use concerns and POROs for organization.

Files:

  • app/models/provider/openai.rb
**/*.{rb,erb,haml,slim}

📄 CodeRabbit inference engine (.cursor/rules/general-rules.mdc)

**/*.{rb,erb,haml,slim}: Use Current.user for the current user; do not use current_user
Use Current.family for the current family; do not use current_family
Ignore i18n methods; hardcode strings in English for now (do not use I18n.t, t, or similar)

Files:

  • app/models/provider/openai.rb
  • test/models/provider/openai_test.rb
app/{helpers,models}/**/*.rb

📄 CodeRabbit inference engine (.cursor/rules/project-conventions.mdc)

Format currencies, numbers, and dates on the server side (Ruby) before sending to the client

Files:

  • app/models/provider/openai.rb
app/{models,controllers,views}/**/*.{rb,erb}

📄 CodeRabbit inference engine (.cursor/rules/project-conventions.mdc)

Avoid N+1 queries

Files:

  • app/models/provider/openai.rb
test/**/*_test.rb

📄 CodeRabbit inference engine (AGENTS.md)

Name Minitest files with *_test.rb and mirror the app/ structure under test/

test/**/*_test.rb: ALWAYS use Minitest + fixtures + Mocha for tests; NEVER RSpec or FactoryBot.
Use Mocha for mocking in tests when necessary.
Use VCR for external API tests.

test/**/*_test.rb: Always use Minitest for tests; do not use RSpec
Do not use factories (e.g., FactoryBot) in tests; rely on fixtures instead
For tests needing many records, use Rails helpers to construct data and inline the creation in the test
Only write tests for critical and important code paths
Avoid tests that merely verify framework/ActiveRecord behavior
Test boundaries correctly: for queries, assert returned values; for commands, assert collaborators are called with correct params
Never test the implementation details of one class in another class’s test suite
Use the mocha gem for stubs and mocks
Prefer OpenStruct for mock instances; use a mock class for complex cases
Only mock what’s necessary; don’t mock return values unless they are under test

Files:

  • test/models/provider/openai_test.rb
**/test/**/*.rb

📄 CodeRabbit inference engine (CLAUDE.md)

**/test/**/*.rb: ALWAYS use Minitest and fixtures for Ruby tests; NEVER RSpec or factories.
Only test critical and important code paths; system tests should be used sparingly for critical user flows.

Files:

  • test/models/provider/openai_test.rb
🧬 Code graph analysis (2)
app/models/provider/openai.rb (3)
app/models/provider/openai/chat_config.rb (1)
  • tools (7-17)
config/initializers/version.rb (1)
  • version (3-5)
lib/semver.rb (1)
  • to_release_tag (26-28)
test/models/provider/openai_test.rb (2)
lib/semver.rb (1)
  • to_release_tag (26-28)
app/models/provider/openai.rb (1)
  • chat_response (63-140)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: ci / test
🔇 Additional comments (4)
test/models/provider/openai_test.rb (1)

20-75: LGTM! Well-structured metadata test with proper cleanup.

The test correctly verifies that runtime metadata is passed to the OpenAI client. Using allocate to bypass initialization for isolated mocking is an acceptable pattern here. The ensure block properly restores both the ENV variable and unstubs the Socket method to prevent test pollution.

app/models/provider/openai.rb (3)

1-2: LGTM! Appropriate standard library requirement.

The require "socket" is necessary for Socket.gethostname used in the new build_metadata method.


98-110: LGTM! Clean refactor to build parameters with conditional metadata.

The refactored approach builds the parameters hash first, then conditionally adds metadata before passing to the client. This maintains the existing API while cleanly integrating the new metadata functionality.


145-158: LGTM! Straightforward runtime context collection.

The method gathers appropriate runtime metadata. Using ENV.fetch with a default value for PRODUCT_NAME is good practice. Note that Socket.gethostname could theoretically raise SocketError in unusual network configurations, but since this is wrapped by with_provider_response in the caller, any failure would be properly handled as a provider error.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jjmata jjmata closed this Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex Touched by OpenAI Codex somehow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants