Skip to content

Prevent leaking parent provider config by discarding inherited options for different services#312

Open
TheRealNeil wants to merge 1 commit intoactiveagents:mainfrom
qlarity:fix-generate-with-inheritance
Open

Prevent leaking parent provider config by discarding inherited options for different services#312
TheRealNeil wants to merge 1 commit intoactiveagents:mainfrom
qlarity:fix-generate-with-inheritance

Conversation

@TheRealNeil
Copy link
Contributor

@TheRealNeil TheRealNeil commented Feb 8, 2026

Prevent parent provider config leaking when child agent switches service

Fixes #304

Summary

  • Discard all inherited options when the child agent's provider service differs from the parent's, instead of only stripping :service and :api_version

Root cause

When a child agent overrides generate_with with a different provider (e.g. parent uses Ollama, child uses Azure), the merge in generate_with only removed :service and :api_version from inherited options. All other parent options (:host, :api_key, :model, etc.) survived and — because the merge order is global_options.merge(inherited_options) — overrode the child's YAML config. This caused requests to hit the wrong endpoint with the wrong credentials.

Fix

When global_options[:service] != inherited_options[:service], replace inherited_options.extract!(:service, :api_version) with inherited_options = {}. This gives the child a clean slate from its own YAML config when switching providers, while preserving same-provider inheritance (e.g. a child that only tweaks temperature).

Test plan

  • Child agent with a different generate_with provider uses its own YAML config (host, api_key, model)
  • Child agent with the same provider still inherits parent options correctly
  • Agent-level overrides (e.g. generate_with :azure, model: 'gpt-4.1') still take precedence

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a configuration inheritance bug where a child agent switching to a different provider service could unintentionally inherit (and override) its own provider settings with parent provider options.

Changes:

  • When generate_with detects a provider :service change between parent and child, it now discards all inherited options (instead of only stripping :service and :api_version).
  • Adds clarifying inline comments explaining the rationale (prevent leaking host/api_key/model, etc.).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +109 to 113
# Different Service, different APIs — discard all inherited options
# to prevent parent provider config (host, api_key, etc.) leaking through
if global_options[:service] != inherited_options[:service]
inherited_options.extract!(:service, :api_version)
inherited_options = {}
end
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes provider option inheritance behavior in a subtle way (clearing all inherited options when the service changes), but there’s no automated test coverage validating the new behavior. Please add tests that cover: (1) parent/child with different service does not inherit provider-specific keys like host/api_key/model, and (2) same-service inheritance still works, and (3) explicit generate_with overrides still win over YAML config/inheritance.

Copilot uses AI. Check for mistakes.
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.

generate_with inheritance: parent provider options leak into child when switching providers

1 participant