Skip to content

Warn when Config singleton is re-requested with different parameters#102

Merged
urajat merged 2 commits into
cisco-ai-defense:mainfrom
shiva-guntoju-09:shiva/config-singleton-warning
Apr 7, 2026
Merged

Warn when Config singleton is re-requested with different parameters#102
urajat merged 2 commits into
cisco-ai-defense:mainfrom
shiva-guntoju-09:shiva/config-singleton-warning

Conversation

@shiva-guntoju-09

Copy link
Copy Markdown
Collaborator

Summary

  • BaseConfig.__init__ now detects when an already-initialized singleton is called with different region, timeout, runtime_base_url, or management_base_url and logs a WARNING with the mismatched values
  • Short-code region aliases (e.g., "us""us-west-2") are normalized before comparison so equivalent regions don't trigger false warnings
  • No warning when Config() is called with no kwargs (common default usage)
  • Singleton behavior is fully preserved — this only adds visibility into a silent failure mode

Context

Fixes AIFW-21679. When middleware (e.g., LangChain) creates multiple SDK clients with different Config(region=..., timeout=...) calls, the second call silently returns the first instance with the original parameters. Users get incorrect behavior with no indication.

Test plan

  • test_config_warns_on_different_region — different region triggers warning
  • test_config_warns_on_different_timeout — different timeout triggers warning
  • test_config_no_warning_on_same_params — identical params produce no warning
  • test_config_no_warning_on_short_region_alias"us" vs "us-west-2" correctly recognized as equivalent
  • test_config_no_warning_when_no_kwargs — bare Config() call produces no warning
  • All 7 existing test_config.py tests continue to pass

Made with Cursor

BaseConfig.__init__ now detects when an already-initialized singleton
is called with different region, timeout, runtime_base_url, or
management_base_url and logs a WARNING with the mismatched values.

This surfaces a silent failure mode where callers unknowingly get back
a Config with different settings than requested. The singleton behavior
is preserved — this only adds visibility.

Fixes: AIFW-21679
Made-with: Cursor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff1a61ea83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread aidefense/config.py Outdated
Comment thread aidefense/config.py Outdated
- Merge positional args into the comparison so Config("eu-central-1")
  triggers the warning just like Config(region="eu-central-1")
- Normalize URLs by stripping trailing slashes before comparison to
  avoid false-positive warnings when the same effective URL is passed

Adds regression tests for both cases.

Made-with: Cursor
@urajat urajat merged commit 2c95650 into cisco-ai-defense:main Apr 7, 2026
5 checks passed
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.

3 participants